Fix autochisel inventory syncing and change autochisel block bounds

This commit is contained in:
tterrag1098 committed 2015-01-11 17:21:53 -05:00
1 parent 1ec6bfddbe
commit 64e390fc1d
6 files changed
+41 -77

No files matched your search

@@ -33,6 +33,7 @@ import com.cricketcraft.chisel.inventory.ContainerChisel;
import com.cricketcraft.chisel.inventory.ContainerPresent;
import com.cricketcraft.chisel.inventory.InventoryChiselSelection;
import com.cricketcraft.chisel.item.chisel.ChiselController;
import com.cricketcraft.chisel.network.PacketHandler;
import com.cricketcraft.chisel.proxy.CommonProxy;
import com.cricketcraft.chisel.utils.General;
import com.cricketcraft.chisel.world.GeneratorChisel;
@@ -1,15 +0,0 @@
package com.cricketcraft.chisel;
import com.cricketcraft.chisel.item.chisel.ChiselController;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(Chisel.MOD_ID);
public static void init() {
INSTANCE.registerMessage(ChiselController.PlaySoundHandler.class, ChiselController.PacketPlaySound.class, 0, Side.CLIENT);
}
}
@@ -20,6 +20,7 @@ public class BlockAutoChisel extends BlockContainer {
public BlockAutoChisel() {
super(Material.rock);
setHardness(1F);
setBlockBounds(0.125f, 0, 0.125f, 0.875f, 0.8125f, 0.875f);
}
@Override
@@ -46,7 +47,7 @@ public class BlockAutoChisel extends BlockContainer {
if (tile != null && tile instanceof TileEntityAutoChisel && !player.isSneaking()) {
player.openGui(Chisel.instance, 1, world, x, y, z);
}
return true;
}
@@ -17,6 +17,8 @@ import net.minecraft.util.StatCollector;
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.MessageSlotUpdate;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -122,22 +124,20 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
if (canMerge(chiseled)) {
// if our output is empty, just use the current result
if (output == null) {
inventory[OUTPUT] = chiseled;
setInventorySlotContents(OUTPUT, chiseled);
} else {
// otherwise just add our result to the existing stack
inventory[OUTPUT].stackSize += chiseled.stackSize;
slotChanged(OUTPUT);
}
// remove what we made from the stack
base.stackSize -= chiseled.stackSize;
if (base.stackSize <= 0) {
inventory[BASE] = null; // clear out 0 size itemstacks
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]);
// we changed something, so we need to tell the chunk to save
markDirty();
}
}
}
@@ -221,6 +221,14 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
if (!worldObj.isRemote) {
slotChanged(slot);
}
}
private void slotChanged(int slot) {
PacketHandler.INSTANCE.sendToDimension(new MessageSlotUpdate(this, slot, inventory[slot]), worldObj.provider.dimensionId);
markDirty();
}
@@ -246,7 +254,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return new int[] { BASE, OUTPUT };
return new int[] { BASE, TARGET, OUTPUT, CHISEL };
}
@Override
@@ -270,7 +278,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
return hasUpgrade(Upgrade.AUTOMATION) && slot == BASE;
return hasUpgrade(Upgrade.AUTOMATION) && (slot == BASE || slot == TARGET || slot == CHISEL);
}
@Override
@@ -1,6 +1,5 @@
package com.cricketcraft.chisel.item.chisel;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -12,17 +11,14 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import org.apache.commons.lang3.ArrayUtils;
import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.PacketHandler;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.carving.CarvingVariation;
import com.cricketcraft.chisel.client.GeneralChiselClient;
import com.cricketcraft.chisel.network.PacketHandler;
import com.cricketcraft.chisel.network.message.MessageChiselSound;
import com.cricketcraft.chisel.utils.General;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
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 final class ChiselController {
@@ -92,56 +88,9 @@ public final class ChiselController {
* Assumes that the player is holding a chisel
*/
private void setVariation(EntityPlayer player, World world, int x, int y, int z, CarvingVariation v, ItemStack target) {
PacketHandler.INSTANCE.sendTo(new PacketPlaySound(x, y, z, v), (EntityPlayerMP) player);
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v), (EntityPlayerMP) player);
world.setBlock(x, y, z, v.block);
world.setBlockMetadataWithNotify(x, y, z, v.meta, 3);
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), target);
}
public static class PacketPlaySound implements IMessage {
public PacketPlaySound() {
}
private int x, y, z;
private int block;
private byte meta;
public PacketPlaySound(int x, int y, int z, CarvingVariation v) {
this.x = x;
this.y = y;
this.z = 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);
buf.writeInt(block);
buf.writeByte(meta);
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
block = buf.readInt();
meta = buf.readByte();
}
}
public static class PlaySoundHandler implements IMessageHandler<PacketPlaySound, IMessage> {
@Override
public IMessage onMessage(PacketPlaySound message, MessageContext ctx) {
String sound = ItemChisel.carving.getVariationSound(Block.getBlockById(message.block), message.meta);
GeneralChiselClient.spawnChiselEffect(message.x, message.y, message.z, sound);
return null;
}
}
}
@@ -0,0 +1,20 @@
package com.cricketcraft.chisel.network;
import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.network.message.MessageChiselSound;
import com.cricketcraft.chisel.network.message.MessageSlotUpdate;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(Chisel.MOD_ID);
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);
}
}