Skip to content

Commit

Permalink
add debug mode to blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
botn365 committed Apr 21, 2024
1 parent 1e5ab93 commit dbd16fd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/StructureLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ScrollConstructablePacket, IMessage> {
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;
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/util/EventHandler.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/structurelib/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dbd16fd

Please sign in to comment.