2015-08-18 20:40:55 -04:00
|
|
|
package team.chisel.block.tileentity;
|
2014-10-27 16:26:14 -04:00
|
|
|
|
2015-01-22 21:33:43 -05:00
|
|
|
import java.util.List;
|
2015-01-07 22:45:20 -05:00
|
|
|
|
2015-08-18 20:40:55 -04:00
|
|
|
import com.cricketcraft.chisel.api.IChiselItem;
|
|
|
|
|
|
|
|
|
|
import team.chisel.carving.Carving;
|
|
|
|
|
import team.chisel.client.GeneralChiselClient;
|
|
|
|
|
import team.chisel.init.ChiselItems;
|
|
|
|
|
import team.chisel.network.PacketHandler;
|
|
|
|
|
import team.chisel.network.message.MessageAutoChisel;
|
|
|
|
|
import team.chisel.network.message.MessageSlotUpdate;
|
|
|
|
|
import team.chisel.utils.General;
|
2014-11-24 18:48:10 -05:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-10-27 16:26:14 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-01-07 23:36:27 -05:00
|
|
|
import net.minecraft.util.StatCollector;
|
2015-01-07 19:50:18 -05:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
2014-11-26 20:03:54 -05:00
|
|
|
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
|
2014-10-27 16:26:14 -04:00
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
public enum Upgrade {
|
2015-08-06 00:10:46 -04:00
|
|
|
SPEED,
|
|
|
|
|
AUTOMATION,
|
|
|
|
|
STACK,
|
|
|
|
|
REVERSION;
|
2015-01-07 23:36:27 -05:00
|
|
|
|
|
|
|
|
public String getUnlocalizedName() {
|
2015-01-08 05:46:10 -05:00
|
|
|
return ChiselItems.upgrade.getUnlocalizedName() + "_" + this.name().toLowerCase();
|
2015-01-07 23:36:27 -05:00
|
|
|
}
|
2015-01-09 01:50:32 -05:00
|
|
|
|
2015-01-07 23:36:27 -05:00
|
|
|
public String getLocalizedName() {
|
|
|
|
|
return StatCollector.translateToLocal(getUnlocalizedName() + ".name");
|
|
|
|
|
}
|
2015-01-07 22:45:20 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-09 01:50:32 -05:00
|
|
|
public static final int BASE = 0, TARGET = 1, OUTPUT = 2, CHISEL = 3, MIN_UPGRADE = 4;
|
2015-01-12 00:19:05 -05:00
|
|
|
private static final int FAST_SPEED = 1, SLOW_SPEED = 4;
|
|
|
|
|
|
|
|
|
|
private int progress = 0;
|
2015-01-09 02:09:22 -05:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
private static EntityItem ghostItem;
|
|
|
|
|
boolean equal = false;
|
2015-06-01 18:24:52 -04:00
|
|
|
private ItemStack[] inventory = new ItemStack[8];
|
2015-01-07 19:50:18 -05:00
|
|
|
private String name = "autoChisel";
|
2015-01-09 01:50:32 -05:00
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
// client animation fields
|
|
|
|
|
|
|
|
|
|
// used for floating target
|
2015-01-11 18:23:07 -05:00
|
|
|
public float xRot, yRot, zRot;
|
|
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
// used for chisel item rotation
|
|
|
|
|
public static final int maxRot = 60;
|
|
|
|
|
public static final int rotAmnt = 15;
|
2015-01-11 18:23:07 -05:00
|
|
|
public float chiselRot;
|
2015-01-19 11:23:11 -05:00
|
|
|
public boolean chiseling = false, breakChisel = false;;
|
2015-01-12 17:54:32 -05:00
|
|
|
public int toChisel = 1;
|
2015-01-07 19:50:18 -05:00
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
private ItemStack lastBase;
|
|
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public boolean canUpdate() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack decrStackSize(int slot, int size) {
|
|
|
|
|
if (inventory[slot] != null) {
|
|
|
|
|
ItemStack is;
|
|
|
|
|
if (inventory[slot].stackSize <= size) {
|
|
|
|
|
is = inventory[slot];
|
|
|
|
|
inventory[slot] = null;
|
|
|
|
|
return is;
|
|
|
|
|
} else {
|
|
|
|
|
is = inventory[slot].splitStack(size);
|
|
|
|
|
if (inventory[slot].stackSize == 0)
|
|
|
|
|
inventory[slot] = null;
|
|
|
|
|
return is;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
|
|
|
super.readFromNBT(nbt);
|
|
|
|
|
NBTTagList tags = nbt.getTagList("Items", 10);
|
|
|
|
|
inventory = new ItemStack[getSizeInventory()];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < tags.tagCount(); i++) {
|
|
|
|
|
NBTTagCompound data = tags.getCompoundTagAt(i);
|
|
|
|
|
int j = data.getByte("Slot") & 255;
|
|
|
|
|
|
|
|
|
|
if (j >= 0 && j < inventory.length) {
|
|
|
|
|
inventory[j] = ItemStack.loadItemStackFromNBT(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nbt.hasKey("CustomName", 8)) {
|
|
|
|
|
this.name = nbt.getString("CustomName");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateEntity() {
|
|
|
|
|
|
2015-06-02 00:46:23 -04:00
|
|
|
ItemStack base = inventory[BASE], target = getTarget(), output = inventory[OUTPUT];
|
2015-01-07 19:50:18 -05:00
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
if (!worldObj.isRemote && hasChisel() && base != null && target != null) {
|
|
|
|
|
if (canBeMadeFrom(base, target)) {
|
|
|
|
|
if (progress >= (hasUpgrade(Upgrade.SPEED) ? FAST_SPEED : SLOW_SPEED)) {
|
|
|
|
|
|
|
|
|
|
// reset progress
|
|
|
|
|
progress = 0;
|
|
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// the max possible for this craft
|
|
|
|
|
int canBeMade = target.getMaxStackSize();
|
2015-01-07 19:50:18 -05:00
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// if there are items in the output, they count towards the max we can make
|
|
|
|
|
if (output != null) {
|
|
|
|
|
canBeMade -= output.stackSize;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2015-01-07 22:45:20 -05:00
|
|
|
|
|
|
|
|
// can't make more than we have
|
|
|
|
|
canBeMade = Math.min(base.stackSize, canBeMade);
|
|
|
|
|
|
|
|
|
|
// if we can't make any, forget it
|
|
|
|
|
if (canBeMade <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 00:46:23 -04:00
|
|
|
// result will always be a copy of the target
|
2015-01-07 22:45:20 -05:00
|
|
|
ItemStack chiseled = target.copy();
|
2015-06-02 00:46:23 -04:00
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// if we have the stack upgrade, boost the stack size to the max possible, otherwise just one
|
|
|
|
|
chiseled.stackSize = hasUpgrade(Upgrade.STACK) ? canBeMade : 1;
|
|
|
|
|
|
2015-06-01 18:24:52 -04:00
|
|
|
if (canChisel(chiseled)) {
|
|
|
|
|
// if our output is empty, just use the current result
|
|
|
|
|
if (output == null) {
|
|
|
|
|
setInventorySlotContents(OUTPUT, chiseled);
|
|
|
|
|
} else {
|
|
|
|
|
// otherwise just add our result to the existing stack
|
|
|
|
|
inventory[OUTPUT].stackSize += chiseled.stackSize;
|
|
|
|
|
slotChanged(OUTPUT);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 00:46:23 -04:00
|
|
|
chiselItem(chiseled.stackSize, target);
|
2015-01-12 00:19:05 -05:00
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// remove what we made from the stack
|
|
|
|
|
base.stackSize -= chiseled.stackSize;
|
|
|
|
|
if (base.stackSize <= 0) {
|
2015-01-11 17:21:53 -05:00
|
|
|
setInventorySlotContents(BASE, null); // clear out 0 size itemstacks
|
2015-01-07 22:45:20 -05:00
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2015-01-12 00:19:05 -05:00
|
|
|
} else if (worldObj.getTotalWorldTime() % 10 == 0) {
|
|
|
|
|
progress++;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-01-12 00:19:05 -05:00
|
|
|
} else if (worldObj.isRemote) {
|
|
|
|
|
if (chiseling) {
|
|
|
|
|
chiselRot += rotAmnt;
|
|
|
|
|
if (chiselRot >= maxRot) {
|
2015-06-02 00:46:23 -04:00
|
|
|
chiselItem(0, getTarget());
|
2015-01-12 00:19:05 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
chiselRot = Math.max(chiselRot - rotAmnt, 0);
|
|
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2015-01-07 22:45:20 -05:00
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
|
2015-06-02 00:46:23 -04:00
|
|
|
private ItemStack getTarget() {
|
|
|
|
|
if (inventory[BASE] != null && hasUpgrade(Upgrade.REVERSION)) {
|
|
|
|
|
// if we have a reversion upgrade, use that for the target
|
2015-08-16 15:45:22 -04:00
|
|
|
List<ItemStack> possible = Carving.chisel.getItemsForChiseling(inventory[BASE]);
|
|
|
|
|
return possible.isEmpty() ? null : possible.get(0);
|
2015-06-02 00:46:23 -04:00
|
|
|
} else {
|
|
|
|
|
return inventory[TARGET];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target
|
|
|
|
|
private boolean canBeMadeFrom(ItemStack from, ItemStack to) {
|
2015-01-22 21:33:43 -05:00
|
|
|
List<ItemStack> results = Carving.chisel.getItemsForChiseling(from);
|
2015-01-07 22:45:20 -05:00
|
|
|
for (ItemStack s : results) {
|
|
|
|
|
if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-21 02:54:59 -05:00
|
|
|
private boolean canChisel(ItemStack toMerge) {
|
2015-01-07 22:45:20 -05:00
|
|
|
// if the output slot is empty we can merge without checking
|
|
|
|
|
if (inventory[OUTPUT] == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-06-02 00:46:23 -04:00
|
|
|
|
2015-01-07 22:45:20 -05:00
|
|
|
// need to check NBT as well as item
|
2015-06-02 00:46:23 -04:00
|
|
|
if (!toMerge.isItemEqual(inventory[OUTPUT]) || !ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) {
|
|
|
|
|
return false;
|
2015-01-07 22:45:20 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-02 00:46:23 -04:00
|
|
|
// we only care about metadata if the item has subtypes
|
|
|
|
|
if (toMerge.getHasSubtypes() && toMerge.getItemDamage() != inventory[OUTPUT].getItemDamage()) {
|
|
|
|
|
return false;
|
2015-06-01 18:24:52 -04:00
|
|
|
}
|
2015-06-02 00:46:23 -04:00
|
|
|
|
|
|
|
|
return ((IChiselItem) inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(getTarget()));
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-09 01:50:32 -05:00
|
|
|
private boolean hasChisel() {
|
2015-01-10 04:22:03 -05:00
|
|
|
return inventory[CHISEL] != null && inventory[CHISEL].getItem() instanceof IChiselItem && inventory[CHISEL].stackSize >= 1;
|
2015-01-09 01:50:32 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-11 18:23:07 -05:00
|
|
|
/** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */
|
2015-06-02 00:46:23 -04:00
|
|
|
private void chiselItem(int chiseled, ItemStack target) {
|
2015-01-12 00:19:05 -05:00
|
|
|
if (!worldObj.isRemote) {
|
2015-01-19 11:23:11 -05:00
|
|
|
boolean breakChisel = false;
|
2015-06-02 00:46:23 -04:00
|
|
|
if (((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, inventory[CHISEL], General.getVariation(target))) {
|
|
|
|
|
inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1);
|
|
|
|
|
if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
|
|
|
|
|
setInventorySlotContents(CHISEL, null);
|
|
|
|
|
breakChisel = true;
|
2015-06-01 18:24:52 -04:00
|
|
|
}
|
2015-01-19 10:01:08 -05:00
|
|
|
}
|
2015-06-02 00:46:23 -04:00
|
|
|
PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this, chiseled, true, breakChisel), worldObj.provider.dimensionId);
|
2015-01-12 00:19:05 -05:00
|
|
|
} else {
|
2015-01-19 11:23:11 -05:00
|
|
|
if (breakChisel) {
|
|
|
|
|
worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "random.break", 0.8F, 0.8F + worldObj.rand.nextFloat() * 0.4F, false);
|
|
|
|
|
}
|
2015-01-12 00:19:05 -05:00
|
|
|
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
|
|
|
|
chiseling = false;
|
|
|
|
|
if (lastBase != null) {
|
2015-01-12 17:54:32 -05:00
|
|
|
lastBase.stackSize -= toChisel;
|
2015-01-12 00:19:05 -05:00
|
|
|
if (lastBase.stackSize <= 0) {
|
|
|
|
|
lastBase = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-11 18:23:07 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
|
|
|
super.writeToNBT(nbt);
|
|
|
|
|
NBTTagList tags = new NBTTagList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < inventory.length; i++) {
|
|
|
|
|
if (inventory[i] != null) {
|
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
|
|
|
data.setByte("Slot", (byte) i);
|
|
|
|
|
inventory[i].writeToNBT(data);
|
|
|
|
|
tags.appendTag(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nbt.setTag("Items", tags);
|
|
|
|
|
|
|
|
|
|
if (this.hasCustomInventoryName()) {
|
|
|
|
|
nbt.setString("CustomName", this.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSizeInventory() {
|
|
|
|
|
return inventory.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlot(int slot) {
|
|
|
|
|
return inventory[slot];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
|
|
|
|
if (inventory[slot] != null) {
|
|
|
|
|
ItemStack is = inventory[slot];
|
|
|
|
|
inventory[slot] = null;
|
|
|
|
|
return is;
|
|
|
|
|
} else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
|
|
|
|
inventory[slot] = stack;
|
|
|
|
|
|
|
|
|
|
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
|
|
|
|
|
stack.stackSize = getInventoryStackLimit();
|
|
|
|
|
}
|
2015-01-19 11:23:11 -05:00
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
if (worldObj.isRemote && slot == BASE && stack != null) {
|
|
|
|
|
lastBase = stack.copy();
|
|
|
|
|
}
|
2015-01-11 17:21:53 -05:00
|
|
|
|
|
|
|
|
if (!worldObj.isRemote) {
|
|
|
|
|
slotChanged(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void slotChanged(int slot) {
|
|
|
|
|
PacketHandler.INSTANCE.sendToDimension(new MessageSlotUpdate(this, slot, inventory[slot]), worldObj.provider.dimensionId);
|
2015-01-07 19:50:18 -05:00
|
|
|
markDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getInventoryName() {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public final boolean isUseableByPlayer(EntityPlayer player) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
|
return 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasCustomInventoryName() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side) {
|
2015-01-11 17:21:53 -05:00
|
|
|
return new int[] { BASE, TARGET, OUTPUT, CHISEL };
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
|
2015-01-09 01:50:32 -05:00
|
|
|
if (itemStack == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-09 02:09:22 -05:00
|
|
|
|
|
|
|
|
switch (slot) {
|
|
|
|
|
case BASE:
|
2015-01-09 01:50:32 -05:00
|
|
|
case TARGET:
|
2015-01-22 21:33:43 -05:00
|
|
|
return !Carving.chisel.getItemsForChiseling(itemStack).isEmpty();
|
2015-01-09 01:50:32 -05:00
|
|
|
case OUTPUT:
|
|
|
|
|
return false;
|
2015-01-09 02:09:22 -05:00
|
|
|
case CHISEL:
|
2015-01-09 01:50:32 -05:00
|
|
|
return itemStack.getItem() instanceof IChiselItem;
|
|
|
|
|
default:
|
|
|
|
|
return itemStack.getItem() == ChiselItems.upgrade && Upgrade.values()[slot - MIN_UPGRADE].ordinal() == itemStack.getItemDamage();
|
|
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
2015-01-11 17:21:53 -05:00
|
|
|
return hasUpgrade(Upgrade.AUTOMATION) && (slot == BASE || slot == TARGET || slot == CHISEL);
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
2015-01-09 02:09:22 -05:00
|
|
|
return hasUpgrade(Upgrade.AUTOMATION) && slot == OUTPUT;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void openInventory() {
|
2015-01-10 04:22:03 -05:00
|
|
|
;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void closeInventory() {
|
2015-01-10 04:22:03 -05:00
|
|
|
;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public EntityItem getItemForRendering(int slot) {
|
|
|
|
|
if (ghostItem == null) {
|
|
|
|
|
ghostItem = new EntityItem(worldObj);
|
|
|
|
|
ghostItem.hoverStart = 0.0F;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
if (slot == BASE && lastBase != null) {
|
|
|
|
|
ghostItem.setEntityItemStack(lastBase.copy());
|
|
|
|
|
return ghostItem;
|
2015-06-02 00:46:23 -04:00
|
|
|
} else if (slot == TARGET) {
|
|
|
|
|
ItemStack target = getTarget();
|
|
|
|
|
if (target != null) {
|
|
|
|
|
ghostItem.setEntityItemStack(target);
|
|
|
|
|
return ghostItem;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2015-01-12 00:19:05 -05:00
|
|
|
} else if (inventory[slot] == null) {
|
2015-01-07 19:50:18 -05:00
|
|
|
return null;
|
|
|
|
|
} else {
|
2015-01-19 11:23:11 -05:00
|
|
|
ghostItem.setEntityItemStack(inventory[slot].copy());
|
2015-01-07 19:50:18 -05:00
|
|
|
return ghostItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Packet getDescriptionPacket() {
|
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
|
writeToNBT(tag);
|
|
|
|
|
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
|
|
|
|
readFromNBT(packet.func_148857_g());
|
|
|
|
|
}
|
2015-01-07 22:45:20 -05:00
|
|
|
|
|
|
|
|
public boolean hasUpgrade(Upgrade upgrade) {
|
|
|
|
|
ItemStack stack = inventory[MIN_UPGRADE + upgrade.ordinal()];
|
|
|
|
|
if (stack != null) {
|
2015-01-08 05:46:10 -05:00
|
|
|
return stack.getItem() == ChiselItems.upgrade && stack.getItemDamage() == upgrade.ordinal();
|
2015-01-07 22:45:20 -05:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-09 01:50:32 -05:00
|
|
|
|
|
|
|
|
public String getSlotTooltipUnloc(int slotNumber) {
|
|
|
|
|
String base = "autochisel.slot.%s.tooltip";
|
|
|
|
|
String name = null;
|
|
|
|
|
if (slotNumber < MIN_UPGRADE) {
|
|
|
|
|
if (slotNumber == TARGET) {
|
|
|
|
|
name = "target";
|
|
|
|
|
} else if (slotNumber == CHISEL) {
|
|
|
|
|
name = "chisel";
|
|
|
|
|
}
|
|
|
|
|
return name == null ? null : String.format(base, name);
|
|
|
|
|
} else {
|
|
|
|
|
return Upgrade.values()[slotNumber - MIN_UPGRADE].getUnlocalizedName() + ".name";
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-11 18:23:07 -05:00
|
|
|
|
2015-01-19 11:23:11 -05:00
|
|
|
public void doChiselAnim(ItemStack lastChiseled, int chiseled, boolean playSound, boolean breakChisel) {
|
2015-01-12 00:19:05 -05:00
|
|
|
this.lastBase = lastChiseled == null ? null : lastChiseled.copy();
|
2015-01-12 17:54:32 -05:00
|
|
|
this.toChisel = chiseled;
|
2015-01-12 00:19:05 -05:00
|
|
|
if (playSound) {
|
|
|
|
|
this.chiseling = true;
|
|
|
|
|
}
|
2015-01-19 11:23:11 -05:00
|
|
|
this.breakChisel = breakChisel;
|
2015-01-12 00:19:05 -05:00
|
|
|
}
|
2015-01-19 11:23:11 -05:00
|
|
|
|
2015-01-12 00:19:05 -05:00
|
|
|
public ItemStack getLastBase() {
|
|
|
|
|
return lastBase == null ? null : lastBase.copy();
|
2015-01-11 18:23:07 -05:00
|
|
|
}
|
2014-10-27 16:26:14 -04:00
|
|
|
}
|