Blockstates for disk drive slots

This commit is contained in:
Raoul Van den Berge
2016-09-26 00:01:00 +02:00
parent 8ba64dffab
commit 72fde5ce31
3 changed files with 98 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
package refinedstorage.block;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -18,6 +19,15 @@ import refinedstorage.tile.TileDiskDrive;
public class BlockDiskDrive extends BlockNode {
private static final PropertyInteger STORED = PropertyInteger.create("stored", 0, 7);
private static final PropertyBool FILLED_0 = PropertyBool.create("filled_0");
private static final PropertyBool FILLED_1 = PropertyBool.create("filled_1");
private static final PropertyBool FILLED_2 = PropertyBool.create("filled_2");
private static final PropertyBool FILLED_3 = PropertyBool.create("filled_3");
private static final PropertyBool FILLED_4 = PropertyBool.create("filled_4");
private static final PropertyBool FILLED_5 = PropertyBool.create("filled_5");
private static final PropertyBool FILLED_6 = PropertyBool.create("filled_6");
private static final PropertyBool FILLED_7 = PropertyBool.create("filled_7");
public BlockDiskDrive() {
super("disk_drive");
}
@@ -31,13 +41,33 @@ public class BlockDiskDrive extends BlockNode {
public BlockStateContainer createBlockState() {
return createBlockStateBuilder()
.add(STORED)
.add(FILLED_0)
.add(FILLED_1)
.add(FILLED_2)
.add(FILLED_3)
.add(FILLED_4)
.add(FILLED_5)
.add(FILLED_6)
.add(FILLED_7)
.build();
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return super.getActualState(state, world, pos)
.withProperty(STORED, Math.max(0, ((TileDiskDrive) world.getTileEntity(pos)).getStoredForDisplay()));
TileDiskDrive diskDrive = (TileDiskDrive) world.getTileEntity(pos);
state = super.getActualState(state, world, pos);
state = state.withProperty(STORED, Math.max(0, diskDrive.getStoredForDisplay()));
state = state.withProperty(FILLED_0, diskDrive.getFilled()[0]);
state = state.withProperty(FILLED_1, diskDrive.getFilled()[1]);
state = state.withProperty(FILLED_2, diskDrive.getFilled()[2]);
state = state.withProperty(FILLED_3, diskDrive.getFilled()[3]);
state = state.withProperty(FILLED_4, diskDrive.getFilled()[4]);
state = state.withProperty(FILLED_5, diskDrive.getFilled()[5]);
state = state.withProperty(FILLED_6, diskDrive.getFilled()[6]);
state = state.withProperty(FILLED_7, diskDrive.getFilled()[7]);
return state;
}
@Override

View File

@@ -86,6 +86,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
private static final String NBT_MODE = "Mode";
private static final String NBT_STORED = "Stored";
private static final String NBT_TYPE = "Type";
private static final String NBT_FILLED = "Filled_%d";
private ItemHandlerBasic disks = new ItemHandlerBasic(8, this, IItemValidator.STORAGE_DISK) {
@Override
@@ -99,6 +100,10 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
network.getItemStorage().rebuild();
network.getFluidStorage().rebuild();
}
if (worldObj != null) {
updateBlock();
}
}
}
@@ -128,6 +133,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
private int type = IType.ITEMS;
private int stored = 0;
private boolean[] filled = new boolean[8];
public TileDiskDrive() {
dataManager.addWatchedParameter(PRIORITY);
@@ -263,6 +269,10 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
tag.setInteger(NBT_STORED, stored);
for (int i = 0; i < 8; ++i) {
tag.setBoolean(String.format(NBT_FILLED, i), disks.getStackInSlot(i) != null);
}
return tag;
}
@@ -270,9 +280,17 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
public void readUpdate(NBTTagCompound tag) {
stored = tag.getInteger(NBT_STORED);
for (int i = 0; i < 8; ++i) {
filled[i] = tag.getBoolean(String.format(NBT_FILLED, i));
}
super.readUpdate(tag);
}
public boolean[] getFilled() {
return filled;
}
@Override
public int getCompare() {
return compare;