use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class WorkableTieredMetaTileEntity method canInputFluid.
protected boolean canInputFluid(FluidStack inputFluid) {
RecipeMap<?> recipeMap = workable.getRecipeMap();
if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
// if recipe map forces input of given fluid, return true
return true;
Set<Recipe> matchingRecipes = null;
for (IFluidTank fluidTank : importFluids) {
FluidStack fluidInTank = fluidTank.getFluid();
if (fluidInTank != null) {
if (matchingRecipes == null) {
// if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
} else {
// retain recipes which use the fluid in this tank
matchingRecipes.retainAll(recipeMap.getRecipesForFluid(fluidInTank));
}
}
}
if (matchingRecipes == null) {
// if all tanks are empty, generally fluid can be inserted if there are recipes for it
return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
} else {
matchingRecipes.retainAll(recipeMap.getRecipesForFluid(inputFluid));
return !matchingRecipes.isEmpty();
}
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class TricorderBehavior method getScannerInfo.
public List<ITextComponent> getScannerInfo(EntityPlayer player, World world, BlockPos pos) {
int energyCost = 100;
List<ITextComponent> list = new ArrayList<>();
TileEntity tileEntity = world.getTileEntity(pos);
Block block = world.getBlockState(pos).getBlock();
// coordinates of the block
list.add(new TextComponentTranslation("behavior.tricorder.position", new TextComponentTranslation(GTUtility.formatNumbers(pos.getX())).setStyle(new Style().setColor(TextFormatting.AQUA)), new TextComponentTranslation(GTUtility.formatNumbers(pos.getY())).setStyle(new Style().setColor(TextFormatting.AQUA)), new TextComponentTranslation(GTUtility.formatNumbers(pos.getZ())).setStyle(new Style().setColor(TextFormatting.AQUA)), new TextComponentTranslation(GTUtility.formatNumbers(world.provider.getDimension())).setStyle(new Style().setColor(TextFormatting.AQUA))));
// hardness and blast resistance
list.add(new TextComponentTranslation("behavior.tricorder.block_hardness", new TextComponentTranslation(GTUtility.formatNumbers(block.blockHardness)).setStyle(new Style().setColor(TextFormatting.YELLOW)), new TextComponentTranslation(GTUtility.formatNumbers(block.getExplosionResistance(player))).setStyle(new Style().setColor(TextFormatting.YELLOW))));
MetaTileEntity metaTileEntity;
if (tileEntity instanceof MetaTileEntityHolder) {
metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
if (metaTileEntity == null)
return list;
// name of the machine
list.add(new TextComponentTranslation("behavior.tricorder.block_name", new TextComponentTranslation(LocalizationUtils.format(metaTileEntity.getMetaFullName())).setStyle(new Style().setColor(TextFormatting.BLUE)), new TextComponentTranslation(GTUtility.formatNumbers(GregTechAPI.MTE_REGISTRY.getIdByObjectName(metaTileEntity.metaTileEntityId))).setStyle(new Style().setColor(TextFormatting.BLUE))));
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
// fluid tanks
FluidTankList tanks = metaTileEntity.getImportFluids();
int tankIndex = 0;
boolean allTanksEmpty = true;
if (tanks != null && !tanks.getFluidTanks().isEmpty()) {
energyCost += 500;
for (int i = 0; i < tanks.getFluidTanks().size(); i++) {
IFluidTank tank = tanks.getTankAt(i);
if (tank.getFluid() == null)
continue;
allTanksEmpty = false;
list.add(new TextComponentTranslation("behavior.tricorder.tank", i, new TextComponentTranslation(GTUtility.formatNumbers(tank.getFluid().amount)).setStyle(new Style().setColor(TextFormatting.GREEN)), new TextComponentTranslation(GTUtility.formatNumbers(tank.getCapacity())).setStyle(new Style().setColor(TextFormatting.YELLOW)), new TextComponentTranslation(tank.getFluid().getLocalizedName()).setStyle(new Style().setColor(TextFormatting.GOLD))));
}
tankIndex += tanks.getFluidTanks().size();
}
tanks = metaTileEntity.getExportFluids();
if (tanks != null && !tanks.getFluidTanks().isEmpty()) {
energyCost += 500;
for (int i = 0; i < tanks.getFluidTanks().size(); i++) {
IFluidTank tank = tanks.getTankAt(i);
if (tank.getFluid() == null)
continue;
allTanksEmpty = false;
list.add(new TextComponentTranslation("behavior.tricorder.tank", tankIndex + i, new TextComponentTranslation(GTUtility.formatNumbers(tank.getFluid().amount)).setStyle(new Style().setColor(TextFormatting.GREEN)), new TextComponentTranslation(GTUtility.formatNumbers(tank.getCapacity())).setStyle(new Style().setColor(TextFormatting.YELLOW)), new TextComponentTranslation(tank.getFluid().getLocalizedName()).setStyle(new Style().setColor(TextFormatting.GOLD))));
}
}
if (allTanksEmpty && (metaTileEntity.getImportFluids() != null || metaTileEntity.getExportFluids() != null))
list.add(new TextComponentTranslation("behavior.tricorder.tanks_empty"));
// sound muffling
energyCost += 500;
if (metaTileEntity.isMuffled())
list.add(new TextComponentTranslation("behavior.tricorder.muffled").setStyle(new Style().setColor(TextFormatting.GREEN)));
// workable progress info
IWorkable workable = metaTileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null);
if (workable != null) {
if (!workable.isWorkingEnabled()) {
list.add(new TextComponentTranslation("behavior.tricorder.machine_disabled").setStyle(new Style().setColor(TextFormatting.RED)));
}
// if (workable.wasShutdown()) { //todo
// list.add(new TextComponentTranslation("behavior.tricorder.machine_power_loss").setStyle(new Style().setColor(TextFormatting.RED)));
// }
energyCost += 400;
if (workable.getMaxProgress() > 0) {
list.add(new TextComponentTranslation("behavior.tricorder.machine_progress", new TextComponentTranslation(GTUtility.formatNumbers(workable.getProgress())).setStyle(new Style().setColor(TextFormatting.GREEN)), new TextComponentTranslation(GTUtility.formatNumbers(workable.getMaxProgress())).setStyle(new Style().setColor(TextFormatting.YELLOW))));
}
}
// energy container
IEnergyContainer container = metaTileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, null);
if (container != null && container.getEnergyCapacity() > 0) {
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
if (container.getInputVoltage() > 0) {
list.add(new TextComponentTranslation("behavior.tricorder.energy_container_in", new TextComponentTranslation(GTUtility.formatNumbers(container.getInputVoltage())).setStyle(new Style().setColor(TextFormatting.RED)), new TextComponentTranslation(GTValues.VN[GTUtility.getTierByVoltage(container.getInputVoltage())]).setStyle(new Style().setColor(TextFormatting.RED)), new TextComponentTranslation(GTUtility.formatNumbers(container.getInputAmperage())).setStyle(new Style().setColor(TextFormatting.RED))));
}
if (container.getOutputVoltage() > 0) {
list.add(new TextComponentTranslation("behavior.tricorder.energy_container_out", new TextComponentTranslation(GTUtility.formatNumbers(container.getOutputVoltage())).setStyle(new Style().setColor(TextFormatting.RED)), new TextComponentTranslation(GTValues.VN[GTUtility.getTierByVoltage(container.getOutputVoltage())]).setStyle(new Style().setColor(TextFormatting.RED)), new TextComponentTranslation(GTUtility.formatNumbers(container.getOutputAmperage())).setStyle(new Style().setColor(TextFormatting.RED))));
}
list.add(new TextComponentTranslation("behavior.tricorder.energy_container_storage", new TextComponentTranslation(GTUtility.formatNumbers(container.getEnergyStored())).setStyle(new Style().setColor(TextFormatting.GREEN)), new TextComponentTranslation(GTUtility.formatNumbers(container.getEnergyCapacity())).setStyle(new Style().setColor(TextFormatting.YELLOW))));
}
// machine-specific info
IDataInfoProvider provider = null;
if (tileEntity instanceof IDataInfoProvider)
provider = (IDataInfoProvider) tileEntity;
else if (metaTileEntity instanceof IDataInfoProvider)
provider = (IDataInfoProvider) metaTileEntity;
if (provider != null) {
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
list.addAll(provider.getDataInfo());
}
} else if (tileEntity instanceof IPipeTile) {
// pipes need special name handling
IPipeTile<?, ?> pipeTile = (IPipeTile<?, ?>) tileEntity;
if (pipeTile.getPipeBlock().getRegistryName() != null) {
list.add(new TextComponentTranslation("behavior.tricorder.block_name", new TextComponentTranslation(LocalizationUtils.format(pipeTile.getPipeBlock().getTranslationKey())).setStyle(new Style().setColor(TextFormatting.BLUE)), new TextComponentTranslation(GTUtility.formatNumbers(block.getMetaFromState(world.getBlockState(pos)))).setStyle(new Style().setColor(TextFormatting.BLUE))));
}
// pipe-specific info
if (tileEntity instanceof IDataInfoProvider) {
IDataInfoProvider provider = (IDataInfoProvider) tileEntity;
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
list.addAll(provider.getDataInfo());
}
if (tileEntity instanceof TileEntityFluidPipe) {
// getting fluid info always costs 500
energyCost += 500;
}
} else if (tileEntity instanceof IDataInfoProvider) {
IDataInfoProvider provider = (IDataInfoProvider) tileEntity;
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
list.addAll(provider.getDataInfo());
} else {
list.add(new TextComponentTranslation("behavior.tricorder.block_name", new TextComponentTranslation(LocalizationUtils.format(block.getLocalizedName())).setStyle(new Style().setColor(TextFormatting.BLUE)), new TextComponentTranslation(GTUtility.formatNumbers(block.getMetaFromState(world.getBlockState(pos)))).setStyle(new Style().setColor(TextFormatting.BLUE))));
}
// crops (adds 1000EU)
// bedrock fluids
list.add(new TextComponentTranslation("behavior.tricorder.divider"));
// -# to only read
Fluid fluid = BedrockFluidVeinHandler.getFluidInChunk(world, pos.getX() / 16, pos.getZ() / 16);
if (fluid != null) {
FluidStack stack = new FluidStack(fluid, BedrockFluidVeinHandler.getOperationsRemaining(world, pos.getX() / 16, pos.getZ() / 16));
double fluidPercent = stack.amount * 100.0 / BedrockFluidVeinHandler.MAXIMUM_VEIN_OPERATIONS;
if (player.isCreative()) {
list.add(new TextComponentTranslation("behavior.tricorder.bedrock_fluid.amount", new TextComponentTranslation(fluid.getLocalizedName(stack)).setStyle(new Style().setColor(TextFormatting.GOLD)), new TextComponentTranslation("" + BedrockFluidVeinHandler.getFluidYield(world, pos.getX() / 16, pos.getZ() / 16)).setStyle(new Style().setColor(TextFormatting.GOLD)), new TextComponentTranslation("" + fluidPercent).setStyle(new Style().setColor(TextFormatting.YELLOW))));
} else {
list.add(new TextComponentTranslation("behavior.tricorder.bedrock_fluid.amount_unknown", new TextComponentTranslation("" + fluidPercent).setStyle(new Style().setColor(TextFormatting.YELLOW))));
}
} else {
list.add(new TextComponentTranslation("behavior.tricorder.bedrock_fluid.nothing"));
}
// debug
if (tileEntity instanceof MetaTileEntityHolder) {
list.addAll(((MetaTileEntityHolder) tileEntity).getDebugInfo(player, debugLevel));
}
this.energyCost = energyCost;
return list;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class VirtualTankApp method readUpdateInfo.
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
if (id == -1) {
// update all info
int size = buffer.readVarInt();
cacheClient.clear();
try {
for (int i = 0; i < size; i++) {
UUID uuid = null;
if (buffer.readBoolean()) {
uuid = UUID.fromString(buffer.readString(32767));
}
String key = buffer.readString(32767);
IFluidTank fluidTank = new FluidTank(64000);
if (buffer.readBoolean()) {
fluidTank.fill(FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag()), true);
}
cacheClient.put(new ImmutablePair<>(uuid, key), fluidTank);
}
} catch (Exception e) {
GTLog.logger.error("error sync fluid", e);
}
reloadWidgets(cacheClient);
} else if (id == -2) {
int size = buffer.readVarInt();
try {
for (int i = 0; i < size; i++) {
UUID uuid = null;
if (buffer.readBoolean()) {
uuid = UUID.fromString(buffer.readString(32767));
}
String key = buffer.readString(32767);
FluidStack fluidStack = null;
if (buffer.readBoolean()) {
fluidStack = FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag());
}
IFluidTank fluidTank = cacheClient.get(new ImmutablePair<>(uuid, key));
if (fluidTank != null) {
fluidTank.drain(64000, true);
if (fluidStack != null) {
fluidTank.fill(fluidStack, true);
}
}
}
} catch (Exception e) {
GTLog.logger.error("error sync fluid", e);
}
} else {
super.readUpdateInfo(id, buffer);
}
}
use of net.minecraftforge.fluids.IFluidTank in project Create by Creators-of-Create.
the class Contraption method readNBT.
public void readNBT(Level world, CompoundTag nbt, boolean spawnData) {
blocks.clear();
presentTileEntities.clear();
specialRenderedTileEntities.clear();
Tag blocks = nbt.get("Blocks");
// used to differentiate between the 'old' and the paletted serialization
boolean usePalettedDeserialization = blocks != null && blocks.getId() == 10 && ((CompoundTag) blocks).contains("Palette");
readBlocksCompound(blocks, world, usePalettedDeserialization);
actors.clear();
nbt.getList("Actors", 10).forEach(c -> {
CompoundTag comp = (CompoundTag) c;
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp.getCompound("Pos")));
MovementContext context = MovementContext.readNBT(world, info, comp, this);
getActors().add(MutablePair.of(info, context));
});
superglue.clear();
NBTHelper.iterateCompoundList(nbt.getList("Superglue", Tag.TAG_COMPOUND), c -> superglue.add(Pair.of(NbtUtils.readBlockPos(c.getCompound("Pos")), Direction.from3DDataValue(c.getByte("Direction")))));
seats.clear();
NBTHelper.iterateCompoundList(nbt.getList("Seats", Tag.TAG_COMPOUND), c -> seats.add(NbtUtils.readBlockPos(c)));
seatMapping.clear();
NBTHelper.iterateCompoundList(nbt.getList("Passengers", Tag.TAG_COMPOUND), c -> seatMapping.put(NbtUtils.loadUUID(NBTHelper.getINBT(c, "Id")), c.getInt("Seat")));
stabilizedSubContraptions.clear();
NBTHelper.iterateCompoundList(nbt.getList("SubContraptions", Tag.TAG_COMPOUND), c -> stabilizedSubContraptions.put(c.getUUID("Id"), BlockFace.fromNBT(c.getCompound("Location"))));
storage.clear();
NBTHelper.iterateCompoundList(nbt.getList("Storage", Tag.TAG_COMPOUND), c -> storage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedStorage.deserialize(c.getCompound("Data"))));
fluidStorage.clear();
NBTHelper.iterateCompoundList(nbt.getList("FluidStorage", Tag.TAG_COMPOUND), c -> fluidStorage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedFluidStorage.deserialize(c.getCompound("Data"))));
interactors.clear();
NBTHelper.iterateCompoundList(nbt.getList("Interactors", Tag.TAG_COMPOUND), c -> {
BlockPos pos = NbtUtils.readBlockPos(c.getCompound("Pos"));
MovingInteractionBehaviour behaviour = AllInteractionBehaviours.of(getBlocks().get(pos).state.getBlock());
if (behaviour != null)
interactors.put(pos, behaviour);
});
if (spawnData)
fluidStorage.forEach((pos, mfs) -> {
BlockEntity tileEntity = presentTileEntities.get(pos);
if (!(tileEntity instanceof FluidTankTileEntity))
return;
FluidTankTileEntity tank = (FluidTankTileEntity) tileEntity;
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof FluidTank)
((FluidTank) tankInventory).setFluid(mfs.tank.getFluid());
tank.getFluidLevel().start(tank.getFillState());
mfs.assignTileEntity(tank);
});
IItemHandlerModifiable[] handlers = new IItemHandlerModifiable[storage.size()];
int index = 0;
for (MountedStorage mountedStorage : storage.values()) handlers[index++] = mountedStorage.getItemHandler();
IFluidHandler[] fluidHandlers = new IFluidHandler[fluidStorage.size()];
index = 0;
for (MountedFluidStorage mountedStorage : fluidStorage.values()) fluidHandlers[index++] = mountedStorage.getFluidHandler();
inventory = new ContraptionInvWrapper(handlers);
fluidInventory = new CombinedTankWrapper(fluidHandlers);
if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));
stalled = nbt.getBoolean("Stalled");
hasUniversalCreativeCrate = nbt.getBoolean("BottomlessSupply");
anchor = NbtUtils.readBlockPos(nbt.getCompound("Anchor"));
}
use of net.minecraftforge.fluids.IFluidTank in project Create by Creators-of-Create.
the class MountedFluidStorage method updateFluid.
public void updateFluid(FluidStack fluid) {
tank.setFluid(fluid);
if (!(te instanceof FluidTankTileEntity))
return;
float fillState = tank.getFluidAmount() / (float) tank.getCapacity();
FluidTankTileEntity tank = (FluidTankTileEntity) te;
if (tank.getFluidLevel() == null)
tank.setFluidLevel(new InterpolatedChasingValue().start(fillState));
tank.getFluidLevel().target(fillState);
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof SmartFluidTank)
((SmartFluidTank) tankInventory).setFluid(fluid);
}
Aggregations