diff --git a/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityAutoChisel.java b/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityAutoChisel.java index 63963c7d..e92c5678 100644 --- a/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityAutoChisel.java +++ b/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityAutoChisel.java @@ -18,6 +18,7 @@ import com.cricketcraft.chisel.api.IChiselItem; import com.cricketcraft.chisel.carving.Carving; import com.cricketcraft.chisel.init.ChiselItems; import com.cricketcraft.chisel.network.PacketHandler; +import com.cricketcraft.chisel.network.message.MessageAutoChisel; import com.cricketcraft.chisel.network.message.MessageSlotUpdate; import cpw.mods.fml.relauncher.Side; @@ -44,7 +45,12 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory private ItemStack[] inventory = new ItemStack[7]; private String name = "autoChisel"; - public float xRot, yRot, zRot; // used for floating target client only + // used for floating target client only + public float xRot, yRot, zRot; + + // used for chisel item rotation client only + public float chiselRot; + public boolean chiseling = false; @Override public boolean canUpdate() { @@ -132,12 +138,13 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory } // remove what we made from the stack base.stackSize -= chiseled.stackSize; + slotChanged(BASE); if (base.stackSize <= 0) { setInventorySlotContents(BASE, null); // clear out 0 size itemstacks } // TODO here we need to send a packet to the client so that the animation and sound can be played - ((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], inventory[TARGET]); + chiselItem(); } } } @@ -173,6 +180,12 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory return inventory[CHISEL] != null && inventory[CHISEL].getItem() instanceof IChiselItem && inventory[CHISEL].stackSize >= 1; } + /** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */ + private void chiselItem() { + ((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], inventory[TARGET]); + PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this), worldObj.provider.dimensionId); + } + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -345,4 +358,8 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory return Upgrade.values()[slotNumber - MIN_UPGRADE].getUnlocalizedName() + ".name"; } } + + public void doChiselAnim() { + chiseling = true; + } } diff --git a/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderAutoChisel.java b/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderAutoChisel.java index 82a91b04..7fe9c67b 100644 --- a/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderAutoChisel.java +++ b/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderAutoChisel.java @@ -4,6 +4,7 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityDiggingFX; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; @@ -13,6 +14,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -27,6 +29,9 @@ import org.lwjgl.opengl.GL11; import com.cricketcraft.chisel.Chisel; import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel; +import com.cricketcraft.chisel.carving.Carving; +import com.cricketcraft.chisel.client.GeneralChiselClient; +import com.cricketcraft.chisel.utils.GeneralClient; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; @@ -169,21 +174,50 @@ public class RenderAutoChisel extends TileEntitySpecialRenderer implements ISimp if (item != null) { GL11.glPushMatrix(); GL11.glTranslated(x + 0.35, y + 0.934, z + 0.5); + item.getEntityItem().stackSize = autoChisel.getStackInSlot(TileEntityAutoChisel.BASE).stackSize; renderItem.doRender(item, 0, 0, 0, 0, 0); GL11.glPopMatrix(); } - + item = autoChisel.getItemForRendering(TileEntityAutoChisel.CHISEL); if (item != null) { + if (autoChisel.chiseling) { + autoChisel.chiselRot += 1; + if (autoChisel.chiselRot > 70) { + chiselItem(autoChisel); + } + } else { + autoChisel.chiselRot = Math.max(autoChisel.chiselRot - 1, 0); + } GL11.glPushMatrix(); - GL11.glTranslated(x + 0.7, y + 1, z + 0.5); + GL11.glTranslated(x + 0.7, y + 1.01, z + 0.5); + GL11.glRotatef(autoChisel.chiselRot, 0, 0, 1); GL11.glTranslated(-0.12, 0, 0); GL11.glScalef(0.9f, 0.9f, 0.9f); renderItem.doRender(item, 0, 0, 0, 0, 0); GL11.glPopMatrix(); + } else { + autoChisel.chiselRot = 0; + autoChisel.chiseling = false; } } + private void chiselItem(TileEntityAutoChisel autoChisel) { + World world = autoChisel.getWorldObj(); + ItemStack base = autoChisel.getStackInSlot(TileEntityAutoChisel.BASE); + if (base != null) { + for (int i = 0; i < 5; i++) { + EntityDiggingFX particle = new EntityDiggingFX(world, autoChisel.xCoord + 0.5, autoChisel.yCoord + 1, autoChisel.zCoord + 0.5, 0, 0, 0, Block.getBlockFromItem(base.getItem()), + base.getItemDamage()); + particle.setVelocity((world.rand.nextDouble() / 4) - 0.125, world.rand.nextDouble() / 8, (world.rand.nextDouble() / 4) - 0.125); + Minecraft.getMinecraft().effectRenderer.addEffect(particle); + } + String sound = Carving.chisel.getVariationSound(base.getItem(), base.getItemDamage()); + GeneralClient.playChiselSound(world, autoChisel.xCoord, autoChisel.yCoord, autoChisel.zCoord, sound); + } + autoChisel.chiseling = false; + } + @SideOnly(Side.CLIENT) public EntityItem getGhostItem(World world, ItemStack itemStack) { if (ghostItem == null) { diff --git a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java index d83930da..ffbb42de 100644 --- a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java +++ b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java @@ -1,6 +1,7 @@ package com.cricketcraft.chisel.network; import com.cricketcraft.chisel.Chisel; +import com.cricketcraft.chisel.network.message.MessageAutoChisel; import com.cricketcraft.chisel.network.message.MessageChiselSound; import com.cricketcraft.chisel.network.message.MessageSlotUpdate; @@ -13,8 +14,9 @@ public class PacketHandler { public static void init() { int id = 0; - + 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); } } \ No newline at end of file diff --git a/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselSound.java b/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselSound.java index a7ec289b..5df9a879 100644 --- a/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselSound.java +++ b/src/main/java/com/cricketcraft/chisel/network/message/MessageChiselSound.java @@ -6,42 +6,37 @@ import net.minecraft.block.Block; import com.cricketcraft.chisel.carving.CarvingVariation; import com.cricketcraft.chisel.client.GeneralChiselClient; import com.cricketcraft.chisel.item.chisel.ItemChisel; +import com.cricketcraft.chisel.network.message.base.MessageCoords; 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 MessageChiselSound implements IMessage { +public class MessageChiselSound extends MessageCoords { public MessageChiselSound() { + super(); } - private int x, y, z; private int block; private byte meta; public MessageChiselSound(int x, int y, int z, CarvingVariation v) { - this.x = x; - this.y = y; - this.z = z; + super(x, y, z); this.block = Block.getIdFromBlock(v.block); this.meta = (byte) v.meta; } @Override public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); + super.toBytes(buf); buf.writeInt(block); buf.writeByte(meta); } @Override public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); + super.fromBytes(buf); block = buf.readInt(); meta = buf.readByte(); } diff --git a/src/main/java/com/cricketcraft/chisel/network/message/MessageSlotUpdate.java b/src/main/java/com/cricketcraft/chisel/network/message/MessageSlotUpdate.java index 51de779f..47a74d85 100644 --- a/src/main/java/com/cricketcraft/chisel/network/message/MessageSlotUpdate.java +++ b/src/main/java/com/cricketcraft/chisel/network/message/MessageSlotUpdate.java @@ -1,47 +1,42 @@ package com.cricketcraft.chisel.network.message; -import com.cricketcraft.chisel.Chisel; - import io.netty.buffer.ByteBuf; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; + +import com.cricketcraft.chisel.Chisel; +import com.cricketcraft.chisel.network.message.base.MessageCoords; + 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 MessageSlotUpdate implements IMessage { +public class MessageSlotUpdate extends MessageCoords { public MessageSlotUpdate() { } - private int x, y, z; private int slot; private ItemStack stack; public MessageSlotUpdate(TileEntity te, int slot, ItemStack stack) { - this.x = te.xCoord; - this.y = te.yCoord; - this.z = te.zCoord; + super(te); this.slot = slot; this.stack = stack; } @Override public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); + super.toBytes(buf); buf.writeInt(slot); ByteBufUtils.writeItemStack(buf, stack); } @Override public void fromBytes(ByteBuf buf) { - this.x = buf.readInt(); - this.y = buf.readInt(); - this.z = buf.readInt(); + super.fromBytes(buf); this.slot = buf.readInt(); this.stack = ByteBufUtils.readItemStack(buf); }