diff --git a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java index 81f8d024..7429e454 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java +++ b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java @@ -7,6 +7,7 @@ import com.gtnewhorizon.structurelib.item.ItemDebugStructureWriter; import com.gtnewhorizon.structurelib.item.ItemFrontRotationTool; import com.gtnewhorizon.structurelib.net.AlignmentMessage; +import com.gtnewhorizon.structurelib.net.ScrollConstructablePacket; import com.gtnewhorizon.structurelib.net.UpdateDebugWriterModePacket; import com.gtnewhorizon.structurelib.proxy.CommonProxy; import com.gtnewhorizon.structurelib.util.XSTR; @@ -47,6 +48,9 @@ public class StructureLib { net.registerMessage(UpdateDebugWriterModePacket.class, UpdateDebugWriterModePacket.class, 0, Side.CLIENT); net.registerMessage(UpdateDebugWriterModePacket.class, UpdateDebugWriterModePacket.class, 0, Side.SERVER); + + net.registerMessage(ScrollConstructablePacket.class, ScrollConstructablePacket.class, 0, Side.CLIENT); + net.registerMessage(ScrollConstructablePacket.class, ScrollConstructablePacket.class, 0, Side.SERVER); } public static final XSTR RANDOM = new XSTR(); diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java index 3ff5e22e..da6a738e 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java @@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import java.util.List; @@ -17,9 +18,22 @@ public class ItemConstructableTrigger extends Item { public ItemConstructableTrigger() { setUnlocalizedName("structurelib.constructableTrigger"); setTextureName(MOD_ID + ":itemConstructableTrigger"); + setHasSubtypes(true); setCreativeTab(StructureLib.creativeTab); } + public enum Mode { + Default, Debug + } + + @Override + public String getItemStackDisplayName(ItemStack itemStack) { + if (itemStack.getItemDamage() == 0) return super.getItemStackDisplayName(itemStack); + return String.format("%s (%s)", super.getItemStackDisplayName(itemStack), + StatCollector.translateToLocal("item.structurelib.constructableTrigger.debug")); + } + + @Override public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { return ConstructableUtility.handle(stack, player, world, x, y, z, side); diff --git a/src/main/java/com/gtnewhorizon/structurelib/net/ScrollConstructablePacket.java b/src/main/java/com/gtnewhorizon/structurelib/net/ScrollConstructablePacket.java new file mode 100644 index 00000000..941c162d --- /dev/null +++ b/src/main/java/com/gtnewhorizon/structurelib/net/ScrollConstructablePacket.java @@ -0,0 +1,42 @@ +package com.gtnewhorizon.structurelib.net; + +import com.gtnewhorizon.structurelib.item.ItemConstructableTrigger; +import com.gtnewhorizon.structurelib.item.ItemDebugStructureWriter; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.item.ItemStack; + +public class ScrollConstructablePacket implements IMessage, IMessageHandler { + public ScrollConstructablePacket() {} + + byte metaData; + + public ScrollConstructablePacket(byte metaData) { + this.metaData = metaData; + } + + + @Override + public void fromBytes(ByteBuf buf) { + metaData = buf.readByte(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeByte(metaData); + } + + @Override + public IMessage onMessage(ScrollConstructablePacket message, MessageContext ctx) { + ItemStack itemStack = ctx.getServerHandler().playerEntity.inventory.getCurrentItem(); + if (itemStack == null || !(itemStack.getItem() instanceof ItemConstructableTrigger)) { + return null; + } + if (message.metaData < 0 || message.metaData > 1) return null; + itemStack.setItemDamage(message.metaData); + return null; + } +} diff --git a/src/main/java/com/gtnewhorizon/structurelib/util/EventHandler.java b/src/main/java/com/gtnewhorizon/structurelib/util/EventHandler.java index 21aecdb5..e978ebae 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/util/EventHandler.java +++ b/src/main/java/com/gtnewhorizon/structurelib/util/EventHandler.java @@ -1,8 +1,10 @@ package com.gtnewhorizon.structurelib.util; import com.gtnewhorizon.structurelib.StructureLib; +import com.gtnewhorizon.structurelib.item.ItemConstructableTrigger; import com.gtnewhorizon.structurelib.item.ItemDebugStructureWriter; import com.gtnewhorizon.structurelib.item.ItemDebugStructureWriter.Mode; +import com.gtnewhorizon.structurelib.net.ScrollConstructablePacket; import com.gtnewhorizon.structurelib.net.UpdateDebugWriterModePacket; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; @@ -36,6 +38,17 @@ public void onMouseEvent(MouseEvent event) { StructureLib.net.sendToServer(new UpdateDebugWriterModePacket(itemStack)); + event.setCanceled(true); + } + } else if (itemStack != null && itemStack.getItem() instanceof ItemConstructableTrigger) { + if (event.dwheel != 0) { + if (itemStack.getItemDamage() == 0) { + itemStack.setItemDamage(1); + StructureLib.net.sendToServer(new ScrollConstructablePacket((byte) 1)); + } else { + itemStack.setItemDamage(0); + StructureLib.net.sendToServer(new ScrollConstructablePacket((byte) 0)); + } event.setCanceled(true); } } diff --git a/src/main/resources/assets/structurelib/lang/en_US.lang b/src/main/resources/assets/structurelib/lang/en_US.lang index 177cccdc..4941d3de 100644 --- a/src/main/resources/assets/structurelib/lang/en_US.lang +++ b/src/main/resources/assets/structurelib/lang/en_US.lang @@ -39,7 +39,8 @@ item.structurelib.frontRotationTool.desc.0=Triggers Front Rotation Interface item.structurelib.frontRotationTool.desc.1=Rotates only the front panel, item.structurelib.frontRotationTool.desc.2=which allows structure rotation. -item.structurelib.constructableTrigger.name=Multiblock Structure Hologram Projector +item.structurelib.constructableTrigger.name=Structure Blueprint +item.structurelib.constructableTrigger.debug=Debug item.structurelib.constructableTrigger.desc.0=Triggers Constructable Interface item.structurelib.constructableTrigger.desc.1=Shows multiblock construction details, item.structurelib.constructableTrigger.desc.2=just Use on a multiblock controller.