From a3f8c357e37ed849e843e05c0997f1081f775a6f Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Sun, 18 Jan 2015 15:58:13 -0500 Subject: [PATCH] Finish chisel modes --- .../cricketcraft/chisel/api/ChiselMode.java | 49 ++++++++++++++++--- .../chisel/client/gui/GuiChisel.java | 37 +++++++++++++- .../chisel/network/PacketHandler.java | 2 + .../network/message/MessageChiselMode.java | 46 +++++++++++++++++ .../resources/assets/chisel/lang/en_US.lang | 5 ++ 5 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/cricketcraft/chisel/network/message/MessageChiselMode.java diff --git a/src/main/java/com/cricketcraft/chisel/api/ChiselMode.java b/src/main/java/com/cricketcraft/chisel/api/ChiselMode.java index 8a578641..a0da6f00 100644 --- a/src/main/java/com/cricketcraft/chisel/api/ChiselMode.java +++ b/src/main/java/com/cricketcraft/chisel/api/ChiselMode.java @@ -3,6 +3,7 @@ package com.cricketcraft.chisel.api; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -44,15 +45,44 @@ public enum ChiselMode { public void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); - if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) { - setVariation(player, world, x, y, z, block, meta, variation); - setVariation(player, world, x, y + 1, z, block, meta, variation); - setVariation(player, world, x, y - 1, z, block, meta, variation); - } else { - // TODO top/bottom + int facing = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + for (int i = -1; i <= 1; i++) { + if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) { + setVariation(player, world, x, y + i, z, block, meta, variation); + } else { + if (facing == 0 || facing == 2) { + setVariation(player, world, x, y, z + i, block, meta, variation); + } else { + setVariation(player, world, x + i, y, z, block, meta, variation); + } + } } } - }; // TODO SIDEWAYS + }, + ROW { + + @Override + public void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int facing = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + for (int i = -1; i <= 1; i++) { + if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) { + if (side == ForgeDirection.EAST || side == ForgeDirection.WEST) { + setVariation(player, world, x, y, z + i, block, meta, variation); + } else { + setVariation(player, world, x + i, y, z, block, meta, variation); + } + } else { + if (facing == 0 || facing == 2) { + setVariation(player, world, x + i, y, z, block, meta, variation); + } else { + setVariation(player, world, x, y, z + i, block, meta, variation); + } + } + } + } + }; public abstract void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation); @@ -73,4 +103,9 @@ public enum ChiselMode { world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3); ((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), v); } + + public ChiselMode next() { + ChiselMode[] values = values(); + return values[(ordinal() + 1) % values.length]; + } } diff --git a/src/main/java/com/cricketcraft/chisel/client/gui/GuiChisel.java b/src/main/java/com/cricketcraft/chisel/client/gui/GuiChisel.java index 38353a33..a7c4e765 100644 --- a/src/main/java/com/cricketcraft/chisel/client/gui/GuiChisel.java +++ b/src/main/java/com/cricketcraft/chisel/client/gui/GuiChisel.java @@ -1,22 +1,29 @@ package com.cricketcraft.chisel.client.gui; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; +import com.cricketcraft.chisel.api.ChiselMode; import com.cricketcraft.chisel.inventory.ContainerChisel; import com.cricketcraft.chisel.inventory.InventoryChiselSelection; import com.cricketcraft.chisel.inventory.SlotChiselInput; +import com.cricketcraft.chisel.network.PacketHandler; +import com.cricketcraft.chisel.network.message.MessageChiselMode; +import com.cricketcraft.chisel.utils.General; import com.cricketcraft.chisel.utils.GeneralClient; public class GuiChisel extends GuiContainer { public EntityPlayer player; public ContainerChisel container; + private ChiselMode currentMode; public GuiChisel(InventoryPlayer iinventory, InventoryChiselSelection menu) { super(new ContainerChisel(iinventory, menu)); @@ -33,12 +40,30 @@ public class GuiChisel extends GuiContainer { inventorySlots.onContainerClosed(player); } + @SuppressWarnings("unchecked") + @Override + public void initGui() { + super.initGui(); + currentMode = General.getChiselMode(container.chisel); + + int x = this.width / 2 - 120; + int y = this.height / 2 - 6; + buttonList.add(new GuiButton(0, x, y, 53, 20, "")); + setButtonText(); + } + + private void setButtonText() { + ((GuiButton) buttonList.get(0)).displayString = I18n.format(container.inventory.getInventoryName() + ".mode." + currentMode.name().toLowerCase()); + } + @Override protected void drawGuiContainerForegroundLayer(int j, int i) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); String line = I18n.format(this.container.inventory.getInventoryName() + ".title"); fontRendererObj.drawSplitString(line, 50 - fontRendererObj.getStringWidth(line) / 2, 60, 40, 0x404040); + line = I18n.format(this.container.inventory.getInventoryName() + ".mode"); + fontRendererObj.drawString(line, fontRendererObj.getStringWidth(line) / 2 + 6, 85, 0x404040); } @Override @@ -56,13 +81,23 @@ public class GuiChisel extends GuiContainer { int x = (width - xSize) / 2; int y = (height - ySize) / 2; - + Slot main = (Slot) container.inventorySlots.get(InventoryChiselSelection.normalSlots); if (main.getStack() == null) { GuiAutoChisel.drawSlotOverlay(this, x + 14, y + 14, main, 0, ySize, 60); } } + @Override + protected void actionPerformed(GuiButton button) { + if (button.id == 0) { + PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode)); + currentMode = currentMode.next(); + setButtonText(); + } + super.actionPerformed(button); + } + @Override protected void func_146977_a(Slot slot) { if (slot instanceof SlotChiselInput) { diff --git a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java index ffbb42de..44e742a3 100644 --- a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java +++ b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java @@ -2,6 +2,7 @@ package com.cricketcraft.chisel.network; import com.cricketcraft.chisel.Chisel; import com.cricketcraft.chisel.network.message.MessageAutoChisel; +import com.cricketcraft.chisel.network.message.MessageChiselMode; import com.cricketcraft.chisel.network.message.MessageChiselSound; import com.cricketcraft.chisel.network.message.MessageSlotUpdate; @@ -18,5 +19,6 @@ public class PacketHandler { INSTANCE.registerMessage(MessageChiselSound.Handler.class, MessageChiselSound.class, id++, Side.CLIENT); INSTANCE.registerMessage(MessageSlotUpdate.Handler.class, MessageSlotUpdate.class, id++, Side.CLIENT); INSTANCE.registerMessage(MessageAutoChisel.Handler.class, MessageAutoChisel.class, id++, Side.CLIENT); + INSTANCE.registerMessage(MessageChiselMode.Handler.class, MessageChiselMode.class, id++, Side.SERVER); } } \ No newline at end of file diff --git a/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselMode.java b/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselMode.java new file mode 100644 index 00000000..0bde806e --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselMode.java @@ -0,0 +1,46 @@ +package com.cricketcraft.chisel.network.message; + +import io.netty.buffer.ByteBuf; +import net.minecraft.item.ItemStack; + +import com.cricketcraft.chisel.api.ChiselMode; +import com.cricketcraft.chisel.api.IChiselItem; +import com.cricketcraft.chisel.utils.General; + +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; + + +public class MessageChiselMode implements IMessage { + + public MessageChiselMode(){ + } + + private String mode; + + public MessageChiselMode(ChiselMode current) { + this.mode = current.next().name(); + } + + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, mode); + } + + @Override + public void fromBytes(ByteBuf buf) { + this.mode = ByteBufUtils.readUTF8String(buf); + } + + public static class Handler implements IMessageHandler { + @Override + public IMessage onMessage(MessageChiselMode message, MessageContext ctx) { + ItemStack stack = ctx.getServerHandler().playerEntity.getCurrentEquippedItem(); + if (stack != null && stack.getItem() instanceof IChiselItem) { + General.setChiselMode(stack, ChiselMode.valueOf(message.mode)); + } + return null; + } + } +} diff --git a/src/main/resources/assets/chisel/lang/en_US.lang b/src/main/resources/assets/chisel/lang/en_US.lang index f48deee5..8585f0a2 100644 --- a/src/main/resources/assets/chisel/lang/en_US.lang +++ b/src/main/resources/assets/chisel/lang/en_US.lang @@ -1214,3 +1214,8 @@ itemGroup.tabChisel=Chisel Items container.chisel=Chisel container.chisel.title=Carve blocks container.chisel.titleShort=Carve +container.chisel.mode=Mode: +container.chisel.mode.single=Single +container.chisel.mode.panel=Panel +container.chisel.mode.column=Column +container.chisel.mode.row=Row