From 4e5a92aff76e36adfabc62408907178ee42b0fa8 Mon Sep 17 00:00:00 2001
From: evgengoldwar <69961523+evgengoldwar@users.noreply.github.com>
Date: Thu, 26 Mar 2026 18:23:20 +0400
Subject: [PATCH] Add more info (#56)
Fixing the issue where the ofBlock method does not show a hint about
which block cannot be placed.
---
.../structure/StructureUtility.java | 56 +++++++++++++++++--
.../assets/structurelib/lang/en_US.lang | 1 +
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java
index 13219225..23c8354f 100644
--- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java
+++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java
@@ -36,7 +36,10 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
+import net.minecraft.util.ChatStyle;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
@@ -338,9 +341,7 @@ public class StructureUtility {
ItemStack stack = new ItemStack(itemBlock, 1, itemMeta);
if (!s.takeOne(stack, true)) {
if (chatter != null) chatter.accept(
- new ChatComponentTranslation(
- "structurelib.autoplace.error.no_simple_block",
- stack.func_151000_E()));
+ new ChatComponentTranslation("structurelib.autoplace.missing_block", stack.func_151000_E()));
return PlaceResult.REJECT;
}
if (block instanceof ICustomBlockSetting) {
@@ -447,7 +448,7 @@ public class StructureUtility {
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor)) return PlaceResult.REJECT;
if (!assumeStackPresent && !s.takeOne(stack, true)) {
if (chatter != null) chatter.accept(
- new ChatComponentTranslation("structurelib.autoplace.error.no_item_stack", stack.func_151000_E()));
+ new ChatComponentTranslation("structurelib.autoplace.missing_block", stack.func_151000_E()));
return PlaceResult.REJECT;
}
if (!stack.copy().tryPlaceItemIntoWorld(actor, world, x, y, z, ForgeDirection.UP.ordinal(), 0.5f, 0.5f, 0.5f))
@@ -1411,6 +1412,53 @@ public class StructureUtility {
} else {
return new IStructureElement() {
+ @Override
+ public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
+ AutoPlaceEnvironment env) {
+ BlocksToPlace e = getBlocksToPlace(t, world, x, y, z, trigger, env);
+ IItemSource source = env.getSource();
+ EntityPlayer actor = env.getActor();
+ Consumer chatter = env.getChatter();
+ if (check(t, world, x, y, z)) return PlaceResult.SKIP;
+ if (e.getStacks() == null) {
+ ItemStack taken = source.takeOne(e.getPredicate(), true);
+ return StructureUtility.survivalPlaceBlock(
+ taken,
+ NBTMode.EXACT,
+ taken.stackTagCompound,
+ false,
+ world,
+ x,
+ y,
+ z,
+ source,
+ actor,
+ chatter);
+ }
+ for (ItemStack stack : e.getStacks()) {
+ if (!source.takeOne(stack, true)) {
+ IChatComponent name = new ChatComponentText(stack.getDisplayName());
+ name.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW));
+ env.getChatter()
+ .accept(new ChatComponentTranslation("structurelib.autoplace.missing_block", name));
+ continue;
+ }
+ return StructureUtility.survivalPlaceBlock(
+ stack,
+ NBTMode.EXACT,
+ stack.stackTagCompound,
+ false,
+ world,
+ x,
+ y,
+ z,
+ source,
+ actor,
+ chatter);
+ }
+ return PlaceResult.REJECT;
+ }
+
@Override
public boolean check(T t, World world, int x, int y, int z) {
Block worldBlock = world.getBlock(x, y, z);
diff --git a/src/main/resources/assets/structurelib/lang/en_US.lang b/src/main/resources/assets/structurelib/lang/en_US.lang
index 23157638..9845ae25 100644
--- a/src/main/resources/assets/structurelib/lang/en_US.lang
+++ b/src/main/resources/assets/structurelib/lang/en_US.lang
@@ -51,6 +51,7 @@ structurelib.autoplace.error.not_enabled=§cThis multiblock does not support aut
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§6. Using master channel instead.
+structurelib.autoplace.missing_block=§cMissing block: %s
structurelib.blockhint.desc.0=Helps while building
structurelib.blockhint.0.name=Hint 1 dot