use of net.minecraftforge.fluids.capability.templates.FluidTank in project BluePower by Qmunity.
the class NetworkUtils method getSyncedFieldsForField.
private static List<SyncedField> getSyncedFieldsForField(Field field, Object te, Class searchedAnnotation) {
boolean isLazy = field.getAnnotation(LazySynced.class) != null;
List<SyncedField> syncedFields = new ArrayList<SyncedField>();
SyncedField syncedField = getSyncedFieldForField(field, te);
if (syncedField != null) {
syncedFields.add(syncedField.setLazy(isLazy));
return syncedFields;
} else {
Object o;
try {
int filteredIndex = field.getAnnotation(FilteredSynced.class) != null ? field.getAnnotation(FilteredSynced.class).index() : -1;
field.setAccessible(true);
o = field.get(te);
if (o instanceof int[]) {
int[] array = (int[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedInt(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedInt(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof float[]) {
float[] array = (float[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedFloat(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedFloat(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof double[]) {
double[] array = (double[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedDouble(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedDouble(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof boolean[]) {
boolean[] array = (boolean[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof String[]) {
String[] array = (String[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedString(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedString(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o.getClass().isArray() && o.getClass().getComponentType().isEnum()) {
Object[] enumArray = (Object[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedEnum(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < enumArray.length; i++) {
syncedFields.add(new SyncedEnum(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof ItemStack[]) {
ItemStack[] array = (ItemStack[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof FluidTank[]) {
FluidTank[] array = (FluidTank[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (field.getType().isArray()) {
Object[] array = (Object[]) o;
for (Object obj : array) {
syncedFields.addAll(getSyncedFields(obj, searchedAnnotation));
}
} else {
syncedFields.addAll(getSyncedFields(o, searchedAnnotation));
}
if (syncedFields.size() > 0)
return syncedFields;
} catch (Exception e) {
e.printStackTrace();
}
BPLog.warning("Field " + field + " didn't produce any syncable fields!");
return syncedFields;
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class RenderCoolantResavoir method render.
@Override
public void render(TileCoolantResavoir entity, float tick, PoseStack stack, MultiBufferSource source, int light, int overlay) {
FluidTank tank = ((ComponentFluidHandlerSimple) entity.getComponent(ComponentType.FluidHandler)).getOutputTanks()[0];
if (!tank.isEmpty() && tank.getFluidAmount() > 0) {
FluidStack fluid = tank.getFluid();
float yHeight = Math.max(Math.min((float) tank.getFluidAmount() / (float) tank.getCapacity(), MAX_Y), MIN_Y);
AABB aabb = new AABB(MIN_X, MIN_Y, MIN_Z, MAX_X, yHeight, MAX_Z);
VertexConsumer builder = source.getBuffer(Sheets.translucentCullBlockSheet());
RenderingUtils.renderFluidBox(stack, Minecraft.getInstance(), builder, aabb, fluid, light, overlay);
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class FluidUtilities method fillItem.
public static void fillItem(GenericTile tile) {
ComponentInventory inv = tile.getComponent(ComponentType.Inventory);
AbstractFluidHandler<?> handler = tile.getComponent(ComponentType.FluidHandler);
FluidTank[] tanks = handler.getOutputTanks();
List<ItemStack> buckets = inv.getOutputBucketContents();
for (int i = 0; i < buckets.size(); i++) {
ItemStack stack = buckets.get(i);
FluidTank tank = tanks[i];
if (!stack.isEmpty() && !(stack.getItem() instanceof BucketItem) && !CapabilityUtils.isFluidItemNull()) {
FluidStack fluid = tank.getFluid();
int amtFilled = CapabilityUtils.simFill(stack, fluid);
FluidStack taken = new FluidStack(fluid.getFluid(), amtFilled);
CapabilityUtils.fill(stack, taken);
tank.drain(taken, FluidAction.EXECUTE);
}
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class TileCombustionChamber method tickServer.
protected void tickServer(ComponentTickable tickable) {
ComponentDirection direction = getComponent(ComponentType.Direction);
Direction facing = direction.getDirection();
if (output == null) {
output = new CachedTileOutput(level, worldPosition.relative(facing.getClockWise()));
}
if (tickable.getTicks() % 40 == 0) {
output.update();
}
if (tickable.getTicks() % 5 == 0) {
this.<ComponentPacketHandler>getComponent(ComponentType.PacketHandler).sendGuiPacketToTracking();
}
ComponentFluidHandlerMulti handler = getComponent(ComponentType.FluidHandler);
FluidUtilities.drainItem(this);
FluidTank tank = handler.getInputTanks()[0];
if (burnTime <= 0) {
running = false;
if (tank.getFluidAmount() > 0) {
CombustionFuelSource source = CombustionFuelSource.getSourceFromFluid(tank.getFluid().getFluid());
tank.getFluid().shrink(source.getFluidUsage());
multiplier = source.getPowerMultiplier();
running = true;
burnTime = TICKS_PER_MILLIBUCKET;
}
} else {
running = true;
}
if (burnTime > 0) {
--burnTime;
}
if (running && burnTime > 0 && output.valid()) {
ElectricityUtils.receivePower(output.getSafe(), facing.getClockWise().getOpposite(), getProduced(), false);
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class TileCreativeFluidSource method tickServer.
private void tickServer(ComponentTickable tick) {
ComponentFluidHandlerSimple handler = (ComponentFluidHandlerSimple) getComponent(ComponentType.FluidHandler);
ComponentInventory inv = getComponent(ComponentType.Inventory);
ItemStack input = inv.getItem(0);
ItemStack output = inv.getItem(1);
FluidTank tank = handler.getInputTanks()[0];
tank.setFluid(new FluidStack(tank.getFluid(), tank.getCapacity()));
// set tank fluid from slot 1
if (!input.isEmpty() && CapabilityUtils.hasFluidItemCap(input)) {
tank.setFluid(new FluidStack(CapabilityUtils.simDrain(input, Integer.MAX_VALUE).getFluid(), tank.getCapacity()));
}
// fill item in slot 2
if (!output.isEmpty() && CapabilityUtils.hasFluidItemCap(output)) {
boolean isBucket = output.getItem() instanceof BucketItem;
FluidStack tankFluid = handler.getFluidInTank(0);
int amtTaken = CapabilityUtils.simFill(output, handler.getFluidInTank(0));
Fluid fluid = tankFluid.getFluid();
if (amtTaken > 0 && !isBucket) {
CapabilityUtils.fill(output, new FluidStack(fluid, amtTaken));
} else if (amtTaken >= 1000 && isBucket && (fluid.isSame(Fluids.WATER) || fluid.isSame(Fluids.LAVA))) {
if (fluid.isSame(Fluids.WATER)) {
inv.setItem(1, new ItemStack(Items.WATER_BUCKET, 1));
} else {
inv.setItem(1, new ItemStack(Items.LAVA_BUCKET, 1));
}
}
}
// try to output to pipe
ComponentDirection componentDirection = getComponent(ComponentType.Direction);
for (Direction relative : handler.relativeOutputDirections) {
Direction direction = BlockEntityUtils.getRelativeSide(componentDirection.getDirection(), relative.getOpposite());
BlockPos face = getBlockPos().relative(direction.getOpposite());
BlockEntity faceTile = getLevel().getBlockEntity(face);
if (faceTile != null) {
boolean electroPipe = faceTile instanceof GenericTilePipe;
LazyOptional<IFluidHandler> cap = faceTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction);
if (cap.isPresent()) {
IFluidHandler fHandler = cap.resolve().get();
for (FluidTank fluidTank : handler.getOutputTanks()) {
FluidStack tankFluid = fluidTank.getFluid();
if (electroPipe) {
if (fluidTank.getFluidAmount() > 0) {
fHandler.fill(tankFluid, FluidAction.EXECUTE);
}
} else {
int amtAccepted = fHandler.fill(tankFluid, FluidAction.SIMULATE);
FluidStack taken = new FluidStack(tankFluid.getFluid(), amtAccepted);
fHandler.fill(taken, FluidAction.EXECUTE);
}
}
}
}
}
}
Aggregations