Merged most recent master.

This commit is contained in:
Sebastian Hartte
2020-08-06 00:46:20 +02:00
parent 3c737d8d1e
commit 89058448cf
20 changed files with 165 additions and 233 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ public interface IPart extends ICustomCableConnection {
/** /**
* a block around the bus's host has been changed. * a block around the bus's host has been changed.
*/ */
void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor); void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor);
/** /**
* @return output redstone on facing side * @return output redstone on facing side
@@ -93,7 +93,7 @@ public class TabButton extends ButtonWidget implements ITooltip {
} }
@Override @Override
public ITextComponent getTooltipMessage() { public Text getTooltipMessage() {
return getMessage(); return getMessage();
} }
@@ -89,7 +89,7 @@ public class FluidAnnihilationPlanePart extends BasicStatePart implements IGridT
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.refresh(); this.refresh();
} else { } else {
@@ -67,7 +67,7 @@ public abstract class SharedFluidBusPart extends UpgradeablePart implements IGri
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
this.updateState(); this.updateState();
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) { if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
this.lastRedstone = !this.lastRedstone; this.lastRedstone = !this.lastRedstone;
+1 -1
View File
@@ -193,7 +193,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
} }
@@ -29,7 +29,6 @@ import javax.annotation.Nullable;
import net.fabricmc.fabric.api.util.NbtType; import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
@@ -685,7 +684,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
for (final AEPartLocation s : AEPartLocation.values()) { for (final AEPartLocation s : AEPartLocation.values()) {
final IPart part = this.getPart(s); final IPart part = this.getPart(s);
if (part != null) { if (part != null) {
part.onneighborUpdate(w, pos, neighbor); part.onNeighborUpdate(w, pos, neighbor);
} }
} }
@@ -71,7 +71,7 @@ public abstract class AbstractFormationPlanePart<T extends IAEStack<T>> extends
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
final BlockEntity te = this.getHost().getTile(); final BlockEntity te = this.getHost().getTile();
final AEPartLocation side = this.getSide(); final AEPartLocation side = this.getSide();
@@ -132,7 +132,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.refresh(); this.refresh();
} else { } else {
@@ -18,34 +18,14 @@
package appeng.parts.automation; package appeng.parts.automation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import alexiil.mc.lib.attributes.item.FixedItemInv; import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.config.AccessRestriction;
import appeng.api.config.*; import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.networking.events.MENetworkCellArrayUpdate; import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkChannelsChanged; import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe; import appeng.api.networking.events.MENetworkEventSubscribe;
@@ -73,6 +53,30 @@ import appeng.util.Platform;
import appeng.util.inv.InvOperation; import appeng.util.inv.InvOperation;
import appeng.util.prioritylist.FuzzyPriorityList; import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList; import appeng.util.prioritylist.PrecisePriorityList;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AutomaticItemPlacementContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack> { public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack> {
@@ -232,7 +236,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
PlaneDirectionalPlaceContext context = new PlaneDirectionalPlaceContext(w, player, placePos, PlaneDirectionalPlaceContext context = new PlaneDirectionalPlaceContext(w, player, placePos,
lookDirection, is, lookDirection.getOpposite()); lookDirection, is, lookDirection.getOpposite());
i.onItemUse(context); i.useOnBlock(context);
maxStorage -= is.getCount(); maxStorage -= is.getCount();
} else { } else {
@@ -357,39 +361,39 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
} }
/** /**
* A custom {@link DirectionalPlaceContext} which also accepts a player needed * A custom {@link AutomaticItemPlacementContext} which also accepts a player needed
* various blocks like seeds. * various blocks like seeds.
* <p> * <p>
* Also removed {@link DirectionalPlaceContext#replacingClickedOnBlock} as this * Also removed {@link AutomaticItemPlacementContext#canReplaceExisting} as this
* can cause a {@link StackOverflowError} for certain replaceable blocks. * can cause a {@link StackOverflowError} for certain replaceable blocks.
*/ */
private static class PlaneDirectionalPlaceContext extends BlockItemUseContext { private static class PlaneDirectionalPlaceContext extends ItemPlacementContext {
private final Direction lookDirection; private final Direction lookDirection;
public PlaneDirectionalPlaceContext(World world, PlayerEntity player, BlockPos pos, Direction lookDirection, public PlaneDirectionalPlaceContext(World world, PlayerEntity player, BlockPos pos, Direction lookDirection,
ItemStack itemStack, Direction facing) { ItemStack itemStack, Direction facing) {
super(world, player, Hand.MAIN_HAND, itemStack, super(world, player, Hand.MAIN_HAND, itemStack,
new BlockRayTraceResult(Vector3d.copyCenteredHorizontally(pos), facing, pos, false)); new BlockHitResult(Vec3d.ofBottomCenter(pos), facing, pos, false));
this.lookDirection = lookDirection; this.lookDirection = lookDirection;
} }
@Override @Override
public BlockPos getPos() { public BlockPos getBlockPos() {
return this.rayTraceResult.getPos(); return this.method_30344().getBlockPos();
} }
@Override @Override
public boolean canPlace() { public boolean canPlace() {
return this.world.getBlockState(this.rayTraceResult.getPos()).isReplaceable(this); return this.getWorld().getBlockState(this.method_30344().getBlockPos()).canReplace(this);
} }
@Override @Override
public Direction getNearestLookingDirection() { public Direction getPlayerLookDirection() {
return Direction.DOWN; return Direction.DOWN;
} }
@Override @Override
public Direction[] getNearestLookingDirections() { public Direction[] getPlacementDirections() {
switch (this.lookDirection) { switch (this.lookDirection) {
case DOWN: case DOWN:
default: default:
@@ -414,18 +418,18 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
} }
@Override @Override
public Direction getPlacementHorizontalFacing() { public Direction getPlayerFacing() {
return this.lookDirection.getAxis() == Axis.Y ? Direction.NORTH : this.lookDirection; return this.lookDirection.getAxis() == Direction.Axis.Y ? Direction.NORTH : this.lookDirection;
} }
@Override @Override
public boolean func_225518_g_() { public boolean shouldCancelInteraction() {
return false; return false;
} }
@Override @Override
public float getPlacementYaw() { public float getPlayerYaw() {
return (float) (this.lookDirection.getHorizontalIndex() * 90); return (float) (this.lookDirection.getHorizontal() * 90);
} }
} }
} }
@@ -2,9 +2,9 @@ package appeng.parts.automation;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.tileentity.TileEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
import appeng.api.parts.IPart; import appeng.api.parts.IPart;
@@ -31,7 +31,7 @@ public final class PlaneConnectionHelper {
* to * to
*/ */
public PlaneConnections getConnections() { public PlaneConnections getConnections() {
TileEntity hostTileEntity = getHostTileEntity(); BlockEntity hostTileEntity = getHostBlockEntity();
AEPartLocation side = part.getSide(); AEPartLocation side = part.getSide();
final Direction facingRight, facingUp; final Direction facingRight, facingUp;
@@ -71,19 +71,19 @@ public final class PlaneConnectionHelper {
World world = hostTileEntity.getWorld(); World world = hostTileEntity.getWorld();
BlockPos pos = hostTileEntity.getPos(); BlockPos pos = hostTileEntity.getPos();
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingRight.getOpposite())))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingRight.getOpposite())))) {
left = true; left = true;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingRight)))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingRight)))) {
right = true; right = true;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingUp.getOpposite())))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingUp.getOpposite())))) {
down = true; down = true;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingUp)))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingUp)))) {
up = true; up = true;
} }
} }
@@ -100,28 +100,28 @@ public final class PlaneConnectionHelper {
int maxX = 15; int maxX = 15;
int maxY = 15; int maxY = 15;
TileEntity hostTile = getHostTileEntity(); BlockEntity hostEntity = getHostBlockEntity();
if (hostTile != null) { if (hostEntity != null) {
World world = hostTile.getWorld(); World world = hostEntity.getWorld();
final BlockPos pos = hostTile.getPos(); final BlockPos pos = hostEntity.getPos();
final Direction e = bch.getWorldX(); final Direction e = bch.getWorldX();
final Direction u = bch.getWorldY(); final Direction u = bch.getWorldY();
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(e.getOpposite())))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(e.getOpposite())))) {
minX = 0; minX = 0;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(e)))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(e)))) {
maxX = 16; maxX = 16;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(u.getOpposite())))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(u.getOpposite())))) {
minY = 0; minY = 0;
} }
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(u)))) { if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(u)))) {
maxY = 16; maxY = 16;
} }
} }
@@ -135,21 +135,18 @@ public final class PlaneConnectionHelper {
* recalculated. * recalculated.
*/ */
public void updateConnections() { public void updateConnections() {
TileEntity hostTile = getHostTileEntity(); // Not needed in Fabric, since model data is automatically updated
if (hostTile != null) {
hostTile.requestModelDataUpdate();
}
} }
private boolean isCompatiblePlaneAdjacent(@Nullable TileEntity adjacentTileEntity) { private boolean isCompatiblePlaneAdjacent(@Nullable BlockEntity adjacentBlockEntity) {
if (adjacentTileEntity instanceof IPartHost) { if (adjacentBlockEntity instanceof IPartHost) {
final IPart p = ((IPartHost) adjacentTileEntity).getPart(part.getSide()); final IPart p = ((IPartHost) adjacentBlockEntity).getPart(part.getSide());
return p != null && p.getClass() == part.getClass(); return p != null && p.getClass() == part.getClass();
} }
return false; return false;
} }
private TileEntity getHostTileEntity() { private BlockEntity getHostBlockEntity() {
IPartHost host = part.getHost(); IPartHost host = part.getHost();
if (host != null) { if (host != null) {
return host.getTile(); return host.getTile();
@@ -71,7 +71,7 @@ public abstract class SharedItemBusPart extends UpgradeablePart implements IGrid
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
this.updateState(); this.updateState();
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) { if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
this.lastRedstone = !this.lastRedstone; this.lastRedstone = !this.lastRedstone;
@@ -117,7 +117,7 @@ public class CableAnchorPart implements IPart {
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
} }
@@ -134,7 +134,7 @@ public abstract class SharedStorageBusPart extends UpgradeablePart
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.resetCache(false); this.resetCache(false);
} }
@@ -255,7 +255,7 @@ public class StorageBusPart extends UpgradeablePart
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
final BlockEntity te = w.getBlockEntity(neighbor); final BlockEntity te = w.getBlockEntity(neighbor);
@@ -99,7 +99,7 @@ public class ToggleBusPart extends BasicStatePart {
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
final boolean oldHasRedstone = this.hasRedstone; final boolean oldHasRedstone = this.hasRedstone;
this.hasRedstone = this.getHost().hasRedstone(this.getSide()); this.hasRedstone = this.getHost().hasRedstone(this.getSide());
@@ -18,32 +18,38 @@
package appeng.parts.p2p; package appeng.parts.p2p;
import java.util.List; import alexiil.mc.lib.attributes.Attribute;
import alexiil.mc.lib.attributes.AttributeList;
import javax.annotation.Nonnull; import alexiil.mc.lib.attributes.SearchOptions;
import alexiil.mc.lib.attributes.Simulation;
import net.minecraft.item.ItemStack; import alexiil.mc.lib.attributes.fluid.FluidAttributes;
import net.minecraft.tileentity.TileEntity; import alexiil.mc.lib.attributes.fluid.FluidExtractable;
import net.minecraft.util.math.BlockPos; import alexiil.mc.lib.attributes.fluid.FluidInsertable;
import net.minecraft.world.IBlockReader; import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
import net.minecraftforge.common.capabilities.Capability; import alexiil.mc.lib.attributes.fluid.filter.FluidFilter;
import net.minecraftforge.common.util.LazyOptional; import alexiil.mc.lib.attributes.fluid.impl.EmptyFluidExtractable;
import net.minecraftforge.fluids.FluidStack; import alexiil.mc.lib.attributes.fluid.impl.RejectingFluidInsertable;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
import net.minecraftforge.fluids.capability.IFluidHandler; import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import appeng.api.config.PowerUnits; import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartModel; import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels; import appeng.items.parts.PartModels;
import appeng.me.GridAccessException; import appeng.me.GridAccessException;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import java.util.List;
public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> { public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fluids"); private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fluids");
private static final IFluidHandler NULL_FLUID_HANDLER = new NullFluidHandler();
private final IFluidHandler inputHandler = new InputFluidHandler(); private final FluidInsertable inputHandler = new InputFluidHandler();
private final IFluidHandler outputHandler = new OutputFluidHandler(); private final FluidExtractable outputHandler = new OutputFluidHandler();
public FluidP2PTunnelPart(final ItemStack is) { public FluidP2PTunnelPart(final ItemStack is) {
super(is); super(is);
@@ -63,7 +69,7 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
} }
@Override @Override
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (this.isOutput()) { if (this.isOutput()) {
final FluidP2PTunnelPart in = this.getInput(); final FluidP2PTunnelPart in = this.getInput();
if (in != null) { if (in != null) {
@@ -72,17 +78,13 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) { public void addAllAttributes(AttributeList<?> to) {
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
if (this.isOutput()) { if (this.isOutput()) {
return (LazyOptional<T>) LazyOptional.of(() -> this.outputHandler); to.offer(this.outputHandler);
} else {
to.offer(this.inputHandler);
} }
return (LazyOptional<T>) LazyOptional.of(() -> this.inputHandler);
}
return super.getCapability(capabilityClass);
} }
@Override @Override
@@ -90,173 +92,103 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
return MODELS.getModel(this.isPowered(), this.isActive()); return MODELS.getModel(this.isPowered(), this.isActive());
} }
private IFluidHandler getAttachedFluidHandler() { // Gets the given attribute (or the defaultValue) of the block that this part attaches to
LazyOptional<IFluidHandler> fluidHandler = LazyOptional.empty(); private <T> T getAttachedAttribute(Attribute<T> attribute, T defaultValue) {
T result = null;
if (this.isActive()) { if (this.isActive()) {
final TileEntity self = this.getTile(); final BlockEntity self = this.getTile();
final TileEntity te = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing())); Direction direction = this.getSide().getFacing();
BlockPos targetPos = self.getPos().offset(direction);
if (te != null) { World world = self.getWorld();
fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, result = attribute.getFirstOrNull(world, targetPos, SearchOptions.inDirection(direction));
this.getSide().getOpposite().getFacing());
} }
} return result != null ? result : defaultValue;
return fluidHandler.orElse(NULL_FLUID_HANDLER);
} }
private class InputFluidHandler implements IFluidHandler { private FluidInsertable getAttachedOutput() {
return getAttachedAttribute(FluidAttributes.INSERTABLE, RejectingFluidInsertable.NULL);
}
private FluidExtractable getAttachedInput() {
return getAttachedAttribute(FluidAttributes.EXTRACTABLE, EmptyFluidExtractable.NULL);
}
private class InputFluidHandler implements FluidInsertable {
@Override @Override
public int getTanks() { public FluidVolume attemptInsertion(FluidVolume fluidVolume, Simulation simulation) {
return 1; FluidAmount overflowAmount = FluidAmount.ZERO;
}
@Override
@Nonnull
public FluidStack getFluidInTank(int tank) {
return FluidStack.EMPTY;
}
@Override
public int getTankCapacity(int tank) {
return Integer.MAX_VALUE;
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return true;
}
@Override
public int fill(FluidStack resource, FluidAction action) {
int total = 0;
try { try {
final int outputTunnels = FluidP2PTunnelPart.this.getOutputs().size(); final int outputTunnels = FluidP2PTunnelPart.this.getOutputs().size();
final int amount = resource.getAmount(); final FluidAmount amount = fluidVolume.amount();
if (outputTunnels == 0 || amount == 0) { if (outputTunnels == 0 || amount.isZero()) {
return 0; return fluidVolume;
} }
final int amountPerOutput = Math.max(1, amount / outputTunnels); final FluidAmount amountPerOutput = amount.div(outputTunnels);
int overflow = amountPerOutput == 0 ? amount : amount % amountPerOutput;
for (FluidP2PTunnelPart target : FluidP2PTunnelPart.this.getOutputs()) { for (FluidP2PTunnelPart target : FluidP2PTunnelPart.this.getOutputs()) {
final IFluidHandler output = target.getAttachedFluidHandler(); final FluidInsertable output = target.getAttachedOutput();
final int toSend = amountPerOutput + overflow; final FluidVolume fillWithFluidStack = fluidVolume.withAmount(amountPerOutput.add(overflowAmount));
final FluidStack fillWithFluidStack = resource.copy();
fillWithFluidStack.setAmount(toSend);
final int received = output.fill(fillWithFluidStack, action); overflowAmount = output.attemptInsertion(fillWithFluidStack, simulation).amount();
overflow = toSend - received;
total += received;
} }
if (action == FluidAction.EXECUTE) { if (simulation.isAction()) {
FluidP2PTunnelPart.this.queueTunnelDrain(PowerUnits.RF, total); FluidP2PTunnelPart.this.queueTunnelDrain(PowerUnits.RF, amount.sub(overflowAmount).asInexactDouble() * 1000);
} }
} catch (GridAccessException ignored) { } catch (GridAccessException ignored) {
} }
return total; return fluidVolume.withAmount(overflowAmount);
}
}
private class OutputFluidHandler implements FluidExtractable {
@Override
public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) {
return getAttachedInput().attemptExtraction(filter, maxAmount, simulation);
} }
@Override @Override
@Nonnull public FluidVolume attemptAnyExtraction(FluidAmount maxAmount, Simulation simulation) {
public FluidStack drain(FluidStack resource, FluidAction action) { return getAttachedInput().attemptAnyExtraction(maxAmount, simulation);
return FluidStack.EMPTY;
} }
@Override @Override
@Nonnull public FluidVolume extract(FluidFilter filter, FluidAmount maxAmount) {
public FluidStack drain(int maxDrain, FluidAction action) { return getAttachedInput().extract(filter, maxAmount);
return FluidStack.EMPTY;
}
}
private class OutputFluidHandler implements IFluidHandler {
@Override
public int getTanks() {
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getTanks();
} }
@Override @Override
@Nonnull public FluidVolume extract(FluidKey filter, FluidAmount maxAmount) {
public FluidStack getFluidInTank(int tank) { return getAttachedInput().extract(filter, maxAmount);
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getFluidInTank(tank);
} }
@Override @Override
public int getTankCapacity(int tank) { public FluidVolume extract(FluidAmount maxAmount) {
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getTankCapacity(tank); return getAttachedInput().extract(maxAmount);
} }
@Override @Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) { public boolean couldExtractAnything() {
return FluidP2PTunnelPart.this.getAttachedFluidHandler().isFluidValid(tank, stack); return getAttachedInput().couldExtractAnything();
} }
@Override @Override
public int fill(FluidStack resource, FluidAction action) { public FluidExtractable filtered(FluidFilter filter) {
return 0; return getAttachedInput().filtered(filter);
} }
@Override @Override
@Nonnull public FluidExtractable getPureExtractable() {
public FluidStack drain(FluidStack resource, FluidAction action) { return getAttachedInput().getPureExtractable();
return FluidP2PTunnelPart.this.getAttachedFluidHandler().drain(resource, action); }
}
@Override
@Nonnull
public FluidStack drain(int maxDrain, FluidAction action) {
return FluidP2PTunnelPart.this.getAttachedFluidHandler().drain(maxDrain, action);
}
}
private static class NullFluidHandler implements IFluidHandler {
@Override
public int getTanks() {
return 0;
}
@Override
@Nonnull
public FluidStack getFluidInTank(int tank) {
return FluidStack.EMPTY;
}
@Override
public int getTankCapacity(int tank) {
return 0;
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return false;
}
@Override
public int fill(FluidStack resource, FluidAction action) {
return 0;
}
@Override
@Nonnull
public FluidStack drain(FluidStack resource, FluidAction action) {
return FluidStack.EMPTY;
}
@Override
@Nonnull
public FluidStack drain(int maxDrain, FluidAction action) {
return FluidStack.EMPTY;
}
} }
} }
@@ -67,7 +67,7 @@ public class ItemP2PTunnelPart extends P2PTunnelPart<ItemP2PTunnelPart> implemen
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
this.cachedInv = null; this.cachedInv = null;
this.cachedInvs.clear(); this.cachedInvs.clear();
final ItemP2PTunnelPart input = this.getInput(); final ItemP2PTunnelPart input = this.getInput();
@@ -113,7 +113,7 @@ public class LightP2PTunnelPart extends P2PTunnelPart<LightP2PTunnelPart> implem
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (this.isOutput() && pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (this.isOutput() && pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.opacity = -1; this.opacity = -1;
this.getHost().markForUpdate(); this.getHost().markForUpdate();
@@ -128,7 +128,7 @@ public class RedstoneP2PTunnelPart extends P2PTunnelPart<RedstoneP2PTunnelPart>
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (!this.isOutput()) { if (!this.isOutput()) {
final BlockPos target = this.getTile().getPos().offset(this.getSide().getFacing()); final BlockPos target = this.getTile().getPos().offset(this.getSide().getFacing());
@@ -105,7 +105,7 @@ public abstract class AbstractReportingPart extends AEBasePart implements IMonit
} }
@Override @Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) { public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) { if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.opacity = -1; this.opacity = -1;
this.getHost().markForUpdate(); this.getHost().markForUpdate();