tile still wont save inventory
This commit is contained in:
@@ -43,7 +43,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
/**
|
||||
* Created by mminaie on 4/9/17.
|
||||
*/
|
||||
public class Breaker extends CustomContainerFacing implements ITileEntityProvider {
|
||||
public class Breaker extends CustomContainerFacing {
|
||||
|
||||
public static final PropertyBool ACTIVE = PropertyBool.create("active");
|
||||
|
||||
@@ -60,6 +60,7 @@ public class Breaker extends CustomContainerFacing implements ITileEntityProvide
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitx, float hity, float hitz) {
|
||||
|
||||
if(!world.isRemote){
|
||||
System.out.println("tile: " + pos);
|
||||
TileBreaker tile = (TileBreaker) world.getTileEntity(pos);
|
||||
ItemStack pItem = player.inventory.getCurrentItem();
|
||||
if(state.getValue(ACTIVE) == true && player.isSneaking() && pItem.isEmpty()){
|
||||
@@ -125,7 +126,7 @@ public class Breaker extends CustomContainerFacing implements ITileEntityProvide
|
||||
System.out.println(pItem);
|
||||
tile.setSlotStack(0, pItem);
|
||||
pItem.shrink(1);
|
||||
System.out.println(tile.getSlotStack(0) + " " + tile.getSlotListSize());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package nmd.primal.forgecraft.tiles;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mminaie on 4/9/17.
|
||||
*/
|
||||
public class TileBreaker extends BaseTile {
|
||||
public class TileBreaker extends TileBaseSlot implements ITickable {
|
||||
|
||||
private float charge;
|
||||
|
||||
@@ -22,71 +25,19 @@ public class TileBreaker extends BaseTile {
|
||||
this.charge = charge;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> slotList = NonNullList.<ItemStack>withSize(2, ItemStack.EMPTY);
|
||||
//public NonNullList<ItemStack> slotList = NonNullList.<ItemStack>withSize(2, ItemStack.EMPTY);
|
||||
|
||||
// ***************************************************************************** //
|
||||
// Controls
|
||||
// ***************************************************************************** //
|
||||
|
||||
// ***************************************************************************** //
|
||||
// get
|
||||
//
|
||||
public NonNullList<ItemStack> getSlotList()
|
||||
{
|
||||
return this.slotList;
|
||||
}
|
||||
|
||||
public ItemStack getSlotStack(int i)
|
||||
{
|
||||
return this.slotList.get(i);
|
||||
}
|
||||
|
||||
public int getSlotListSize()
|
||||
{
|
||||
return slotList.size();
|
||||
}
|
||||
|
||||
public int getSlotLimit()
|
||||
{
|
||||
//return ((ShelfBasic)this.getBlockType()).getShelfSize();
|
||||
//return 1;
|
||||
return 64;
|
||||
}
|
||||
|
||||
public ItemStack decrStackSize(int index, int count)
|
||||
{
|
||||
return ItemStackHelper.getAndSplit(this.getSlotList(), index, count);
|
||||
}
|
||||
|
||||
public ItemStack incrementStackSize(List<ItemStack> stacks, int index, int count) {
|
||||
Integer tempCount = ((ItemStack)stacks.get(index)).getCount();
|
||||
ItemStack tempStack = ((ItemStack)stacks.get(index));
|
||||
if(tempCount + count > 64) {
|
||||
tempStack.setCount(64);
|
||||
@Override
|
||||
public void update () {
|
||||
World world = this.getWorld();
|
||||
if (!world.isRemote) {
|
||||
IBlockState state = world.getBlockState(this.pos);
|
||||
for(int i =0; i < this.getSlotListSize(); i++) {
|
||||
System.out.println(this.getSlotStack(i));
|
||||
}
|
||||
}
|
||||
if(tempCount + count <= 64) {
|
||||
tempStack.setCount(tempCount + count);
|
||||
}
|
||||
|
||||
return tempStack;
|
||||
}
|
||||
|
||||
// ***************************************************************************** //
|
||||
// set
|
||||
//
|
||||
public void setSlotStack(int index, ItemStack stack)
|
||||
{
|
||||
this.slotList.set(index, stack);
|
||||
this.markDirty();
|
||||
this.updateBlock();
|
||||
}
|
||||
|
||||
public void clearSlots()
|
||||
{
|
||||
this.slotList.clear();
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************** //
|
||||
// NBT
|
||||
// ***************************************************************************** //
|
||||
@@ -94,18 +45,16 @@ public class TileBreaker extends BaseTile {
|
||||
public NBTTagCompound readNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readNBT(nbt);
|
||||
this.slotList = NonNullList.<ItemStack>withSize(this.getSlotListSize(), ItemStack.EMPTY);
|
||||
ItemStackHelper.loadAllItems(nbt, this.slotList);
|
||||
|
||||
this.charge = nbt.getFloat("charge");
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setFloat("charge", this.charge);
|
||||
super.writeNBT(nbt);
|
||||
ItemStackHelper.saveAllItems(nbt, this.slotList);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user