mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 00:07:37 +00:00
I have no idea why this gets NPE's all the time
This commit is contained in:
1 parent
55aac1030b
commit
d64a379b41
5 files changed
+99
-15
No files matched your search
@@ -2,6 +2,8 @@ package com.cricketcraft.chisel.block.tileentity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvingUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -29,7 +31,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
|
||||
|
||||
public enum Upgrade {
|
||||
SPEED, AUTOMATION, STACK;
|
||||
SPEED, AUTOMATION, STACK, REVERSION;
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return ChiselItems.upgrade.getUnlocalizedName() + "_" + this.name().toLowerCase();
|
||||
@@ -47,7 +49,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
private static EntityItem ghostItem;
|
||||
boolean equal = false;
|
||||
private ItemStack[] inventory = new ItemStack[7];
|
||||
private ItemStack[] inventory = new ItemStack[8];
|
||||
private String name = "autoChisel";
|
||||
|
||||
// client animation fields
|
||||
@@ -114,7 +116,6 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
if (!worldObj.isRemote && hasChisel() && base != null && target != null) {
|
||||
if (canBeMadeFrom(base, target)) {
|
||||
|
||||
if (progress >= (hasUpgrade(Upgrade.SPEED) ? FAST_SPEED : SLOW_SPEED)) {
|
||||
|
||||
// reset progress
|
||||
@@ -141,6 +142,65 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
// 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);
|
||||
|
||||
// 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 && hasChisel() && base != null && hasUpgrade(Upgrade.REVERSION)){
|
||||
if(Carving.chisel.getItemsForChiseling(base) != null){
|
||||
if (progress >= (hasUpgrade(Upgrade.SPEED) ? FAST_SPEED : SLOW_SPEED)) {
|
||||
|
||||
// reset progress
|
||||
progress = 0;
|
||||
|
||||
// the max possible for this craft
|
||||
int canBeMade = base.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;
|
||||
}
|
||||
ItemStack chiseled;
|
||||
if(Carving.chisel.getItemsForChiseling(inventory[TARGET]).get(0) != null){
|
||||
|
||||
// result will always be a copy of the target, of course
|
||||
chiseled = inventory[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;
|
||||
} else {
|
||||
// result will always be a copy of the target, of course
|
||||
chiseled = base.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) {
|
||||
@@ -197,7 +257,11 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
return !toMerge.getHasSubtypes() || toMerge.getItemDamage() == inventory[OUTPUT].getItemDamage();
|
||||
}
|
||||
|
||||
return ((IChiselItem)inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(inventory[TARGET]));
|
||||
if(inventory[TARGET] == null){
|
||||
return ((IChiselItem)inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(inventory[BASE]));
|
||||
} else {
|
||||
return ((IChiselItem)inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(inventory[TARGET]));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasChisel() {
|
||||
@@ -208,14 +272,27 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
private void chiselItem(int chiseled) {
|
||||
if (!worldObj.isRemote) {
|
||||
boolean breakChisel = false;
|
||||
if (((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, inventory[CHISEL], General.getVariation(inventory[TARGET]))) {
|
||||
inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1);
|
||||
if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
|
||||
setInventorySlotContents(CHISEL, null);
|
||||
breakChisel = true;
|
||||
if(inventory[TARGET] == null){
|
||||
if (((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, inventory[CHISEL], CarvingUtils.getDefaultVariationFor(Block.getBlockFromItem(inventory[TARGET].getItem()), inventory[TARGET].getItemDamage(), General.getVariation(inventory[TARGET]).getOrder()))) {
|
||||
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 (((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, inventory[CHISEL], General.getVariation(inventory[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);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -25,9 +25,10 @@ public class ContainerAutoChisel extends Container {
|
||||
addSlot(tileEntityAutoChisel, 1, 78, 52);
|
||||
addSlot(tileEntityAutoChisel, 2, 103, 15);
|
||||
addSlot(tileEntityAutoChisel, 3, 8, 62);
|
||||
addSlot(tileEntityAutoChisel, 4, 151, 11);
|
||||
addSlot(tileEntityAutoChisel, 5, 151, 31);
|
||||
addSlot(tileEntityAutoChisel, 6, 151, 51);
|
||||
addSlot(tileEntityAutoChisel, 4, 151, 5);
|
||||
addSlot(tileEntityAutoChisel, 5, 151, 25);
|
||||
addSlot(tileEntityAutoChisel, 6, 151, 45);
|
||||
addSlot(tileEntityAutoChisel, 7, 151, 65);
|
||||
|
||||
bindPlayerInventory(player);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel.Upgrade;
|
||||
|
||||
public class ItemUpgrade extends BaseItem {
|
||||
|
||||
public IIcon[] icons = new IIcon[3];
|
||||
public IIcon[] icons = new IIcon[4];
|
||||
|
||||
public ItemUpgrade(String unlocalizedName) {
|
||||
super();
|
||||
@@ -40,7 +40,7 @@ public class ItemUpgrade extends BaseItem {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < Upgrade.values().length; i++) {
|
||||
list.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user