mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-17 11:15:07 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
a314fccd1b
commit
8f026dad8f
161 files changed
+14073
-12846
No files matched your search
@@ -4,26 +4,23 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IDoubleChest {
|
||||
|
||||
/**
|
||||
* @return The size of this specific chest's inventory. Does not account for the connection.
|
||||
*/
|
||||
int getTrueSizeInventory();
|
||||
/**
|
||||
* @return The size of this specific chest's inventory. Does not account for the connection.
|
||||
*/
|
||||
int getTrueSizeInventory();
|
||||
|
||||
/**
|
||||
* @param slot
|
||||
* The true slot index.
|
||||
* @return The actual stack in this chest's slot. Does not account for the connection.
|
||||
*/
|
||||
ItemStack getTrueStackInSlot(int slot);
|
||||
/**
|
||||
* @param slot The true slot index.
|
||||
* @return The actual stack in this chest's slot. Does not account for the connection.
|
||||
*/
|
||||
ItemStack getTrueStackInSlot(int slot);
|
||||
|
||||
/**
|
||||
* Puts a stack in this chest's real slot at the given true index.
|
||||
*
|
||||
* @param slot
|
||||
* The true slot index.
|
||||
* @param stack
|
||||
* The ItemStack to place in the slot.
|
||||
*/
|
||||
void putStackInTrueSlot(int slot, ItemStack stack);
|
||||
/**
|
||||
* Puts a stack in this chest's real slot at the given true index.
|
||||
*
|
||||
* @param slot The true slot index.
|
||||
* @param stack The ItemStack to place in the slot.
|
||||
*/
|
||||
void putStackInTrueSlot(int slot, ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import team.chisel.Features;
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.client.GeneralChiselClient;
|
||||
@@ -30,437 +31,450 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
|
||||
|
||||
public enum Upgrade {
|
||||
SPEED,
|
||||
AUTOMATION,
|
||||
STACK,
|
||||
REVERSION;
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
if (Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
return "item.upgrade_" + this.name().toLowerCase();
|
||||
}
|
||||
return "chisel.autochisel.upgrade.disabled";
|
||||
}
|
||||
|
||||
public String getLocalizedName() {
|
||||
String ret = StatCollector.translateToLocal("autochisel.slot." + this.name().toLowerCase() + ".tooltip");
|
||||
if (!Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
ret = EnumChatFormatting.RED.toString().concat(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int BASE = 0, TARGET = 1, OUTPUT = 2, CHISEL = 3, MIN_UPGRADE = 4;
|
||||
private static final int FAST_SPEED = 1, SLOW_SPEED = 4;
|
||||
|
||||
private int progress = 0;
|
||||
|
||||
private static EntityItem ghostItem;
|
||||
boolean equal = false;
|
||||
private ItemStack[] inventory = new ItemStack[8];
|
||||
private String name = "autoChisel";
|
||||
|
||||
// client animation fields
|
||||
|
||||
// used for floating target
|
||||
public float xRot, yRot, zRot;
|
||||
|
||||
// used for chisel item rotation
|
||||
public static final int maxRot = 60;
|
||||
public static final int rotAmnt = 15;
|
||||
public float chiselRot;
|
||||
public boolean chiseling = false, breakChisel = false;;
|
||||
public int toChisel = 1;
|
||||
|
||||
private ItemStack lastBase;
|
||||
|
||||
@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() {
|
||||
|
||||
ItemStack base = inventory[BASE], target = getTarget(), output = inventory[OUTPUT];
|
||||
|
||||
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;
|
||||
|
||||
// the max possible for this craft
|
||||
int canBeMade = target.getMaxStackSize();
|
||||
|
||||
// if there are items in the output, they count towards the max we can make
|
||||
if (output != null) {
|
||||
canBeMade -= output.stackSize;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// result will always be a copy of the target
|
||||
ItemStack chiseled = target.copy();
|
||||
|
||||
// if we have the stack upgrade, boost the stack size to the max possible, otherwise just one
|
||||
chiseled.stackSize = hasUpgrade(Upgrade.STACK) ? canBeMade : 1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
chiselItem(chiseled.stackSize, target);
|
||||
|
||||
// remove what we made from the stack
|
||||
base.stackSize -= chiseled.stackSize;
|
||||
if (base.stackSize <= 0) {
|
||||
setInventorySlotContents(BASE, null); // clear out 0 size itemstacks
|
||||
}
|
||||
}
|
||||
} else if (worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
progress++;
|
||||
}
|
||||
}
|
||||
} else if (worldObj.isRemote) {
|
||||
if (chiseling) {
|
||||
chiselRot += rotAmnt;
|
||||
if (chiselRot >= maxRot) {
|
||||
chiselItem(0, getTarget());
|
||||
}
|
||||
} else {
|
||||
chiselRot = Math.max(chiselRot - rotAmnt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getTarget() {
|
||||
if (inventory[BASE] != null && hasUpgrade(Upgrade.REVERSION)) {
|
||||
// if we have a reversion upgrade, use that for the target
|
||||
List<ItemStack> possible = Carving.chisel.getItemsForChiseling(inventory[BASE]);
|
||||
return possible.isEmpty() ? null : possible.get(0);
|
||||
} else {
|
||||
return inventory[TARGET];
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
List<ItemStack> results = Carving.chisel.getItemsForChiseling(from);
|
||||
for (ItemStack s : results) {
|
||||
if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean canChisel(ItemStack toMerge) {
|
||||
// if the output slot is empty we can merge without checking
|
||||
if (inventory[OUTPUT] == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// need to check NBT as well as item
|
||||
if (!toMerge.isItemEqual(inventory[OUTPUT]) || !ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we only care about metadata if the item has subtypes
|
||||
if (toMerge.getHasSubtypes() && toMerge.getItemDamage() != inventory[OUTPUT].getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((IChiselItem) inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(getTarget()));
|
||||
}
|
||||
|
||||
private boolean hasChisel() {
|
||||
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(int chiseled, ItemStack target) {
|
||||
if (!worldObj.isRemote) {
|
||||
boolean breakChisel = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this, chiseled, true, breakChisel), worldObj.provider.dimensionId);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
chiseling = false;
|
||||
if (lastBase != null) {
|
||||
lastBase.stackSize -= toChisel;
|
||||
if (lastBase.stackSize <= 0) {
|
||||
lastBase = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
if (worldObj.isRemote && slot == BASE && stack != null) {
|
||||
lastBase = stack.copy();
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
slotChanged(slot);
|
||||
}
|
||||
}
|
||||
|
||||
private void slotChanged(int slot) {
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessageSlotUpdate(this, slot, inventory[slot]), worldObj.provider.dimensionId);
|
||||
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) {
|
||||
return new int[] { BASE, TARGET, OUTPUT, CHISEL };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (slot) {
|
||||
case BASE:
|
||||
case TARGET:
|
||||
return !Carving.chisel.getItemsForChiseling(itemStack).isEmpty();
|
||||
case OUTPUT:
|
||||
return false;
|
||||
case CHISEL:
|
||||
return itemStack.getItem() instanceof IChiselItem;
|
||||
default:
|
||||
return Features.AUTO_CHISEL_UPGRADES.enabled() && itemStack.getItem() == ChiselItems.upgrade && Upgrade.values()[slot - MIN_UPGRADE].ordinal() == itemStack.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
||||
return hasUpgrade(Upgrade.AUTOMATION) && (slot == BASE || slot == TARGET || slot == CHISEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
||||
return hasUpgrade(Upgrade.AUTOMATION) && slot == OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EntityItem getItemForRendering(int slot) {
|
||||
if (ghostItem == null) {
|
||||
ghostItem = new EntityItem(worldObj);
|
||||
ghostItem.hoverStart = 0.0F;
|
||||
}
|
||||
|
||||
if (slot == BASE && lastBase != null) {
|
||||
ghostItem.setEntityItemStack(lastBase.copy());
|
||||
return ghostItem;
|
||||
} else if (slot == TARGET) {
|
||||
ItemStack target = getTarget();
|
||||
if (target != null) {
|
||||
ghostItem.setEntityItemStack(target);
|
||||
return ghostItem;
|
||||
}
|
||||
return null;
|
||||
} else if (inventory[slot] == null) {
|
||||
return null;
|
||||
} else {
|
||||
ghostItem.setEntityItemStack(inventory[slot].copy());
|
||||
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());
|
||||
}
|
||||
|
||||
public boolean hasUpgrade(Upgrade upgrade) {
|
||||
if (Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
ItemStack stack = inventory[MIN_UPGRADE + upgrade.ordinal()];
|
||||
if (stack != null) {
|
||||
return stack.getItem() == ChiselItems.upgrade && stack.getItemDamage() == upgrade.ordinal();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return upgrade == Upgrade.REVERSION ? false : true;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
String unloc = name == null ? null : String.format(base, name);
|
||||
return StatCollector.translateToLocal(unloc);
|
||||
} else {
|
||||
return Upgrade.values()[slotNumber - MIN_UPGRADE].getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
public void doChiselAnim(ItemStack lastChiseled, int chiseled, boolean playSound, boolean breakChisel) {
|
||||
this.lastBase = lastChiseled == null ? null : lastChiseled.copy();
|
||||
this.toChisel = chiseled;
|
||||
if (playSound) {
|
||||
this.chiseling = true;
|
||||
}
|
||||
this.breakChisel = breakChisel;
|
||||
}
|
||||
|
||||
public ItemStack getLastBase() {
|
||||
return lastBase == null ? null : lastBase.copy();
|
||||
}
|
||||
public enum Upgrade {
|
||||
|
||||
SPEED,
|
||||
AUTOMATION,
|
||||
STACK,
|
||||
REVERSION;
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
if (Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
return "item.upgrade_" + this.name().toLowerCase();
|
||||
}
|
||||
return "chisel.autochisel.upgrade.disabled";
|
||||
}
|
||||
|
||||
public String getLocalizedName() {
|
||||
String ret = StatCollector.translateToLocal("autochisel.slot." + this.name().toLowerCase() + ".tooltip");
|
||||
if (!Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
ret = EnumChatFormatting.RED.toString().concat(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int BASE = 0, TARGET = 1, OUTPUT = 2, CHISEL = 3, MIN_UPGRADE = 4;
|
||||
private static final int FAST_SPEED = 1, SLOW_SPEED = 4;
|
||||
|
||||
private int progress = 0;
|
||||
|
||||
private static EntityItem ghostItem;
|
||||
boolean equal = false;
|
||||
private ItemStack[] inventory = new ItemStack[8];
|
||||
private String name = "autoChisel";
|
||||
|
||||
// client animation fields
|
||||
|
||||
// used for floating target
|
||||
public float xRot, yRot, zRot;
|
||||
|
||||
// used for chisel item rotation
|
||||
public static final int maxRot = 60;
|
||||
public static final int rotAmnt = 15;
|
||||
public float chiselRot;
|
||||
public boolean chiseling = false, breakChisel = false;;
|
||||
public int toChisel = 1;
|
||||
|
||||
private ItemStack lastBase;
|
||||
|
||||
@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() {
|
||||
|
||||
ItemStack base = inventory[BASE], target = getTarget(), output = inventory[OUTPUT];
|
||||
|
||||
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;
|
||||
|
||||
// the max possible for this craft
|
||||
int canBeMade = target.getMaxStackSize();
|
||||
|
||||
// if there are items in the output, they count towards the max we can make
|
||||
if (output != null) {
|
||||
canBeMade -= output.stackSize;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// result will always be a copy of the target
|
||||
ItemStack chiseled = target.copy();
|
||||
|
||||
// if we have the stack upgrade, boost the stack size to the max possible, otherwise just one
|
||||
chiseled.stackSize = hasUpgrade(Upgrade.STACK) ? canBeMade : 1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
chiselItem(chiseled.stackSize, target);
|
||||
|
||||
// remove what we made from the stack
|
||||
base.stackSize -= chiseled.stackSize;
|
||||
if (base.stackSize <= 0) {
|
||||
setInventorySlotContents(BASE, null); // clear out 0 size itemstacks
|
||||
}
|
||||
}
|
||||
} else if (worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
progress++;
|
||||
}
|
||||
}
|
||||
} else if (worldObj.isRemote) {
|
||||
if (chiseling) {
|
||||
chiselRot += rotAmnt;
|
||||
if (chiselRot >= maxRot) {
|
||||
chiselItem(0, getTarget());
|
||||
}
|
||||
} else {
|
||||
chiselRot = Math.max(chiselRot - rotAmnt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getTarget() {
|
||||
if (inventory[BASE] != null && hasUpgrade(Upgrade.REVERSION)) {
|
||||
// if we have a reversion upgrade, use that for the target
|
||||
List<ItemStack> possible = Carving.chisel.getItemsForChiseling(inventory[BASE]);
|
||||
return possible.isEmpty() ? null : possible.get(0);
|
||||
} else {
|
||||
return inventory[TARGET];
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
List<ItemStack> results = Carving.chisel.getItemsForChiseling(from);
|
||||
for (ItemStack s : results) {
|
||||
if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean canChisel(ItemStack toMerge) {
|
||||
// if the output slot is empty we can merge without checking
|
||||
if (inventory[OUTPUT] == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// need to check NBT as well as item
|
||||
if (!toMerge.isItemEqual(inventory[OUTPUT]) || !ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we only care about metadata if the item has subtypes
|
||||
if (toMerge.getHasSubtypes() && toMerge.getItemDamage() != inventory[OUTPUT].getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((IChiselItem) inventory[CHISEL].getItem())
|
||||
.canChisel(worldObj, inventory[CHISEL], General.getVariation(getTarget()));
|
||||
}
|
||||
|
||||
private boolean hasChisel() {
|
||||
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(int chiseled, ItemStack target) {
|
||||
if (!worldObj.isRemote) {
|
||||
boolean breakChisel = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToDimension(
|
||||
new MessageAutoChisel(this, chiseled, true, breakChisel),
|
||||
worldObj.provider.dimensionId);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
chiseling = false;
|
||||
if (lastBase != null) {
|
||||
lastBase.stackSize -= toChisel;
|
||||
if (lastBase.stackSize <= 0) {
|
||||
lastBase = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
if (worldObj.isRemote && slot == BASE && stack != null) {
|
||||
lastBase = stack.copy();
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
slotChanged(slot);
|
||||
}
|
||||
}
|
||||
|
||||
private void slotChanged(int slot) {
|
||||
PacketHandler.INSTANCE
|
||||
.sendToDimension(new MessageSlotUpdate(this, slot, inventory[slot]), worldObj.provider.dimensionId);
|
||||
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) {
|
||||
return new int[] { BASE, TARGET, OUTPUT, CHISEL };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (slot) {
|
||||
case BASE:
|
||||
case TARGET:
|
||||
return !Carving.chisel.getItemsForChiseling(itemStack).isEmpty();
|
||||
case OUTPUT:
|
||||
return false;
|
||||
case CHISEL:
|
||||
return itemStack.getItem() instanceof IChiselItem;
|
||||
default:
|
||||
return Features.AUTO_CHISEL_UPGRADES.enabled() && itemStack.getItem() == ChiselItems.upgrade
|
||||
&& Upgrade.values()[slot - MIN_UPGRADE].ordinal() == itemStack.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
||||
return hasUpgrade(Upgrade.AUTOMATION) && (slot == BASE || slot == TARGET || slot == CHISEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
||||
return hasUpgrade(Upgrade.AUTOMATION) && slot == OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EntityItem getItemForRendering(int slot) {
|
||||
if (ghostItem == null) {
|
||||
ghostItem = new EntityItem(worldObj);
|
||||
ghostItem.hoverStart = 0.0F;
|
||||
}
|
||||
|
||||
if (slot == BASE && lastBase != null) {
|
||||
ghostItem.setEntityItemStack(lastBase.copy());
|
||||
return ghostItem;
|
||||
} else if (slot == TARGET) {
|
||||
ItemStack target = getTarget();
|
||||
if (target != null) {
|
||||
ghostItem.setEntityItemStack(target);
|
||||
return ghostItem;
|
||||
}
|
||||
return null;
|
||||
} else if (inventory[slot] == null) {
|
||||
return null;
|
||||
} else {
|
||||
ghostItem.setEntityItemStack(inventory[slot].copy());
|
||||
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());
|
||||
}
|
||||
|
||||
public boolean hasUpgrade(Upgrade upgrade) {
|
||||
if (Features.AUTO_CHISEL_UPGRADES.enabled()) {
|
||||
ItemStack stack = inventory[MIN_UPGRADE + upgrade.ordinal()];
|
||||
if (stack != null) {
|
||||
return stack.getItem() == ChiselItems.upgrade && stack.getItemDamage() == upgrade.ordinal();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return upgrade == Upgrade.REVERSION ? false : true;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
String unloc = name == null ? null : String.format(base, name);
|
||||
return StatCollector.translateToLocal(unloc);
|
||||
} else {
|
||||
return Upgrade.values()[slotNumber - MIN_UPGRADE].getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
public void doChiselAnim(ItemStack lastChiseled, int chiseled, boolean playSound, boolean breakChisel) {
|
||||
this.lastBase = lastChiseled == null ? null : lastChiseled.copy();
|
||||
this.toChisel = chiseled;
|
||||
if (playSound) {
|
||||
this.chiseling = true;
|
||||
}
|
||||
this.breakChisel = breakChisel;
|
||||
}
|
||||
|
||||
public ItemStack getLastBase() {
|
||||
return lastBase == null ? null : lastBase.copy();
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,15 @@ package team.chisel.block.tileentity;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityBeacon;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityCarvableBeacon extends TileEntityBeacon {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
package team.chisel.block.tileentity;
|
||||
|
||||
import team.chisel.init.ChiselBlocks;
|
||||
import team.chisel.network.PacketHandler;
|
||||
import team.chisel.network.message.MessagePresentConnect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -17,349 +14,358 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import team.chisel.init.ChiselBlocks;
|
||||
import team.chisel.network.PacketHandler;
|
||||
import team.chisel.network.message.MessagePresentConnect;
|
||||
|
||||
public class TileEntityPresent extends TileEntity implements IInventory, IDoubleChest {
|
||||
|
||||
private TileEntityPresent connection = null;
|
||||
// If cachedDir is non-null, but connection is null, this present must be
|
||||
// connected to an unloaded present. This is handled appropriately.
|
||||
private ForgeDirection cachedDir = null;
|
||||
private boolean isParent;
|
||||
private final ItemStack[] inventory = new ItemStack[27];
|
||||
private int rotation;
|
||||
private boolean autoSearch = true;
|
||||
private TileEntityPresent connection = null;
|
||||
// If cachedDir is non-null, but connection is null, this present must be
|
||||
// connected to an unloaded present. This is handled appropriately.
|
||||
private ForgeDirection cachedDir = null;
|
||||
private boolean isParent;
|
||||
private final ItemStack[] inventory = new ItemStack[27];
|
||||
private int rotation;
|
||||
private boolean autoSearch = true;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (!isConnected() && autoSearch && worldObj != null /* ugh */) {
|
||||
if (cachedDir != null) {
|
||||
connectTo(cachedDir);
|
||||
} else if (!worldObj.isRemote) {
|
||||
findConnections();
|
||||
}
|
||||
autoSearch = false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (!isConnected() && autoSearch && worldObj != null /* ugh */) {
|
||||
if (cachedDir != null) {
|
||||
connectTo(cachedDir);
|
||||
} else if (!worldObj.isRemote) {
|
||||
findConnections();
|
||||
}
|
||||
autoSearch = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connection != null;
|
||||
}
|
||||
public boolean isConnected() {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
private boolean connectTo(TileEntityPresent present, ForgeDirection dir) {
|
||||
if (present.getBlockMetadata() == getBlockMetadata() && !present.isConnected() && (present.cachedDir == null || present.cachedDir == dir.getOpposite())
|
||||
&& Math.abs(present.xCoord - xCoord + present.yCoord - yCoord + present.zCoord - zCoord) == 1) {
|
||||
connection = present;
|
||||
connection.connection = this;
|
||||
connection.cachedDir = dir.getOpposite();
|
||||
connection.markDirty();
|
||||
cachedDir = dir;
|
||||
isParent = !present.isParent;
|
||||
markDirty();
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, dir, true), worldObj.provider.dimensionId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean connectTo(TileEntityPresent present, ForgeDirection dir) {
|
||||
if (present.getBlockMetadata() == getBlockMetadata() && !present.isConnected()
|
||||
&& (present.cachedDir == null || present.cachedDir == dir.getOpposite())
|
||||
&& Math.abs(present.xCoord - xCoord + present.yCoord - yCoord + present.zCoord - zCoord) == 1) {
|
||||
connection = present;
|
||||
connection.connection = this;
|
||||
connection.cachedDir = dir.getOpposite();
|
||||
connection.markDirty();
|
||||
cachedDir = dir;
|
||||
isParent = !present.isParent;
|
||||
markDirty();
|
||||
PacketHandler.INSTANCE
|
||||
.sendToDimension(new MessagePresentConnect(this, dir, true), worldObj.provider.dimensionId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectTo(ForgeDirection dir) {
|
||||
int x = xCoord + dir.offsetX, y = yCoord + dir.offsetY, z = zCoord + dir.offsetZ;
|
||||
TileEntity te = getTileSafe(x, y, z);
|
||||
if (te instanceof TileEntityPresent) {
|
||||
return connectTo((TileEntityPresent) te, dir);
|
||||
}
|
||||
return !exists(x, y, z);
|
||||
}
|
||||
public boolean connectTo(ForgeDirection dir) {
|
||||
int x = xCoord + dir.offsetX, y = yCoord + dir.offsetY, z = zCoord + dir.offsetZ;
|
||||
TileEntity te = getTileSafe(x, y, z);
|
||||
if (te instanceof TileEntityPresent) {
|
||||
return connectTo((TileEntityPresent) te, dir);
|
||||
}
|
||||
return !exists(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preserveDir
|
||||
* If true, this is only a virtual disconnect, meaning the other chest still exists, but is still loaded, so maintain a cachedDir for reconnection upon chunk load.
|
||||
*/
|
||||
public void disconnect(boolean preserveDir) {
|
||||
if (isConnected()) {
|
||||
if (!preserveDir) {
|
||||
this.connection.cachedDir = null;
|
||||
this.cachedDir = null;
|
||||
}
|
||||
this.connection.connection = null;
|
||||
this.connection.markDirty();
|
||||
this.connection = null;
|
||||
this.markDirty();
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, ForgeDirection.UNKNOWN, false, preserveDir), worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param preserveDir If true, this is only a virtual disconnect, meaning the other chest still exists, but is still
|
||||
* loaded, so maintain a cachedDir for reconnection upon chunk load.
|
||||
*/
|
||||
public void disconnect(boolean preserveDir) {
|
||||
if (isConnected()) {
|
||||
if (!preserveDir) {
|
||||
this.connection.cachedDir = null;
|
||||
this.cachedDir = null;
|
||||
}
|
||||
this.connection.connection = null;
|
||||
this.connection.markDirty();
|
||||
this.connection = null;
|
||||
this.markDirty();
|
||||
PacketHandler.INSTANCE.sendToDimension(
|
||||
new MessagePresentConnect(this, ForgeDirection.UNKNOWN, false, preserveDir),
|
||||
worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntityPresent getConnection() {
|
||||
return connection;
|
||||
}
|
||||
public TileEntityPresent getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public ForgeDirection getConnectionDir() {
|
||||
return cachedDir == null ? ForgeDirection.UNKNOWN : cachedDir;
|
||||
}
|
||||
public ForgeDirection getConnectionDir() {
|
||||
return cachedDir == null ? ForgeDirection.UNKNOWN : cachedDir;
|
||||
}
|
||||
|
||||
public boolean isParent() {
|
||||
return isParent || !isConnected();
|
||||
}
|
||||
public boolean isParent() {
|
||||
return isParent || !isConnected();
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(int rot) {
|
||||
this.rotation = rot;
|
||||
}
|
||||
public void setRotation(int rot) {
|
||||
this.rotation = rot;
|
||||
}
|
||||
|
||||
public void findConnections() {
|
||||
if (!isConnected()) {
|
||||
if (cachedDir != null) {
|
||||
if (connectTo(cachedDir)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN) {
|
||||
if (connectTo(dir)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void findConnections() {
|
||||
if (!isConnected()) {
|
||||
if (cachedDir != null) {
|
||||
if (connectTo(cachedDir)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN) {
|
||||
if (connectTo(dir)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntityPresent getParent() {
|
||||
return isParent || connection == null ? this : connection;
|
||||
}
|
||||
public TileEntityPresent getParent() {
|
||||
return isParent || connection == null ? this : connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return ChiselBlocks.present.getBoundingBox(this);
|
||||
}
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return ChiselBlocks.present.getBoundingBox(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < getTrueSizeInventory(); ++i) {
|
||||
if (inventory[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < getTrueSizeInventory(); ++i) {
|
||||
if (inventory[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
tag.setTag("Items", nbttaglist);
|
||||
tag.setBoolean("isParent", isParent);
|
||||
tag.setInteger("rotation", rotation);
|
||||
if (cachedDir != null) {
|
||||
tag.setInteger("conDir", cachedDir.ordinal());
|
||||
}
|
||||
}
|
||||
tag.setTag("Items", nbttaglist);
|
||||
tag.setBoolean("isParent", isParent);
|
||||
tag.setInteger("rotation", rotation);
|
||||
if (cachedDir != null) {
|
||||
tag.setInteger("conDir", cachedDir.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
NBTTagList nbttaglist = tag.getTagList("Items", 10);
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
NBTTagList nbttaglist = tag.getTagList("Items", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound1.getByte("Slot") & 255;
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound1.getByte("Slot") & 255;
|
||||
|
||||
if (j >= 0 && j < getTrueSizeInventory()) {
|
||||
inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
if (j >= 0 && j < getTrueSizeInventory()) {
|
||||
inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
this.isParent = tag.getBoolean("isParent");
|
||||
this.isParent = tag.getBoolean("isParent");
|
||||
|
||||
this.rotation = tag.getInteger("rotation");
|
||||
if (tag.hasKey("conDir")) {
|
||||
cachedDir = ForgeDirection.values()[tag.getInteger("conDir")];
|
||||
}
|
||||
autoSearch = true;
|
||||
}
|
||||
this.rotation = tag.getInteger("rotation");
|
||||
if (tag.hasKey("conDir")) {
|
||||
cachedDir = ForgeDirection.values()[tag.getInteger("conDir")];
|
||||
}
|
||||
autoSearch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||
readFromNBT(packet.func_148857_g());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z) {
|
||||
// prevent losing TE data when in-world chiseling
|
||||
return oldBlock != newBlock;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y,
|
||||
int z) {
|
||||
// prevent losing TE data when in-world chiseling
|
||||
return oldBlock != newBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
if (isConnected()) {
|
||||
disconnect(false);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
if (isConnected()) {
|
||||
disconnect(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
if (isConnected()) {
|
||||
disconnect(true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
if (isConnected()) {
|
||||
disconnect(true);
|
||||
}
|
||||
}
|
||||
|
||||
private int getAdjustedSlot(int slot) {
|
||||
slot %= getSizeInventory();
|
||||
if (isConnected() && !isParent) {
|
||||
slot = (slot + getTrueSizeInventory()) % getSizeInventory();
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
private int getAdjustedSlot(int slot) {
|
||||
slot %= getSizeInventory();
|
||||
if (isConnected() && !isParent) {
|
||||
slot = (slot + getTrueSizeInventory()) % getSizeInventory();
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
private TileEntity getTileSafe(int x, int y, int z) {
|
||||
if (exists(x, y, z)) {
|
||||
return worldObj.getTileEntity(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private TileEntity getTileSafe(int x, int y, int z) {
|
||||
if (exists(x, y, z)) {
|
||||
return worldObj.getTileEntity(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// private Block getBlockSafe(int x, int y, int z) {
|
||||
// if (exists(x, y, z)) {
|
||||
// return worldObj.getBlock(x, y, z);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private int getMetaSafe(int x, int y, int z) {
|
||||
// if (exists(x, y, z)) {
|
||||
// return worldObj.getBlockMetadata(x, y, z);
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
private boolean exists(int x, int y, int z) {
|
||||
return worldObj.blockExists(x, y, z);
|
||||
}
|
||||
// private Block getBlockSafe(int x, int y, int z) {
|
||||
// if (exists(x, y, z)) {
|
||||
// return worldObj.getBlock(x, y, z);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private int getMetaSafe(int x, int y, int z) {
|
||||
// if (exists(x, y, z)) {
|
||||
// return worldObj.getBlockMetadata(x, y, z);
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
private boolean exists(int x, int y, int z) {
|
||||
return worldObj.blockExists(x, y, z);
|
||||
}
|
||||
|
||||
/* IInventory */
|
||||
/* IInventory */
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return isConnected() ? getTrueSizeInventory() + connection.getTrueSizeInventory() : getTrueSizeInventory();
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return isConnected() ? getTrueSizeInventory() + connection.getTrueSizeInventory() : getTrueSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
if (slot >= getTrueSizeInventory()) {
|
||||
return isConnected() ? connection.inventory[slot % getTrueSizeInventory()] : null;
|
||||
} else {
|
||||
return inventory[slot];
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
if (slot >= getTrueSizeInventory()) {
|
||||
return isConnected() ? connection.inventory[slot % getTrueSizeInventory()] : null;
|
||||
} else {
|
||||
return inventory[slot];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
ItemStack[] inv = inventory;
|
||||
if (isConnected() && slot >= getTrueSizeInventory()) {
|
||||
inv = connection.inventory;
|
||||
slot %= getTrueSizeInventory();
|
||||
connection.markDirty();
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
ItemStack[] inv = inventory;
|
||||
if (isConnected() && slot >= getTrueSizeInventory()) {
|
||||
inv = connection.inventory;
|
||||
slot %= getTrueSizeInventory();
|
||||
connection.markDirty();
|
||||
}
|
||||
|
||||
if (inv[slot] != null) {
|
||||
ItemStack itemstack;
|
||||
if (inv[slot] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (inv[slot].stackSize <= amount) {
|
||||
itemstack = inv[slot];
|
||||
inv[slot] = null;
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = inv[slot].splitStack(amount);
|
||||
if (inv[slot].stackSize <= amount) {
|
||||
itemstack = inv[slot];
|
||||
inv[slot] = null;
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = inv[slot].splitStack(amount);
|
||||
|
||||
if (inv[slot].stackSize == 0) {
|
||||
inv[slot] = null;
|
||||
}
|
||||
if (inv[slot].stackSize == 0) {
|
||||
inv[slot] = null;
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getStackInSlot(slot);
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
if (slot < getTrueSizeInventory()) {
|
||||
inventory[slot] = stack;
|
||||
} else if (isConnected()) {
|
||||
connection.inventory[slot % getTrueSizeInventory()] = stack;
|
||||
connection.markDirty();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
slot = getAdjustedSlot(slot);
|
||||
if (slot < getTrueSizeInventory()) {
|
||||
inventory[slot] = stack;
|
||||
} else if (isConnected()) {
|
||||
connection.inventory[slot % getTrueSizeInventory()] = stack;
|
||||
connection.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "chisel.present";
|
||||
}
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "chisel.present";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
;
|
||||
}
|
||||
@Override
|
||||
public void openInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
;
|
||||
}
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IDoubleChest */
|
||||
/* IDoubleChest */
|
||||
|
||||
@Override
|
||||
public int getTrueSizeInventory() {
|
||||
return inventory.length;
|
||||
}
|
||||
@Override
|
||||
public int getTrueSizeInventory() {
|
||||
return inventory.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTrueStackInSlot(int slot) {
|
||||
return inventory[slot % getTrueSizeInventory()];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getTrueStackInSlot(int slot) {
|
||||
return inventory[slot % getTrueSizeInventory()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInTrueSlot(int slot, ItemStack stack) {
|
||||
inventory[slot % getTrueSizeInventory()] = stack;
|
||||
}
|
||||
@Override
|
||||
public void putStackInTrueSlot(int slot, ItemStack stack) {
|
||||
inventory[slot % getTrueSizeInventory()] = stack;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user