From cb82b73e7808b81064554c7bcfe89568aa7c6cc1 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 23 Aug 2022 19:54:36 +0800 Subject: [PATCH] add some warning if subchannel isn't set explicitly --- .../structure/StructureUtility.java | 34 ++++++++++++++----- .../assets/structurelib/lang/en_US.lang | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java index 39744f67..c3c7279f 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java @@ -1,7 +1,8 @@ package com.gtnewhorizon.structurelib.structure; -import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE; -import static java.lang.Integer.MIN_VALUE; +import java.util.*; +import java.util.function.*; +import javax.annotation.Nullable; import com.gtnewhorizon.structurelib.StructureLib; import com.gtnewhorizon.structurelib.StructureLibAPI; @@ -13,10 +14,8 @@ import com.gtnewhorizon.structurelib.structure.adders.ITileAdder; import com.gtnewhorizon.structurelib.util.ItemStackPredicate.NBTMode; import com.gtnewhorizon.structurelib.util.Vec3Impl; import cpw.mods.fml.common.registry.GameRegistry; -import java.util.*; -import java.util.function.*; -import javax.annotation.Nullable; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -32,6 +31,10 @@ import net.minecraftforge.common.util.ForgeDirection; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; + +import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE; +import static java.lang.Integer.MIN_VALUE; + /** * Fluent API for structure checking! *

@@ -1908,10 +1911,21 @@ public class StructureUtility { } public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return backing.spawnHint(t, world, x, y, z, ChannelDataAccessor.withChannel(trigger, channel)); + ItemStack newTrigger = ChannelDataAccessor.withChannel(trigger, channel); + // We know spawnHint will only be called on client side, so the lack of player isn't quite an issue + // we check if it's null again just in case. + if (newTrigger == trigger && StructureLib.getCurrentPlayer() != null) + warnNoExplicitSubChannel(StructureLib.getCurrentPlayer()); + return backing.spawnHint(t, world, x, y, z, newTrigger); + } + + private void warnNoExplicitSubChannel(EntityPlayer currentPlayer) { + currentPlayer.addChatComponentMessage( + new ChatComponentTranslation("structurelib.autoplace.warning.no_explicit_channel", channel)); } public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + // I hope a CREATIVE player know what he is doing... return backing.placeBlock(t, world, x, y, z, ChannelDataAccessor.withChannel(trigger, channel)); } @@ -1925,8 +1939,12 @@ public class StructureUtility { IItemSource s, EntityPlayerMP actor, Consumer chatter) { - return backing.survivalPlaceBlock( - t, world, x, y, z, ChannelDataAccessor.withChannel(trigger, channel), s, actor, chatter); + ItemStack newTrigger = ChannelDataAccessor.withChannel(trigger, channel); + if (newTrigger == trigger) + // we will bypass the chatter filter here, as this is a warning that player definitively want to see + // instead of some false positive error messages like item not find + warnNoExplicitSubChannel(actor); + return backing.survivalPlaceBlock(t, world, x, y, z, newTrigger, s, actor, chatter); } }; } diff --git a/src/main/resources/assets/structurelib/lang/en_US.lang b/src/main/resources/assets/structurelib/lang/en_US.lang index 49783f87..4d9e0835 100644 --- a/src/main/resources/assets/structurelib/lang/en_US.lang +++ b/src/main/resources/assets/structurelib/lang/en_US.lang @@ -41,6 +41,7 @@ structurelib.autoplace.complete=§aThis multiblock has completed! structurelib.autoplace.error.not_enabled=§cThis multiblock does not support autoplace in survival! structurelib.autoplace.error.no_simple_block=§cSuggested to place §r%s§c but none was found structurelib.autoplace.error.no_item_stack=§cSuggested to place block by using §r%s§c but none was found +structurelib.autoplace.warning.no_explicit_channel=§6This structure depends on nonexistent sub channel §r%s§c. Using master channel instead. structurelib.blockhint.desc.0=Helps while building structurelib.blockhint.0.name=Hint 1 dot