Merged most recent master.
This commit is contained in:
@@ -93,7 +93,7 @@ public class TabButton extends ButtonWidget implements ITooltip {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getTooltipMessage() {
|
||||
public Text getTooltipMessage() {
|
||||
return getMessage();
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public class FluidAnnihilationPlanePart extends BasicStatePart implements IGridT
|
||||
}
|
||||
|
||||
@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)) {
|
||||
this.refresh();
|
||||
} else {
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class SharedFluidBusPart extends UpgradeablePart implements IGri
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
|
||||
@@ -193,7 +193,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
|
||||
}
|
||||
|
||||
@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.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
@@ -685,7 +684,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
|
||||
for (final AEPartLocation s : AEPartLocation.values()) {
|
||||
final IPart part = this.getPart(s);
|
||||
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
|
||||
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)) {
|
||||
final BlockEntity te = this.getHost().getTile();
|
||||
final AEPartLocation side = this.getSide();
|
||||
|
||||
@@ -132,7 +132,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab
|
||||
}
|
||||
|
||||
@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)) {
|
||||
this.refresh();
|
||||
} else {
|
||||
|
||||
@@ -18,34 +18,14 @@
|
||||
|
||||
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 appeng.api.config.*;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
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.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
@@ -73,6 +53,30 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.prioritylist.FuzzyPriorityList;
|
||||
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> {
|
||||
|
||||
@@ -232,7 +236,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
PlaneDirectionalPlaceContext context = new PlaneDirectionalPlaceContext(w, player, placePos,
|
||||
lookDirection, is, lookDirection.getOpposite());
|
||||
|
||||
i.onItemUse(context);
|
||||
i.useOnBlock(context);
|
||||
maxStorage -= is.getCount();
|
||||
|
||||
} else {
|
||||
@@ -357,49 +361,49 @@ 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.
|
||||
* <p>
|
||||
* Also removed {@link DirectionalPlaceContext#replacingClickedOnBlock} as this
|
||||
* Also removed {@link AutomaticItemPlacementContext#canReplaceExisting} as this
|
||||
* 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;
|
||||
|
||||
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,
|
||||
new BlockRayTraceResult(Vector3d.copyCenteredHorizontally(pos), facing, pos, false));
|
||||
new BlockHitResult(Vec3d.ofBottomCenter(pos), facing, pos, false));
|
||||
this.lookDirection = lookDirection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return this.rayTraceResult.getPos();
|
||||
public BlockPos getBlockPos() {
|
||||
return this.method_30344().getBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace() {
|
||||
return this.world.getBlockState(this.rayTraceResult.getPos()).isReplaceable(this);
|
||||
return this.getWorld().getBlockState(this.method_30344().getBlockPos()).canReplace(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getNearestLookingDirection() {
|
||||
public Direction getPlayerLookDirection() {
|
||||
return Direction.DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction[] getNearestLookingDirections() {
|
||||
public Direction[] getPlacementDirections() {
|
||||
switch (this.lookDirection) {
|
||||
case DOWN:
|
||||
default:
|
||||
return new Direction[] { Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH,
|
||||
Direction.WEST, Direction.UP };
|
||||
return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH,
|
||||
Direction.WEST, Direction.UP};
|
||||
case UP:
|
||||
return new Direction[] { Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST,
|
||||
Direction.SOUTH, Direction.WEST };
|
||||
return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST,
|
||||
Direction.SOUTH, Direction.WEST};
|
||||
case NORTH:
|
||||
return new Direction[] { Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST,
|
||||
return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST,
|
||||
Direction.UP, Direction.SOUTH };
|
||||
case SOUTH:
|
||||
return new Direction[] { Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST,
|
||||
@@ -414,18 +418,18 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getPlacementHorizontalFacing() {
|
||||
return this.lookDirection.getAxis() == Axis.Y ? Direction.NORTH : this.lookDirection;
|
||||
public Direction getPlayerFacing() {
|
||||
return this.lookDirection.getAxis() == Direction.Axis.Y ? Direction.NORTH : this.lookDirection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_225518_g_() {
|
||||
public boolean shouldCancelInteraction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPlacementYaw() {
|
||||
return (float) (this.lookDirection.getHorizontalIndex() * 90);
|
||||
public float getPlayerYaw() {
|
||||
return (float) (this.lookDirection.getHorizontal() * 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package appeng.parts.automation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
@@ -31,7 +31,7 @@ public final class PlaneConnectionHelper {
|
||||
* to
|
||||
*/
|
||||
public PlaneConnections getConnections() {
|
||||
TileEntity hostTileEntity = getHostTileEntity();
|
||||
BlockEntity hostTileEntity = getHostBlockEntity();
|
||||
AEPartLocation side = part.getSide();
|
||||
|
||||
final Direction facingRight, facingUp;
|
||||
@@ -71,19 +71,19 @@ public final class PlaneConnectionHelper {
|
||||
World world = hostTileEntity.getWorld();
|
||||
BlockPos pos = hostTileEntity.getPos();
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingRight.getOpposite())))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingRight.getOpposite())))) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingRight)))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingRight)))) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingUp.getOpposite())))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingUp.getOpposite())))) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(facingUp)))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(facingUp)))) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
@@ -100,28 +100,28 @@ public final class PlaneConnectionHelper {
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
TileEntity hostTile = getHostTileEntity();
|
||||
if (hostTile != null) {
|
||||
World world = hostTile.getWorld();
|
||||
BlockEntity hostEntity = getHostBlockEntity();
|
||||
if (hostEntity != null) {
|
||||
World world = hostEntity.getWorld();
|
||||
|
||||
final BlockPos pos = hostTile.getPos();
|
||||
final BlockPos pos = hostEntity.getPos();
|
||||
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(e.getOpposite())))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(e.getOpposite())))) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(e)))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(e)))) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(u.getOpposite())))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(u.getOpposite())))) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if (isCompatiblePlaneAdjacent(world.getTileEntity(pos.offset(u)))) {
|
||||
if (isCompatiblePlaneAdjacent(world.getBlockEntity(pos.offset(u)))) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
@@ -135,21 +135,18 @@ public final class PlaneConnectionHelper {
|
||||
* recalculated.
|
||||
*/
|
||||
public void updateConnections() {
|
||||
TileEntity hostTile = getHostTileEntity();
|
||||
if (hostTile != null) {
|
||||
hostTile.requestModelDataUpdate();
|
||||
}
|
||||
// Not needed in Fabric, since model data is automatically updated
|
||||
}
|
||||
|
||||
private boolean isCompatiblePlaneAdjacent(@Nullable TileEntity adjacentTileEntity) {
|
||||
if (adjacentTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) adjacentTileEntity).getPart(part.getSide());
|
||||
private boolean isCompatiblePlaneAdjacent(@Nullable BlockEntity adjacentBlockEntity) {
|
||||
if (adjacentBlockEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) adjacentBlockEntity).getPart(part.getSide());
|
||||
return p != null && p.getClass() == part.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private TileEntity getHostTileEntity() {
|
||||
private BlockEntity getHostBlockEntity() {
|
||||
IPartHost host = part.getHost();
|
||||
if (host != null) {
|
||||
return host.getTile();
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class SharedItemBusPart extends UpgradeablePart implements IGrid
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class CableAnchorPart implements IPart {
|
||||
}
|
||||
|
||||
@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
|
||||
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)) {
|
||||
this.resetCache(false);
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ public class StorageBusPart extends UpgradeablePart
|
||||
}
|
||||
|
||||
@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)) {
|
||||
final BlockEntity te = w.getBlockEntity(neighbor);
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ToggleBusPart extends BasicStatePart {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
final boolean oldHasRedstone = this.hasRedstone;
|
||||
this.hasRedstone = this.getHost().hasRedstone(this.getSide());
|
||||
|
||||
|
||||
@@ -18,32 +18,38 @@
|
||||
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import alexiil.mc.lib.attributes.Attribute;
|
||||
import alexiil.mc.lib.attributes.AttributeList;
|
||||
import alexiil.mc.lib.attributes.SearchOptions;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidAttributes;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidExtractable;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidInsertable;
|
||||
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
|
||||
import alexiil.mc.lib.attributes.fluid.filter.FluidFilter;
|
||||
import alexiil.mc.lib.attributes.fluid.impl.EmptyFluidExtractable;
|
||||
import alexiil.mc.lib.attributes.fluid.impl.RejectingFluidInsertable;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
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> {
|
||||
|
||||
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 IFluidHandler outputHandler = new OutputFluidHandler();
|
||||
private final FluidInsertable inputHandler = new InputFluidHandler();
|
||||
private final FluidExtractable outputHandler = new OutputFluidHandler();
|
||||
|
||||
public FluidP2PTunnelPart(final ItemStack is) {
|
||||
super(is);
|
||||
@@ -63,7 +69,7 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
if (this.isOutput()) {
|
||||
final FluidP2PTunnelPart in = this.getInput();
|
||||
if (in != null) {
|
||||
@@ -72,17 +78,13 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
|
||||
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
if (this.isOutput()) {
|
||||
return (LazyOptional<T>) LazyOptional.of(() -> this.outputHandler);
|
||||
}
|
||||
return (LazyOptional<T>) LazyOptional.of(() -> this.inputHandler);
|
||||
public void addAllAttributes(AttributeList<?> to) {
|
||||
if (this.isOutput()) {
|
||||
to.offer(this.outputHandler);
|
||||
} else {
|
||||
to.offer(this.inputHandler);
|
||||
}
|
||||
|
||||
return super.getCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,173 +92,103 @@ public class FluidP2PTunnelPart extends P2PTunnelPart<FluidP2PTunnelPart> {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
private IFluidHandler getAttachedFluidHandler() {
|
||||
LazyOptional<IFluidHandler> fluidHandler = LazyOptional.empty();
|
||||
// Gets the given attribute (or the defaultValue) of the block that this part attaches to
|
||||
private <T> T getAttachedAttribute(Attribute<T> attribute, T defaultValue) {
|
||||
T result = null;
|
||||
if (this.isActive()) {
|
||||
final TileEntity self = this.getTile();
|
||||
final TileEntity te = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
if (te != null) {
|
||||
fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
|
||||
this.getSide().getOpposite().getFacing());
|
||||
}
|
||||
final BlockEntity self = this.getTile();
|
||||
Direction direction = this.getSide().getFacing();
|
||||
BlockPos targetPos = self.getPos().offset(direction);
|
||||
World world = self.getWorld();
|
||||
result = attribute.getFirstOrNull(world, targetPos, SearchOptions.inDirection(direction));
|
||||
}
|
||||
return fluidHandler.orElse(NULL_FLUID_HANDLER);
|
||||
return result != null ? result : defaultValue;
|
||||
}
|
||||
|
||||
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
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@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;
|
||||
public FluidVolume attemptInsertion(FluidVolume fluidVolume, Simulation simulation) {
|
||||
FluidAmount overflowAmount = FluidAmount.ZERO;
|
||||
|
||||
try {
|
||||
final int outputTunnels = FluidP2PTunnelPart.this.getOutputs().size();
|
||||
final int amount = resource.getAmount();
|
||||
final FluidAmount amount = fluidVolume.amount();
|
||||
|
||||
if (outputTunnels == 0 || amount == 0) {
|
||||
return 0;
|
||||
if (outputTunnels == 0 || amount.isZero()) {
|
||||
return fluidVolume;
|
||||
}
|
||||
|
||||
final int amountPerOutput = Math.max(1, amount / outputTunnels);
|
||||
int overflow = amountPerOutput == 0 ? amount : amount % amountPerOutput;
|
||||
final FluidAmount amountPerOutput = amount.div(outputTunnels);
|
||||
|
||||
for (FluidP2PTunnelPart target : FluidP2PTunnelPart.this.getOutputs()) {
|
||||
final IFluidHandler output = target.getAttachedFluidHandler();
|
||||
final int toSend = amountPerOutput + overflow;
|
||||
final FluidStack fillWithFluidStack = resource.copy();
|
||||
fillWithFluidStack.setAmount(toSend);
|
||||
final FluidInsertable output = target.getAttachedOutput();
|
||||
final FluidVolume fillWithFluidStack = fluidVolume.withAmount(amountPerOutput.add(overflowAmount));
|
||||
|
||||
final int received = output.fill(fillWithFluidStack, action);
|
||||
|
||||
overflow = toSend - received;
|
||||
total += received;
|
||||
overflowAmount = output.attemptInsertion(fillWithFluidStack, simulation).amount();
|
||||
}
|
||||
|
||||
if (action == FluidAction.EXECUTE) {
|
||||
FluidP2PTunnelPart.this.queueTunnelDrain(PowerUnits.RF, total);
|
||||
if (simulation.isAction()) {
|
||||
FluidP2PTunnelPart.this.queueTunnelDrain(PowerUnits.RF, amount.sub(overflowAmount).asInexactDouble() * 1000);
|
||||
}
|
||||
} catch (GridAccessException ignored) {
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public FluidStack drain(int maxDrain, FluidAction action) {
|
||||
return FluidStack.EMPTY;
|
||||
return fluidVolume.withAmount(overflowAmount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class OutputFluidHandler implements IFluidHandler {
|
||||
private class OutputFluidHandler implements FluidExtractable {
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getTanks();
|
||||
public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) {
|
||||
return getAttachedInput().attemptExtraction(filter, maxAmount, simulation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public FluidStack getFluidInTank(int tank) {
|
||||
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getFluidInTank(tank);
|
||||
public FluidVolume attemptAnyExtraction(FluidAmount maxAmount, Simulation simulation) {
|
||||
return getAttachedInput().attemptAnyExtraction(maxAmount, simulation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return FluidP2PTunnelPart.this.getAttachedFluidHandler().getTankCapacity(tank);
|
||||
public FluidVolume extract(FluidFilter filter, FluidAmount maxAmount) {
|
||||
return getAttachedInput().extract(filter, maxAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
|
||||
return FluidP2PTunnelPart.this.getAttachedFluidHandler().isFluidValid(tank, stack);
|
||||
public FluidVolume extract(FluidKey filter, FluidAmount maxAmount) {
|
||||
return getAttachedInput().extract(filter, maxAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
return 0;
|
||||
public FluidVolume extract(FluidAmount maxAmount) {
|
||||
return getAttachedInput().extract(maxAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
return FluidP2PTunnelPart.this.getAttachedFluidHandler().drain(resource, action);
|
||||
public boolean couldExtractAnything() {
|
||||
return getAttachedInput().couldExtractAnything();
|
||||
}
|
||||
|
||||
@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;
|
||||
public FluidExtractable filtered(FluidFilter filter) {
|
||||
return getAttachedInput().filtered(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public FluidStack getFluidInTank(int tank) {
|
||||
return FluidStack.EMPTY;
|
||||
public FluidExtractable getPureExtractable() {
|
||||
return getAttachedInput().getPureExtractable();
|
||||
}
|
||||
|
||||
@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
|
||||
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
this.cachedInv = null;
|
||||
this.cachedInvs.clear();
|
||||
final ItemP2PTunnelPart input = this.getInput();
|
||||
|
||||
@@ -113,7 +113,7 @@ public class LightP2PTunnelPart extends P2PTunnelPart<LightP2PTunnelPart> implem
|
||||
}
|
||||
|
||||
@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)) {
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
|
||||
@@ -128,7 +128,7 @@ public class RedstoneP2PTunnelPart extends P2PTunnelPart<RedstoneP2PTunnelPart>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
public void onNeighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
|
||||
if (!this.isOutput()) {
|
||||
final BlockPos target = this.getTile().getPos().offset(this.getSide().getFacing());
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public abstract class AbstractReportingPart extends AEBasePart implements IMonit
|
||||
}
|
||||
|
||||
@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)) {
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
|
||||
Reference in New Issue
Block a user