Fluid Storage Block
This commit is contained in:
@@ -60,6 +60,7 @@ public final class RefinedStorage {
|
||||
public int relayUsage;
|
||||
public int soldererUsage;
|
||||
public int storageUsage;
|
||||
public int fluidStorageUsage;
|
||||
public int wirelessTransmitterUsage;
|
||||
public int gridUsage;
|
||||
public int craftingGridUsage;
|
||||
@@ -106,6 +107,7 @@ public final class RefinedStorage {
|
||||
relayUsage = config.getInt("relay", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Relays");
|
||||
soldererUsage = config.getInt("solderer", "energy", 3, 0, Integer.MAX_VALUE, "The energy used by Solderers");
|
||||
storageUsage = config.getInt("storage", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Storage Blocks");
|
||||
fluidStorageUsage = config.getInt("fluidStorage", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Fluid Storage Blocks");
|
||||
wirelessTransmitterUsage = config.getInt("wirelessTransmitter", "energy", 8, 0, Integer.MAX_VALUE, "The energy used by Wireless Transmitters");
|
||||
gridUsage = config.getInt("grid", "energy", 2, 0, Integer.MAX_VALUE, "The energy used by Grids");
|
||||
craftingGridUsage = config.getInt("craftingGrid", "energy", 4, 0, Integer.MAX_VALUE, "The energy used by Crafting Grids");
|
||||
|
||||
@@ -25,4 +25,5 @@ public final class RefinedStorageBlocks {
|
||||
public static final BlockNetworkTransmitter NETWORK_TRANSMITTER = new BlockNetworkTransmitter();
|
||||
public static final BlockNetworkReceiver NETWORK_RECEIVER = new BlockNetworkReceiver();
|
||||
public static final BlockFluidInterface FLUID_INTERFACE = new BlockFluidInterface();
|
||||
public static final BlockFluidStorage FLUID_STORAGE = new BlockFluidStorage();
|
||||
}
|
||||
@@ -22,4 +22,5 @@ public final class RefinedStorageGui {
|
||||
public static final int NETWORK_TRANSMITTER = 18;
|
||||
public static final int FLUID_INTERFACE = 19;
|
||||
public static final int EXTERNAL_STORAGE = 20;
|
||||
public static final int FLUID_STORAGE = 21;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package refinedstorage.apiimpl.solderer;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.solderer.ISoldererRecipe;
|
||||
import refinedstorage.block.EnumFluidStorageType;
|
||||
import refinedstorage.item.ItemBlockFluidStorage;
|
||||
import refinedstorage.item.ItemProcessor;
|
||||
|
||||
public class SoldererRecipeFluidStorage implements ISoldererRecipe {
|
||||
private EnumFluidStorageType type;
|
||||
private ItemStack[] rows;
|
||||
|
||||
public SoldererRecipeFluidStorage(EnumFluidStorageType type, int storagePart) {
|
||||
this.type = type;
|
||||
this.rows = new ItemStack[]{
|
||||
new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC),
|
||||
new ItemStack(RefinedStorageBlocks.MACHINE_CASING),
|
||||
new ItemStack(RefinedStorageItems.FLUID_STORAGE_PART, 1, storagePart)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRow(int row) {
|
||||
return rows[row];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult() {
|
||||
return ItemBlockFluidStorage.initNBT(new ItemStack(RefinedStorageBlocks.FLUID_STORAGE, 1, type.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDuration() {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
114
src/main/java/refinedstorage/block/BlockFluidStorage.java
Executable file
114
src/main/java/refinedstorage/block/BlockFluidStorage.java
Executable file
@@ -0,0 +1,114 @@
|
||||
package refinedstorage.block;
|
||||
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.item.ItemBlockFluidStorage;
|
||||
import refinedstorage.tile.TileFluidStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockFluidStorage extends BlockNode {
|
||||
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumFluidStorageType.class);
|
||||
|
||||
public BlockFluidStorage() {
|
||||
super("fluid_storage");
|
||||
|
||||
setHardness(5.8F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subItems) {
|
||||
for (int i = 0; i <= 4; ++i) {
|
||||
subItems.add(ItemBlockFluidStorage.initNBT(new ItemStack(item, 1, i)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return createBlockStateBuilder()
|
||||
.add(TYPE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(TYPE, EnumFluidStorageType.getById(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return ((EnumFluidStorageType) state.getValue(TYPE)).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
return new TileFluidStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
if (!world.isRemote) {
|
||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.FLUID_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
|
||||
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(TileFluidStorage.NBT_STORAGE)) {
|
||||
((TileFluidStorage) world.getTileEntity(pos)).setStorageTag(stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||
((TileFluidStorage) world.getTileEntity(pos)).onBreak();
|
||||
|
||||
super.breakBlock(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
TileFluidStorage storage = (TileFluidStorage) world.getTileEntity(pos);
|
||||
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
|
||||
ItemStack stack = new ItemStack(RefinedStorageBlocks.FLUID_STORAGE, 1, getMetaFromState(state));
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
stack.getTagCompound().setTag(TileFluidStorage.NBT_STORAGE, storage.getStorageTag());
|
||||
|
||||
drops.add(stack);
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item createItem() {
|
||||
return new ItemBlockFluidStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPlacementType getPlacementType() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class BlockStorage extends BlockNode {
|
||||
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
|
||||
ItemStack stack = new ItemStack(RefinedStorageBlocks.STORAGE, 1, RefinedStorageBlocks.STORAGE.getMetaFromState(state));
|
||||
ItemStack stack = new ItemStack(RefinedStorageBlocks.STORAGE, 1, getMetaFromState(state));
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
stack.getTagCompound().setTag(TileStorage.NBT_STORAGE, storage.getStorageTag());
|
||||
|
||||
|
||||
30
src/main/java/refinedstorage/container/ContainerFluidStorage.java
Executable file
30
src/main/java/refinedstorage/container/ContainerFluidStorage.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package refinedstorage.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.container.slot.SlotSpecimenFluid;
|
||||
import refinedstorage.tile.TileFluidStorage;
|
||||
|
||||
public class ContainerFluidStorage extends ContainerBase {
|
||||
public ContainerFluidStorage(TileFluidStorage tile, EntityPlayer player) {
|
||||
super(tile, player);
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new SlotSpecimenFluid(!tile.getWorld().isRemote, tile.getFilters(), i, 8 + (18 * i), 20));
|
||||
}
|
||||
|
||||
addPlayerInventory(8, 129);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
|
||||
Slot slot = getSlot(index);
|
||||
|
||||
if (slot != null && slot.getHasStack() && index >= 8) {
|
||||
return mergeItemStackToSpecimen(slot.getStack(), 0, 9);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new ContainerNetworkTransmitter((TileNetworkTransmitter) tile, player);
|
||||
case RefinedStorageGui.FLUID_INTERFACE:
|
||||
return new ContainerFluidInterface((TileFluidInterface) tile, player);
|
||||
case RefinedStorageGui.FLUID_STORAGE:
|
||||
return new ContainerFluidStorage((TileFluidStorage) tile, player);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -131,6 +133,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new GuiNetworkTransmitter((ContainerNetworkTransmitter) getContainer(ID, player, tile), (TileNetworkTransmitter) tile);
|
||||
case RefinedStorageGui.FLUID_INTERFACE:
|
||||
return new GuiFluidInterface((ContainerFluidInterface) getContainer(ID, player, tile));
|
||||
case RefinedStorageGui.FLUID_STORAGE:
|
||||
return new GuiStorage((ContainerFluidStorage) getContainer(ID, player, tile), (TileFluidStorage) tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
90
src/main/java/refinedstorage/item/ItemBlockFluidStorage.java
Executable file
90
src/main/java/refinedstorage/item/ItemBlockFluidStorage.java
Executable file
@@ -0,0 +1,90 @@
|
||||
package refinedstorage.item;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
import refinedstorage.block.EnumFluidStorageType;
|
||||
import refinedstorage.tile.TileFluidStorage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
public ItemBlockFluidStorage() {
|
||||
super(RefinedStorageBlocks.FLUID_STORAGE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
EnumFluidStorageType type = EnumFluidStorageType.getById(stack.getMetadata());
|
||||
|
||||
if (type != null && isValid(stack)) {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE);
|
||||
|
||||
if (type == EnumFluidStorageType.TYPE_CREATIVE) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", FluidStorageNBT.getStoredFromNBT(tag)));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", FluidStorageNBT.getStoredFromNBT(tag), type.getCapacity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
EnumFluidStorageType type = EnumFluidStorageType.getById(stack.getMetadata());
|
||||
|
||||
if (type != null && isValid(stack) && FluidStorageNBT.getStoredFromNBT(stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE)) == 0 && stack.getMetadata() != ItemFluidStorageDisk.TYPE_CREATIVE && !world.isRemote && player.isSneaking()) {
|
||||
ItemStack storagePart = new ItemStack(RefinedStorageItems.FLUID_STORAGE_PART, 1, stack.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
||||
}
|
||||
|
||||
ItemStack processor = new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC);
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(processor.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), processor);
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageBlocks.MACHINE_CASING));
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.PASS, stack);
|
||||
}
|
||||
|
||||
private static boolean isValid(ItemStack stack) {
|
||||
return stack.getTagCompound() != null && stack.getTagCompound().hasKey(TileFluidStorage.NBT_STORAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
super.onUpdate(stack, world, entity, slot, selected);
|
||||
|
||||
if (!stack.hasTagCompound()) {
|
||||
initNBT(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||
super.onCreated(stack, world, player);
|
||||
|
||||
initNBT(stack);
|
||||
}
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag(TileFluidStorage.NBT_STORAGE, FluidStorageNBT.createNBT());
|
||||
stack.setTagCompound(tag);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,14 @@ import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
import refinedstorage.block.EnumFluidStorageType;
|
||||
|
||||
@@ -43,6 +48,21 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack disk, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote && player.isSneaking() && FluidStorageNBT.isValid(disk) && FluidStorageNBT.getStoredFromNBT(disk.getTagCompound()) == 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
ItemStack storagePart = new ItemStack(RefinedStorageItems.FLUID_STORAGE_PART, 1, disk.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageItems.STORAGE_HOUSING));
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.PASS, disk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack disk, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
if (FluidStorageNBT.isValid(disk)) {
|
||||
|
||||
@@ -86,6 +86,7 @@ public class CommonProxy {
|
||||
registerTile(TileNetworkReceiver.class, "network_receiver");
|
||||
registerTile(TileNetworkTransmitter.class, "network_transmitter");
|
||||
registerTile(TileFluidInterface.class, "fluid_interface");
|
||||
registerTile(TileFluidStorage.class, "fluid_storage");
|
||||
|
||||
registerBlock(RefinedStorageBlocks.CONTROLLER);
|
||||
registerBlock(RefinedStorageBlocks.GRID);
|
||||
@@ -109,6 +110,7 @@ public class CommonProxy {
|
||||
registerBlock(RefinedStorageBlocks.NETWORK_TRANSMITTER);
|
||||
registerBlock(RefinedStorageBlocks.NETWORK_RECEIVER);
|
||||
registerBlock(RefinedStorageBlocks.FLUID_INTERFACE);
|
||||
registerBlock(RefinedStorageBlocks.FLUID_STORAGE);
|
||||
|
||||
registerItem(RefinedStorageItems.QUARTZ_ENRICHED_IRON);
|
||||
registerItem(RefinedStorageItems.STORAGE_DISK);
|
||||
@@ -532,6 +534,12 @@ public class CommonProxy {
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeStorage(EnumItemStorageType.TYPE_16K, ItemStoragePart.TYPE_16K));
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeStorage(EnumItemStorageType.TYPE_64K, ItemStoragePart.TYPE_64K));
|
||||
|
||||
// Fluid Storage Blocks
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeFluidStorage(EnumFluidStorageType.TYPE_64K, ItemFluidStoragePart.TYPE_64K));
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeFluidStorage(EnumFluidStorageType.TYPE_128K, ItemFluidStoragePart.TYPE_128K));
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeFluidStorage(EnumFluidStorageType.TYPE_256K, ItemFluidStoragePart.TYPE_256K));
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY.addRecipe(new SoldererRecipeFluidStorage(EnumFluidStorageType.TYPE_512K, ItemFluidStoragePart.TYPE_512K));
|
||||
|
||||
// Crafting Monitor
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(RefinedStorageBlocks.CRAFTING_MONITOR),
|
||||
"EGE",
|
||||
|
||||
264
src/main/java/refinedstorage/tile/TileFluidStorage.java
Executable file
264
src/main/java/refinedstorage/tile/TileFluidStorage.java
Executable file
@@ -0,0 +1,264 @@
|
||||
package refinedstorage.tile;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.storage.fluid.IFluidStorage;
|
||||
import refinedstorage.api.storage.fluid.IFluidStorageProvider;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
||||
import refinedstorage.block.BlockFluidStorage;
|
||||
import refinedstorage.block.EnumFluidStorageType;
|
||||
import refinedstorage.inventory.ItemHandlerFluid;
|
||||
import refinedstorage.tile.config.IComparable;
|
||||
import refinedstorage.tile.config.IFilterable;
|
||||
import refinedstorage.tile.config.IPrioritizable;
|
||||
import refinedstorage.tile.data.ITileDataProducer;
|
||||
import refinedstorage.tile.data.TileDataParameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileFluidStorage extends TileNode implements IFluidStorageProvider, IStorageGui, IComparable, IFilterable, IPrioritizable {
|
||||
public static final TileDataParameter<Integer> PRIORITY = IPrioritizable.createParameter();
|
||||
public static final TileDataParameter<Integer> COMPARE = IComparable.createParameter();
|
||||
public static final TileDataParameter<Integer> MODE = IFilterable.createParameter();
|
||||
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileFluidStorage>() {
|
||||
@Override
|
||||
public Integer getValue(TileFluidStorage tile) {
|
||||
return FluidStorageNBT.getStoredFromNBT(tile.storageTag);
|
||||
}
|
||||
});
|
||||
|
||||
class FluidStorage extends FluidStorageNBT {
|
||||
public FluidStorage() {
|
||||
super(TileFluidStorage.this.getStorageTag(), TileFluidStorage.this.getCapacity(), TileFluidStorage.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack insertFluid(FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(filters, mode, compare, stack)) {
|
||||
return FluidUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return super.insertFluid(stack, size, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
|
||||
private static final String NBT_PRIORITY = "Priority";
|
||||
private static final String NBT_COMPARE = "Compare";
|
||||
private static final String NBT_MODE = "Mode";
|
||||
|
||||
private ItemHandlerFluid filters = new ItemHandlerFluid(9, this);
|
||||
|
||||
private NBTTagCompound storageTag = FluidStorageNBT.createNBT();
|
||||
|
||||
private FluidStorage storage;
|
||||
|
||||
private EnumFluidStorageType type;
|
||||
|
||||
private int priority = 0;
|
||||
private int compare = 0;
|
||||
private int mode = IFilterable.WHITELIST;
|
||||
|
||||
public TileFluidStorage() {
|
||||
dataManager.addWatchedParameter(PRIORITY);
|
||||
dataManager.addWatchedParameter(COMPARE);
|
||||
dataManager.addWatchedParameter(MODE);
|
||||
dataManager.addWatchedParameter(STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
return RefinedStorage.INSTANCE.fluidStorageUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNode() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
if (storage == null && storageTag != null) {
|
||||
storage = new FluidStorage();
|
||||
|
||||
if (network != null) {
|
||||
network.getFluidStorage().rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onBreak() {
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionChange(INetworkMaster network, boolean state) {
|
||||
super.onConnectionChange(network, state);
|
||||
|
||||
network.getFluidStorage().rebuild();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFluidStorages(List<IFluidStorage> storages) {
|
||||
if (storage != null) {
|
||||
storages.add(storage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound tag) {
|
||||
super.read(tag);
|
||||
|
||||
readItems(filters, 0, tag);
|
||||
|
||||
if (tag.hasKey(NBT_PRIORITY)) {
|
||||
priority = tag.getInteger(NBT_PRIORITY);
|
||||
}
|
||||
|
||||
if (tag.hasKey(NBT_STORAGE)) {
|
||||
storageTag = tag.getCompoundTag(NBT_STORAGE);
|
||||
}
|
||||
|
||||
if (tag.hasKey(NBT_COMPARE)) {
|
||||
compare = tag.getInteger(NBT_COMPARE);
|
||||
}
|
||||
|
||||
if (tag.hasKey(NBT_MODE)) {
|
||||
mode = tag.getInteger(NBT_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound write(NBTTagCompound tag) {
|
||||
super.write(tag);
|
||||
|
||||
writeItems(filters, 0, tag);
|
||||
|
||||
tag.setInteger(NBT_PRIORITY, priority);
|
||||
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
|
||||
tag.setTag(NBT_STORAGE, storageTag);
|
||||
tag.setInteger(NBT_COMPARE, compare);
|
||||
tag.setInteger(NBT_MODE, mode);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public EnumFluidStorageType getType() {
|
||||
if (type == null && worldObj.getBlockState(pos).getBlock() == RefinedStorageBlocks.FLUID_STORAGE) {
|
||||
this.type = ((EnumFluidStorageType) worldObj.getBlockState(pos).getValue(BlockFluidStorage.TYPE));
|
||||
}
|
||||
|
||||
return type == null ? EnumFluidStorageType.TYPE_64K : type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
return compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompare(int compare) {
|
||||
this.compare = compare;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(int mode) {
|
||||
this.mode = mode;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
return "block.refinedstorage:fluid_storage." + getType().getId() + ".name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDataParameter<Integer> getTypeParameter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDataParameter<Integer> getRedstoneModeParameter() {
|
||||
return REDSTONE_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDataParameter<Integer> getCompareParameter() {
|
||||
return COMPARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDataParameter<Integer> getFilterParameter() {
|
||||
return MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileDataParameter<Integer> getPriorityParameter() {
|
||||
return PRIORITY;
|
||||
}
|
||||
|
||||
public NBTTagCompound getStorageTag() {
|
||||
return storageTag;
|
||||
}
|
||||
|
||||
public void setStorageTag(NBTTagCompound storageTag) {
|
||||
this.storageTag = storageTag;
|
||||
}
|
||||
|
||||
public FluidStorageNBT getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public ItemHandlerFluid getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return STORED.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return getType().getCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,11 @@ block.refinedstorage:processing_pattern_encoder.name=Processing Pattern Encoder
|
||||
block.refinedstorage:network_receiver.name=Network Receiver
|
||||
block.refinedstorage:network_transmitter.name=Network Transmitter
|
||||
block.refinedstorage:fluid_interface.name=Fluid Interface
|
||||
block.refinedstorage:fluid_storage.0.name=64k Fluid Storage Block
|
||||
block.refinedstorage:fluid_storage.1.name=128k Fluid Storage Block
|
||||
block.refinedstorage:fluid_storage.2.name=256k Fluid Storage Block
|
||||
block.refinedstorage:fluid_storage.3.name=512k Fluid Storage Block
|
||||
block.refinedstorage:fluid_storage.4.name=Creative Fluid Storage Block
|
||||
|
||||
item.refinedstorage:storage_disk.0.name=1k Storage Disk
|
||||
item.refinedstorage:storage_disk.1.name=4k Storage Disk
|
||||
|
||||
Reference in New Issue
Block a user