Disk state
This commit is contained in:
@@ -34,6 +34,26 @@ import java.util.List;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class DiskDriveNetworkNode extends NetworkNode implements IStorageScreen, IStorageProvider, IComparable, IWhitelistBlacklist, IPrioritizable, IType, IAccessType, IStorageDiskContainerContext {
|
public class DiskDriveNetworkNode extends NetworkNode implements IStorageScreen, IStorageProvider, IComparable, IWhitelistBlacklist, IPrioritizable, IType, IAccessType, IStorageDiskContainerContext {
|
||||||
|
public enum DiskState {
|
||||||
|
NONE,
|
||||||
|
NORMAL,
|
||||||
|
DISCONNECTED,
|
||||||
|
NEAR_CAPACITY,
|
||||||
|
FULL;
|
||||||
|
|
||||||
|
public static final int DISK_NEAR_CAPACITY_THRESHOLD = 75;
|
||||||
|
|
||||||
|
public static DiskState get(int stored, int capacity) {
|
||||||
|
if (stored == capacity) {
|
||||||
|
return FULL;
|
||||||
|
} else if ((int) ((float) stored / (float) capacity * 100F) >= DISK_NEAR_CAPACITY_THRESHOLD) {
|
||||||
|
return NEAR_CAPACITY;
|
||||||
|
} else {
|
||||||
|
return NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final Predicate<ItemStack> VALIDATOR_STORAGE_DISK = s -> s.getItem() instanceof IStorageDiskProvider && ((IStorageDiskProvider) s.getItem()).isValid(s);
|
public static final Predicate<ItemStack> VALIDATOR_STORAGE_DISK = s -> s.getItem() instanceof IStorageDiskProvider && ((IStorageDiskProvider) s.getItem()).isValid(s);
|
||||||
|
|
||||||
public static final String ID = "disk_drive";
|
public static final String ID = "disk_drive";
|
||||||
@@ -339,6 +359,29 @@ public class DiskDriveNetworkNode extends NetworkNode implements IStorageScreen,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DiskState[] getDiskState() {
|
||||||
|
DiskState[] diskStates = new DiskState[8];
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
DiskState state = DiskState.NONE;
|
||||||
|
|
||||||
|
if (itemDisks[i] != null || fluidDisks[i] != null) {
|
||||||
|
if (network == null) {
|
||||||
|
state = DiskState.DISCONNECTED;
|
||||||
|
} else {
|
||||||
|
state = DiskState.get(
|
||||||
|
itemDisks[i] != null ? itemDisks[i].getStored() : fluidDisks[i].getStored(),
|
||||||
|
itemDisks[i] != null ? itemDisks[i].getCapacity() : fluidDisks[i].getCapacity()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diskStates[i] = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return diskStates;
|
||||||
|
}
|
||||||
|
|
||||||
public IItemHandler getDisks() {
|
public IItemHandler getDisks() {
|
||||||
return disks;
|
return disks;
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
@@ -19,14 +18,14 @@ import java.util.Collection;
|
|||||||
public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
|
public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
|
||||||
private DiskDriveNetworkNode diskDrive;
|
private DiskDriveNetworkNode diskDrive;
|
||||||
private IStorageDisk<FluidStack> parent;
|
private IStorageDisk<FluidStack> parent;
|
||||||
private int lastState;
|
private DiskDriveNetworkNode.DiskState lastState;
|
||||||
|
|
||||||
public StorageDiskFluidDriveWrapper(DiskDriveNetworkNode diskDrive, IStorageDisk<FluidStack> parent) {
|
public StorageDiskFluidDriveWrapper(DiskDriveNetworkNode diskDrive, IStorageDisk<FluidStack> parent) {
|
||||||
this.diskDrive = diskDrive;
|
this.diskDrive = diskDrive;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.setSettings(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
int currentState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
DiskDriveNetworkNode.DiskState currentState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
|
|
||||||
if (this.lastState != currentState) {
|
if (this.lastState != currentState) {
|
||||||
this.lastState = currentState;
|
this.lastState = currentState;
|
||||||
@@ -36,7 +35,7 @@ public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
|
|||||||
},
|
},
|
||||||
diskDrive
|
diskDrive
|
||||||
);
|
);
|
||||||
this.lastState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
this.lastState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,7 +5,6 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
@@ -19,14 +18,14 @@ import java.util.Collection;
|
|||||||
public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
|
public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
|
||||||
private DiskDriveNetworkNode diskDrive;
|
private DiskDriveNetworkNode diskDrive;
|
||||||
private IStorageDisk<ItemStack> parent;
|
private IStorageDisk<ItemStack> parent;
|
||||||
private int lastState;
|
private DiskDriveNetworkNode.DiskState lastState;
|
||||||
|
|
||||||
public StorageDiskItemDriveWrapper(DiskDriveNetworkNode diskDrive, IStorageDisk<ItemStack> parent) {
|
public StorageDiskItemDriveWrapper(DiskDriveNetworkNode diskDrive, IStorageDisk<ItemStack> parent) {
|
||||||
this.diskDrive = diskDrive;
|
this.diskDrive = diskDrive;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.setSettings(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
int currentState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
DiskDriveNetworkNode.DiskState currentState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
|
|
||||||
if (this.lastState != currentState) {
|
if (this.lastState != currentState) {
|
||||||
this.lastState = currentState;
|
this.lastState = currentState;
|
||||||
@@ -36,7 +35,7 @@ public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
|
|||||||
},
|
},
|
||||||
diskDrive
|
diskDrive
|
||||||
);
|
);
|
||||||
this.lastState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
this.lastState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
@@ -20,14 +20,14 @@ import java.util.Collection;
|
|||||||
public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidStack> {
|
public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidStack> {
|
||||||
private NetworkNodeDiskManipulator diskManipulator;
|
private NetworkNodeDiskManipulator diskManipulator;
|
||||||
private IStorageDisk<FluidStack> parent;
|
private IStorageDisk<FluidStack> parent;
|
||||||
private int lastState;
|
private DiskDriveNetworkNode.DiskState lastState;
|
||||||
|
|
||||||
public StorageDiskFluidManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
public StorageDiskFluidManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
||||||
this.diskManipulator = diskManipulator;
|
this.diskManipulator = diskManipulator;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.setSettings(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
int currentState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
DiskDriveNetworkNode.DiskState currentState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
lastState = currentState;
|
lastState = currentState;
|
||||||
@@ -37,7 +37,7 @@ public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidSta
|
|||||||
},
|
},
|
||||||
diskManipulator
|
diskManipulator
|
||||||
);
|
);
|
||||||
this.lastState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
this.lastState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
import com.raoulvdberge.refinedstorage.tile.config.IWhitelistBlacklist;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -20,14 +20,14 @@ import java.util.Collection;
|
|||||||
public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack> {
|
public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack> {
|
||||||
private NetworkNodeDiskManipulator diskManipulator;
|
private NetworkNodeDiskManipulator diskManipulator;
|
||||||
private IStorageDisk<ItemStack> parent;
|
private IStorageDisk<ItemStack> parent;
|
||||||
private int lastState;
|
private DiskDriveNetworkNode.DiskState lastState;
|
||||||
|
|
||||||
public StorageDiskItemManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
public StorageDiskItemManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
||||||
this.diskManipulator = diskManipulator;
|
this.diskManipulator = diskManipulator;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.setSettings(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
int currentState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
DiskDriveNetworkNode.DiskState currentState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
lastState = currentState;
|
lastState = currentState;
|
||||||
@@ -37,7 +37,7 @@ public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack
|
|||||||
},
|
},
|
||||||
diskManipulator
|
diskManipulator
|
||||||
);
|
);
|
||||||
this.lastState = ConstantsDisk.getDiskState(getStored(), getCapacity());
|
this.lastState = DiskDriveNetworkNode.DiskState.get(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -64,20 +64,6 @@ public class DiskDriveBlock extends NodeBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
@Override
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public void registerModels(IModelRegistration modelRegistration) {
|
|
||||||
modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "inventory"));
|
|
||||||
|
|
||||||
modelRegistration.addModelLoader(() -> new CustomModelLoaderDefault(info.getId(), ModelDiskDrive::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public BlockDirection getDirection() {
|
|
||||||
return BlockDirection.HORIZONTAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
|
||||||
return openNetworkGui(RSGui.DISK_DRIVE, player, world, pos, side);
|
return openNetworkGui(RSGui.DISK_DRIVE, player, world, pos, side);
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.render.constants;
|
|
||||||
|
|
||||||
public final class ConstantsDisk {
|
|
||||||
public static final int DISK_STATE_NORMAL = 0;
|
|
||||||
public static final int DISK_STATE_NEAR_CAPACITY = 1;
|
|
||||||
public static final int DISK_STATE_FULL = 2;
|
|
||||||
public static final int DISK_STATE_DISCONNECTED = 3;
|
|
||||||
public static final int DISK_STATE_NONE = 4;
|
|
||||||
|
|
||||||
public static final int DISK_NEAR_CAPACITY_THRESHOLD = 75;
|
|
||||||
|
|
||||||
public static int getDiskState(int stored, int capacity) {
|
|
||||||
if (stored == capacity) {
|
|
||||||
return DISK_STATE_FULL;
|
|
||||||
} else if ((int) ((float) stored / (float) capacity * 100F) >= DISK_NEAR_CAPACITY_THRESHOLD) {
|
|
||||||
return DISK_STATE_NEAR_CAPACITY;
|
|
||||||
} else {
|
|
||||||
return DISK_STATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -4,7 +4,8 @@ import com.google.common.cache.CacheBuilder;
|
|||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.DiskDriveTile;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.model.IBakedModel;
|
||||||
@@ -20,10 +21,10 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
private class CacheKey {
|
private class CacheKey {
|
||||||
private BlockState state;
|
private BlockState state;
|
||||||
private Direction side;
|
private Direction side;
|
||||||
private Integer[] diskState;
|
private DiskDriveNetworkNode.DiskState[] diskState;
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
CacheKey(BlockState state, @Nullable Direction side, Integer[] diskState, Random random) {
|
CacheKey(BlockState state, @Nullable Direction side, DiskDriveNetworkNode.DiskState[] diskState, Random random) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.side = side;
|
this.side = side;
|
||||||
this.diskState = diskState;
|
this.diskState = diskState;
|
||||||
@@ -63,7 +64,7 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Direction, IBakedModel> baseByFacing = new HashMap<>();
|
private Map<Direction, IBakedModel> baseByFacing = new HashMap<>();
|
||||||
private Map<Direction, Map<Integer, List<IBakedModel>>> disksByFacing = new HashMap<>();
|
private Map<Direction, Map<DiskDriveNetworkNode.DiskState, List<IBakedModel>>> disksByFacing = new HashMap<>();
|
||||||
|
|
||||||
private LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
|
private LoadingCache<CacheKey, List<BakedQuad>> cache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -73,7 +74,7 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
List<BakedQuad> quads = new ArrayList<>(baseByFacing.get(facing).getQuads(key.state, key.side, key.random));
|
List<BakedQuad> quads = new ArrayList<>(baseByFacing.get(facing).getQuads(key.state, key.side, key.random));
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
if (key.diskState[i] != ConstantsDisk.DISK_STATE_NONE) {
|
if (key.diskState[i] != DiskDriveNetworkNode.DiskState.NONE) {
|
||||||
quads.addAll(disksByFacing.get(facing).get(key.diskState[i]).get(i).getQuads(key.state, key.side, key.random));
|
quads.addAll(disksByFacing.get(facing).get(key.diskState[i]).get(i).getQuads(key.state, key.side, key.random));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,14 +99,14 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
|
|
||||||
disksByFacing.put(facing, new HashMap<>());
|
disksByFacing.put(facing, new HashMap<>());
|
||||||
|
|
||||||
addDiskModels(disk, ConstantsDisk.DISK_STATE_NORMAL, facing);
|
addDiskModels(disk, DiskDriveNetworkNode.DiskState.NORMAL, facing);
|
||||||
addDiskModels(diskNearCapacity, ConstantsDisk.DISK_STATE_NEAR_CAPACITY, facing);
|
addDiskModels(diskNearCapacity, DiskDriveNetworkNode.DiskState.NEAR_CAPACITY, facing);
|
||||||
addDiskModels(diskFull, ConstantsDisk.DISK_STATE_FULL, facing);
|
addDiskModels(diskFull, DiskDriveNetworkNode.DiskState.FULL, facing);
|
||||||
addDiskModels(diskDisconnected, ConstantsDisk.DISK_STATE_DISCONNECTED, facing);
|
addDiskModels(diskDisconnected, DiskDriveNetworkNode.DiskState.DISCONNECTED, facing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDiskModels(IBakedModel disk, int type, Direction facing) {
|
private void addDiskModels(IBakedModel disk, DiskDriveNetworkNode.DiskState type, Direction facing) {
|
||||||
disksByFacing.get(facing).put(type, new ArrayList<>());
|
disksByFacing.get(facing).put(type, new ArrayList<>());
|
||||||
|
|
||||||
for (int y = 0; y < 4; ++y) {
|
for (int y = 0; y < 4; ++y) {
|
||||||
@@ -129,20 +130,9 @@ public class DiskDriveBakedModel extends DelegateBakedModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Integer[] TEST_STATE = {
|
|
||||||
ConstantsDisk.DISK_STATE_FULL,
|
|
||||||
ConstantsDisk.DISK_STATE_NEAR_CAPACITY,
|
|
||||||
ConstantsDisk.DISK_STATE_NONE,
|
|
||||||
ConstantsDisk.DISK_STATE_NORMAL,
|
|
||||||
ConstantsDisk.DISK_STATE_NORMAL,
|
|
||||||
ConstantsDisk.DISK_STATE_NONE,
|
|
||||||
ConstantsDisk.DISK_STATE_NONE,
|
|
||||||
ConstantsDisk.DISK_STATE_NONE,
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data) {
|
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data) {
|
||||||
Integer[] diskState = TEST_STATE;
|
DiskDriveNetworkNode.DiskState[] diskState = data.getData(DiskDriveTile.DISK_STATE_PROPERTY);
|
||||||
|
|
||||||
if (diskState == null) {
|
if (diskState == null) {
|
||||||
return base.getQuads(state, side, rand, data);
|
return base.getQuads(state, side, rand, data);
|
||||||
|
@@ -4,15 +4,22 @@ import com.raoulvdberge.refinedstorage.RSTiles;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.*;
|
import com.raoulvdberge.refinedstorage.tile.config.*;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
|
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.nbt.IntNBT;
|
||||||
|
import net.minecraft.nbt.ListNBT;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.client.model.data.IModelData;
|
||||||
|
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||||
|
import net.minecraftforge.client.model.data.ModelProperty;
|
||||||
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
||||||
public static final TileDataParameter<Integer, DiskDriveTile> PRIORITY = IPrioritizable.createParameter();
|
public static final TileDataParameter<Integer, DiskDriveTile> PRIORITY = IPrioritizable.createParameter();
|
||||||
@@ -63,9 +70,10 @@ public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
|||||||
return capacity;
|
return capacity;
|
||||||
});
|
});
|
||||||
|
|
||||||
private static final String NBT_DISK_STATE = "DiskState_%d";
|
private static final String NBT_DISK_STATE = "DiskStates";
|
||||||
|
public static final ModelProperty<DiskDriveNetworkNode.DiskState[]> DISK_STATE_PROPERTY = new ModelProperty<>();
|
||||||
|
|
||||||
private Integer[] diskState = new Integer[8];
|
private DiskDriveNetworkNode.DiskState[] diskState = new DiskDriveNetworkNode.DiskState[8];
|
||||||
|
|
||||||
public DiskDriveTile() {
|
public DiskDriveTile() {
|
||||||
super(RSTiles.DISK_DRIVE);
|
super(RSTiles.DISK_DRIVE);
|
||||||
@@ -78,14 +86,20 @@ public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
|||||||
dataManager.addWatchedParameter(STORED);
|
dataManager.addWatchedParameter(STORED);
|
||||||
dataManager.addWatchedParameter(CAPACITY);
|
dataManager.addWatchedParameter(CAPACITY);
|
||||||
|
|
||||||
initDiskState(diskState);
|
Arrays.fill(diskState, DiskDriveNetworkNode.DiskState.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundNBT writeUpdate(CompoundNBT tag) {
|
public CompoundNBT writeUpdate(CompoundNBT tag) {
|
||||||
super.writeUpdate(tag);
|
super.writeUpdate(tag);
|
||||||
|
|
||||||
writeDiskState(tag, 8, getNode().canUpdate(), getNode().getItemDisks(), getNode().getFluidDisks());
|
ListNBT list = new ListNBT();
|
||||||
|
|
||||||
|
for (DiskDriveNetworkNode.DiskState state : getNode().getDiskState()) {
|
||||||
|
list.add(new IntNBT(state.ordinal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.put(NBT_DISK_STATE, list);
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@@ -94,42 +108,21 @@ public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
|||||||
public void readUpdate(CompoundNBT tag) {
|
public void readUpdate(CompoundNBT tag) {
|
||||||
super.readUpdate(tag);
|
super.readUpdate(tag);
|
||||||
|
|
||||||
readDiskState(tag, diskState);
|
ListNBT list = tag.getList(NBT_DISK_STATE, Constants.NBT.TAG_INT);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
|
diskState[i] = DiskDriveNetworkNode.DiskState.values()[list.getInt(i)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer[] getDiskState() {
|
requestModelDataUpdate();
|
||||||
return diskState;
|
|
||||||
|
WorldUtils.updateBlock(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeDiskState(CompoundNBT tag, int disks, boolean connected, IStorageDisk[] itemStorages, IStorageDisk[] fluidStorages) {
|
@Nonnull
|
||||||
for (int i = 0; i < disks; ++i) {
|
@Override
|
||||||
int state = ConstantsDisk.DISK_STATE_NONE;
|
public IModelData getModelData() {
|
||||||
|
return new ModelDataMap.Builder().withInitial(DISK_STATE_PROPERTY, diskState).build();
|
||||||
if (itemStorages[i] != null || fluidStorages[i] != null) {
|
|
||||||
if (!connected) {
|
|
||||||
state = ConstantsDisk.DISK_STATE_DISCONNECTED;
|
|
||||||
} else {
|
|
||||||
state = ConstantsDisk.getDiskState(
|
|
||||||
itemStorages[i] != null ? itemStorages[i].getStored() : fluidStorages[i].getStored(),
|
|
||||||
itemStorages[i] != null ? itemStorages[i].getCapacity() : fluidStorages[i].getCapacity()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.putInt(String.format(NBT_DISK_STATE, i), state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void readDiskState(CompoundNBT tag, Integer[] diskState) {
|
|
||||||
for (int i = 0; i < diskState.length; ++i) {
|
|
||||||
diskState[i] = tag.getInt(String.format(NBT_DISK_STATE, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initDiskState(Integer[] diskState) {
|
|
||||||
for (int i = 0; i < diskState.length; ++i) {
|
|
||||||
diskState[i] = ConstantsDisk.DISK_STATE_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
|
@@ -32,14 +32,14 @@ public class TileDiskManipulator extends NetworkNodeTile<NetworkNodeDiskManipula
|
|||||||
dataManager.addWatchedParameter(TYPE);
|
dataManager.addWatchedParameter(TYPE);
|
||||||
dataManager.addWatchedParameter(IO_MODE);
|
dataManager.addWatchedParameter(IO_MODE);
|
||||||
|
|
||||||
DiskDriveTile.initDiskState(diskState);
|
// DiskDriveTile.initDiskState(diskState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundNBT writeUpdate(CompoundNBT tag) {
|
public CompoundNBT writeUpdate(CompoundNBT tag) {
|
||||||
super.writeUpdate(tag);
|
super.writeUpdate(tag);
|
||||||
|
|
||||||
DiskDriveTile.writeDiskState(tag, 6, getNode().canUpdate(), getNode().getItemDisks(), getNode().getFluidDisks());
|
// DiskDriveTile.writeDiskState(tag, 6, getNode().canUpdate(), getNode().getItemDisks(), getNode().getFluidDisks());
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ public class TileDiskManipulator extends NetworkNodeTile<NetworkNodeDiskManipula
|
|||||||
public void readUpdate(CompoundNBT tag) {
|
public void readUpdate(CompoundNBT tag) {
|
||||||
super.readUpdate(tag);
|
super.readUpdate(tag);
|
||||||
|
|
||||||
DiskDriveTile.readDiskState(tag, diskState);
|
// DiskDriveTile.readDiskState(tag, diskState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer[] getDiskState() {
|
public Integer[] getDiskState() {
|
||||||
|
@@ -28,7 +28,6 @@ import com.raoulvdberge.refinedstorage.block.enums.PortableGridType;
|
|||||||
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerBase;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerFilter;
|
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerFilter;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.listener.ListenerTile;
|
import com.raoulvdberge.refinedstorage.inventory.listener.ListenerTile;
|
||||||
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
|
|
||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.GuiGrid;
|
import com.raoulvdberge.refinedstorage.screen.grid.GuiGrid;
|
||||||
import com.raoulvdberge.refinedstorage.tile.BaseTile;
|
import com.raoulvdberge.refinedstorage.tile.BaseTile;
|
||||||
@@ -741,7 +740,7 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
|||||||
|
|
||||||
if (renderInfo.getStored() == renderInfo.getCapacity()) {
|
if (renderInfo.getStored() == renderInfo.getCapacity()) {
|
||||||
return PortableGridDiskState.FULL;
|
return PortableGridDiskState.FULL;
|
||||||
} else if ((int) ((float) renderInfo.getStored() / (float) renderInfo.getCapacity() * 100F) >= ConstantsDisk.DISK_NEAR_CAPACITY_THRESHOLD) {
|
} else if ((int) ((float) renderInfo.getStored() / (float) renderInfo.getCapacity() * 100F) >= DiskDriveNetworkNode.DiskState.DISK_NEAR_CAPACITY_THRESHOLD) {
|
||||||
return PortableGridDiskState.NEAR_CAPACITY;
|
return PortableGridDiskState.NEAR_CAPACITY;
|
||||||
} else {
|
} else {
|
||||||
return PortableGridDiskState.NORMAL;
|
return PortableGridDiskState.NORMAL;
|
||||||
|
@@ -4,7 +4,6 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -22,7 +21,6 @@ import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class WorldUtils {
|
public final class WorldUtils {
|
||||||
// TODO REMOVE. Can just use setBlockState now.
|
|
||||||
public static void updateBlock(@Nullable World world, BlockPos pos) {
|
public static void updateBlock(@Nullable World world, BlockPos pos) {
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
@@ -58,12 +56,4 @@ public final class WorldUtils {
|
|||||||
public static void sendNoPermissionMessage(PlayerEntity player) {
|
public static void sendNoPermissionMessage(PlayerEntity player) {
|
||||||
player.sendMessage(new TranslationTextComponent("misc.refinedstorage:security.no_permission").setStyle(new Style().setColor(TextFormatting.RED)));
|
player.sendMessage(new TranslationTextComponent("misc.refinedstorage:security.no_permission").setStyle(new Style().setColor(TextFormatting.RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dropInventory(World world, BlockPos pos, IItemHandler handler) {
|
|
||||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
|
||||||
if (!handler.getStackInSlot(i).isEmpty()) {
|
|
||||||
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user