Repackage to team.chisel (excepting API)

This commit is contained in:
tterrag1098 committed 2015-08-18 20:40:55 -04:00
1 parent 7555e21144
commit 9574e05c29
132 files changed
+526 -596

No files matched your search

@@ -0,0 +1,54 @@
package team.chisel.network;
import team.chisel.block.tileentity.TileEntityAutoChisel;
import team.chisel.block.tileentity.TileEntityPresent;
import team.chisel.client.gui.GuiAutoChisel;
import team.chisel.client.gui.GuiChisel;
import team.chisel.client.gui.GuiPresent;
import team.chisel.inventory.ContainerAutoChisel;
import team.chisel.inventory.ContainerChisel;
import team.chisel.inventory.ContainerPresent;
import team.chisel.inventory.InventoryChiselSelection;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class ChiselGuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new ContainerChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem()));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)
return new ContainerAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
case 2:
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityPresent)
return new ContainerPresent(player.inventory, (TileEntityPresent) tileEntity);
default:
return null;
}
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new GuiChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem()));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)
return new GuiAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
case 2:
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityPresent)
return new GuiPresent(player.inventory, (TileEntityPresent) tileEntity);
default:
return null;
}
}
}
@@ -0,0 +1,25 @@
package team.chisel.network;
import team.chisel.Chisel;
import team.chisel.network.message.MessageAutoChisel;
import team.chisel.network.message.MessageChiselMode;
import team.chisel.network.message.MessageChiselSound;
import team.chisel.network.message.MessagePresentConnect;
import team.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);
INSTANCE.registerMessage(MessageAutoChisel.Handler.class, MessageAutoChisel.class, id++, Side.CLIENT);
INSTANCE.registerMessage(MessageChiselMode.Handler.class, MessageChiselMode.class, id++, Side.SERVER);
INSTANCE.registerMessage(MessagePresentConnect.Handler.class, MessagePresentConnect.class, id++, Side.CLIENT);
}
}
@@ -0,0 +1,64 @@
package team.chisel.network.message;
import team.chisel.block.tileentity.TileEntityAutoChisel;
import team.chisel.network.message.base.MessageCoords;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
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 MessageAutoChisel extends MessageCoords {
public MessageAutoChisel() {
}
ItemStack base;
boolean playSound, breakChisel;
int chiseled;
public MessageAutoChisel(TileEntityAutoChisel tile, int chiseled, boolean playSound, boolean breakChisel) {
super(tile);
this.base = tile.getStackInSlot(TileEntityAutoChisel.BASE);
if (base != null) {
base = base.copy();
}
this.playSound = playSound;
this.breakChisel = breakChisel;
this.chiseled = chiseled;
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeBoolean(playSound);
buf.writeBoolean(breakChisel);
buf.writeInt(chiseled);
ByteBufUtils.writeItemStack(buf, base);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
this.playSound = buf.readBoolean();
this.breakChisel = buf.readBoolean();
this.chiseled = buf.readInt();
this.base = ByteBufUtils.readItemStack(buf);
}
public static class Handler implements IMessageHandler<MessageAutoChisel, IMessage> {
@Override
public IMessage onMessage(MessageAutoChisel message, MessageContext ctx) {
TileEntity te = message.getTileEntity(ctx);
if (te instanceof TileEntityAutoChisel) {
((TileEntityAutoChisel) te).doChiselAnim(message.base, message.chiseled, message.playSound, message.breakChisel);
}
return null;
}
}
}
@@ -0,0 +1,52 @@
package team.chisel.network.message;
import com.cricketcraft.chisel.api.IAdvancedChisel;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.api.carving.IChiselMode;
import team.chisel.item.chisel.ChiselMode;
import team.chisel.utils.General;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
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(IChiselMode iChiselMode) {
this.mode = iChiselMode.name();
}
@Override
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<MessageChiselMode, IMessage> {
@Override
public IMessage onMessage(MessageChiselMode message, MessageContext ctx) {
ItemStack stack = ctx.getServerHandler().playerEntity.getCurrentEquippedItem();
if (stack != null && stack.getItem() instanceof IChiselItem) {
if (stack.getItem() instanceof IAdvancedChisel) {
General.setChiselMode(stack, ((IAdvancedChisel) stack.getItem()).getMode(stack, message.mode));
} else {
General.setChiselMode(stack, ChiselMode.valueOf(message.mode));
}
}
return null;
}
}
}
@@ -0,0 +1,62 @@
package team.chisel.network.message;
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
import team.chisel.Chisel;
import team.chisel.client.GeneralChiselClient;
import team.chisel.item.chisel.ItemChisel;
import team.chisel.network.message.base.MessageCoords;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
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 extends MessageCoords {
public MessageChiselSound() {
super();
}
private int block;
private byte meta;
private boolean breakChisel;
public MessageChiselSound(int x, int y, int z, ICarvingVariation v, boolean breakChisel) {
super(x, y, z);
this.block = Block.getIdFromBlock(v.getBlock());
this.meta = (byte) v.getBlockMeta();
this.breakChisel = breakChisel;
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeInt(block);
buf.writeByte(meta);
buf.writeBoolean(breakChisel);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
block = buf.readInt();
meta = buf.readByte();
breakChisel = buf.readBoolean();
}
public static class Handler implements IMessageHandler<MessageChiselSound, IMessage> {
@Override
public IMessage onMessage(MessageChiselSound message, MessageContext ctx) {
String sound = ItemChisel.carving.getVariationSound(Block.getBlockById(message.block), message.meta);
GeneralChiselClient.spawnChiselEffect(message.x, message.y, message.z, sound);
if (message.breakChisel) {
EntityPlayer player = Chisel.proxy.getClientPlayer();
player.renderBrokenItemStack(player.getCurrentEquippedItem());
}
return null;
}
}
}
@@ -0,0 +1,64 @@
package team.chisel.network.message;
import team.chisel.block.tileentity.TileEntityPresent;
import team.chisel.network.message.base.MessageCoords;
import io.netty.buffer.ByteBuf;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
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 MessagePresentConnect extends MessageCoords {
private ForgeDirection dir;
private boolean connect, preserveDir;
public MessagePresentConnect() {
super();
}
public MessagePresentConnect(TileEntityPresent present, ForgeDirection dir, boolean connecting) {
this(present, dir, connecting, false);
}
public MessagePresentConnect(TileEntityPresent present, ForgeDirection dir, boolean connecting, boolean preserveDir) {
super(present);
this.dir = dir;
this.connect = connecting;
this.preserveDir = preserveDir;
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeInt(dir.ordinal());
buf.writeBoolean(connect);
buf.writeBoolean(preserveDir);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
dir = ForgeDirection.values()[buf.readInt()];
connect = buf.readBoolean();
preserveDir = buf.readBoolean();
}
public static class Handler implements IMessageHandler<MessagePresentConnect, IMessage> {
@Override
public IMessage onMessage(MessagePresentConnect message, MessageContext ctx) {
TileEntity te = message.getTileEntity(ctx);
if (te instanceof TileEntityPresent) {
if (message.connect) {
((TileEntityPresent) te).connectTo(message.dir);
} else {
((TileEntityPresent) te).disconnect(message.preserveDir);
}
}
return null;
}
}
}
@@ -0,0 +1,54 @@
package team.chisel.network.message;
import team.chisel.Chisel;
import team.chisel.network.message.base.MessageCoords;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
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 extends MessageCoords {
public MessageSlotUpdate() {
}
private int slot;
private ItemStack stack;
public MessageSlotUpdate(TileEntity te, int slot, ItemStack stack) {
super(te);
this.slot = slot;
this.stack = stack;
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeInt(slot);
ByteBufUtils.writeItemStack(buf, stack);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
this.slot = buf.readInt();
this.stack = ByteBufUtils.readItemStack(buf);
}
public static class Handler implements IMessageHandler<MessageSlotUpdate, IMessage> {
@Override
public IMessage onMessage(MessageSlotUpdate message, MessageContext ctx) {
TileEntity te = Chisel.proxy.getClientWorld().getTileEntity(message.x, message.y, message.z);
if (te != null && te instanceof IInventory) {
((IInventory) te).setInventorySlotContents(message.slot, message.stack);
}
return null;
}
}
}
@@ -0,0 +1,59 @@
package team.chisel.network.message.base;
import team.chisel.Chisel;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
public abstract class MessageCoords implements IMessage {
public int x, y, z;
protected MessageCoords() {
;
}
protected MessageCoords(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
protected MessageCoords(TileEntity te) {
this(te.xCoord, te.yCoord, te.zCoord);
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
}
@Override
public void fromBytes(ByteBuf buf) {
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
}
protected Block getBlock(MessageContext ctx) {
return getWorld(ctx).getBlock(x, y, z);
}
protected TileEntity getTileEntity(MessageContext ctx) {
return getWorld(ctx).getTileEntity(x, y, z);
}
protected World getWorld(MessageContext ctx) {
if (ctx.side == Side.CLIENT) {
return Chisel.proxy.getClientWorld();
} else {
return ctx.getServerHandler().playerEntity.worldObj;
}
}
}