From 390b0bf1e6f4e9c4f2afde13846ea3baebbb4a7d Mon Sep 17 00:00:00 2001 From: yueh Date: Sun, 22 Aug 2021 14:42:37 +0200 Subject: [PATCH] Closes #5256: Replace `AEPartLocation` with `Direction` (#5385) * Closes #5256: Replace `AEPartLocation` with `Direction` Completely replaced `AEPartLocation` with `Direction` with using `null` as center/internal. Added a constant to `Platform` for an array including `null` which need to iterate over all 7 cases. This is in preparation of moving from a custom interface to a capability or similar system. --- .../api/implementations/parts/ICablePart.java | 4 +- .../appeng/api/parts/IFacadeContainer.java | 15 +- .../java/appeng/api/parts/IFacadePart.java | 12 +- src/api/java/appeng/api/parts/IPart.java | 8 +- src/api/java/appeng/api/parts/IPartHost.java | 41 ++-- .../java/appeng/api/parts/SelectedPart.java | 16 +- .../java/appeng/api/util/AEPartLocation.java | 119 ---------- src/api/java/appeng/api/util/WorldCoord.java | 43 ++-- .../block/networking/CableBusBlock.java | 3 +- .../MolecularAssemblerBlockEntity.java | 15 +- .../networking/CableBusBlockEntity.java | 23 +- .../client/render/effects/EnergyFx.java | 6 +- .../render/effects/EnergyParticleData.java | 13 +- .../client/render/effects/MatterCannonFX.java | 5 +- .../packets/BlockTransitionEffectPacket.java | 14 +- .../packets/ItemTransitionEffectPacket.java | 14 +- .../sync/packets/PartPlacementPacket.java | 7 +- src/main/java/appeng/debug/DebugCardItem.java | 3 +- .../appeng/debug/DebugPartPlacerItem.java | 8 +- .../java/appeng/facade/FacadeContainer.java | 106 ++++----- src/main/java/appeng/facade/FacadePart.java | 22 +- src/main/java/appeng/facade/IFacadeItem.java | 7 +- .../MatterCannonDispenseItemBehavior.java | 12 +- .../waila/tile/CableBusDataProvider.java | 9 +- .../java/appeng/items/parts/FacadeItem.java | 4 +- .../java/appeng/me/cluster/MBCalculator.java | 9 +- src/main/java/appeng/menu/MenuLocator.java | 17 +- src/main/java/appeng/parts/AEBasePart.java | 14 +- .../java/appeng/parts/BusCollisionHelper.java | 80 ++++--- .../java/appeng/parts/CableBusContainer.java | 223 ++++++++---------- .../java/appeng/parts/CableBusStorage.java | 111 +++++---- src/main/java/appeng/parts/PartPlacement.java | 17 +- .../AbstractFormationPlanePart.java | 8 +- .../automation/AnnihilationPlanePart.java | 4 +- .../FluidAnnihilationPlanePart.java | 4 +- .../parts/automation/FluidExportBusPart.java | 2 +- .../automation/FluidFormationPlanePart.java | 6 +- .../parts/automation/FluidImportBusPart.java | 2 +- .../automation/FluidLevelEmitterPart.java | 12 +- .../parts/automation/FormationPlanePart.java | 25 +- .../parts/automation/LevelEmitterPart.java | 12 +- .../automation/PlaneConnectionHelper.java | 4 +- .../parts/automation/SharedFluidBusPart.java | 4 +- .../parts/automation/SharedItemBusPart.java | 6 +- .../parts/misc/AbstractStorageBusPart.java | 13 +- .../appeng/parts/misc/CableAnchorPart.java | 10 +- .../appeng/parts/misc/FluidInterfacePart.java | 4 +- .../appeng/parts/misc/ItemInterfacePart.java | 4 +- .../java/appeng/parts/misc/ToggleBusPart.java | 8 +- .../appeng/parts/networking/CablePart.java | 11 +- .../parts/networking/QuartzFiberPart.java | 8 +- .../parts/p2p/CapabilityP2PTunnelPart.java | 4 +- .../appeng/parts/p2p/LightP2PTunnelPart.java | 6 +- .../appeng/parts/p2p/MEP2PTunnelPart.java | 8 +- .../java/appeng/parts/p2p/P2PTunnelPart.java | 9 +- .../parts/p2p/RedstoneP2PTunnelPart.java | 4 +- .../parts/reporting/AbstractMonitorPart.java | 2 +- .../reporting/AbstractReportingPart.java | 10 +- .../reporting/ConversionMonitorPart.java | 2 +- src/main/java/appeng/spatial/CachedPlane.java | 6 +- src/main/java/appeng/util/Platform.java | 108 +-------- 61 files changed, 518 insertions(+), 788 deletions(-) delete mode 100644 src/api/java/appeng/api/util/AEPartLocation.java diff --git a/src/api/java/appeng/api/implementations/parts/ICablePart.java b/src/api/java/appeng/api/implementations/parts/ICablePart.java index 640178b98be..bb1ca92a4e3 100644 --- a/src/api/java/appeng/api/implementations/parts/ICablePart.java +++ b/src/api/java/appeng/api/implementations/parts/ICablePart.java @@ -33,11 +33,9 @@ import appeng.api.parts.IPartHost; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; /** - * Implemented on the {@link IPart}s cable objects that can be placed at {@link AEPartLocation}.UNKNOWN in - * {@link IPartHost}s + * Implemented on the {@link IPart}s cable objects that can be placed at the center of {@link IPartHost}s. */ public interface ICablePart extends IPart { diff --git a/src/api/java/appeng/api/parts/IFacadeContainer.java b/src/api/java/appeng/api/parts/IFacadeContainer.java index 3c894b56cec..c866d36ccfa 100644 --- a/src/api/java/appeng/api/parts/IFacadeContainer.java +++ b/src/api/java/appeng/api/parts/IFacadeContainer.java @@ -25,11 +25,12 @@ import java.io.IOException; +import javax.annotation.Nullable; + +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import appeng.api.util.AEPartLocation; - /** * Used Internally. * @@ -47,17 +48,13 @@ public interface IFacadeContainer { /** * Removed the facade on the given side, or does nothing. */ - void removeFacade(IPartHost host, AEPartLocation side); + void removeFacade(IPartHost host, Direction side); /** * @return the {@link IFacadePart} for a given side, or null. */ - IFacadePart getFacade(AEPartLocation s); - - /** - * rotate the facades left. - */ - void rotateLeft(); + @Nullable + IFacadePart getFacade(Direction s); /** * write nbt data diff --git a/src/api/java/appeng/api/parts/IFacadePart.java b/src/api/java/appeng/api/parts/IFacadePart.java index 5923b534a1c..de8dd42d94d 100644 --- a/src/api/java/appeng/api/parts/IFacadePart.java +++ b/src/api/java/appeng/api/parts/IFacadePart.java @@ -23,12 +23,13 @@ package appeng.api.parts; +import javax.annotation.Nonnull; + +import net.minecraft.core.Direction; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import appeng.api.util.AEPartLocation; - /** * Used Internally. * @@ -50,14 +51,13 @@ public interface IFacadePart { void getBoxes(IPartCollisionHelper ch, boolean itemEntity); /** - * @return side the facade is in + * @return The side the facade is attached to. */ - AEPartLocation getSide(); + @Nonnull + Direction getSide(); Item getItem(); - boolean notAEFacade(); - /** * The item that this facade masquerades as. */ diff --git a/src/api/java/appeng/api/parts/IPart.java b/src/api/java/appeng/api/parts/IPart.java index bcb8ca9c5cb..7e59eff1d32 100644 --- a/src/api/java/appeng/api/parts/IPart.java +++ b/src/api/java/appeng/api/parts/IPart.java @@ -29,6 +29,7 @@ import java.util.Set; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; @@ -59,7 +60,6 @@ import appeng.api.networking.IManagedGridNode; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; public interface IPart extends ICustomCableConnection { @@ -216,10 +216,10 @@ default AECableType getExternalCableConnectionType() { /** * called by the Part host to keep your part informed. * - * @param host part side + * @param side The side the part is attached to, or null to indicate the part is at the center. * @param blockEntity block entity of part */ - void setPartHostInfo(AEPartLocation side, IPartHost host, BlockEntity blockEntity); + void setPartHostInfo(@Nullable Direction side, IPartHost host, BlockEntity blockEntity); /** * Called when you right click the part, very similar to Block.onActivateBlock @@ -301,7 +301,7 @@ default boolean onShiftClicked(Player player, InteractionHand hand, Vec3 pos) { * @param held held item * @param side placing side */ - void onPlacement(Player player, InteractionHand hand, ItemStack held, AEPartLocation side); + void onPlacement(Player player, InteractionHand hand, ItemStack held, Direction side); /** * Used to determine which parts can be placed on what cables. diff --git a/src/api/java/appeng/api/parts/IPartHost.java b/src/api/java/appeng/api/parts/IPartHost.java index 2e505957d66..463ac3dbfd1 100644 --- a/src/api/java/appeng/api/parts/IPartHost.java +++ b/src/api/java/appeng/api/parts/IPartHost.java @@ -25,6 +25,8 @@ import java.util.Set; +import javax.annotation.Nullable; + import net.minecraft.core.Direction; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; @@ -33,7 +35,6 @@ import net.minecraft.world.phys.Vec3; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; /** @@ -49,45 +50,35 @@ public interface IPartHost extends ICustomCableConnection { IFacadeContainer getFacadeContainer(); /** - * Test if you can add a part to the specified side of the Part Host, {@link AEPartLocation}.UNKNOWN is used to - * represent the cable in the middle. + * Test if you can add a part to the specified side of the Part Host. A null side represents the center of the part + * host, where a cable would normally be. * * @param part to be added part - * @param side part placed onto side + * @param side onto side or null for center of host. * * @return returns false if the part cannot be added. */ - boolean canAddPart(ItemStack part, AEPartLocation side); + boolean canAddPart(ItemStack part, @Nullable Direction side); /** * try to add a new part to the specified side, returns false if it failed to be added. * * @param is new part - * @param side onto side + * @param side onto side or null for center of host. * @param owner with owning player - * - * @return null if the item failed to add, the side it was placed on other wise ( may different for cables, - * {@link AEPartLocation}.UNKNOWN ) - */ - AEPartLocation addPart(ItemStack is, AEPartLocation side, Player owner, InteractionHand hand); - - /** - * Get part by side ( center is {@link AEPartLocation}.UNKNOWN ) - * - * @param side side of part - * - * @return the part located on the specified side, or null if there is no part. + * @return If the part could be placed. */ - IPart getPart(AEPartLocation side); + boolean addPart(ItemStack is, @Nullable Direction side, Player owner, InteractionHand hand); /** - * Get part by side, this method cannot aquire the center part, you must use the other varient of getPart. + * Get a part attached to the host based on the location it's attached to. * - * @param side side of part + * @param side side of host or null for center. * * @return the part located on the specified side, or null if there is no part. */ - IPart getPart(Direction side); + @Nullable + IPart getPart(@Nullable Direction side); /** * removes the part on the side, this doesn't drop it or anything, if you don't do something with it, its just @@ -95,10 +86,10 @@ public interface IPartHost extends ICustomCableConnection { * * if you want to drop the part you must request it prior to removing it. * - * @param side side of part + * @param side onto side or null for center of host * @param suppressUpdate - used if you need to replace a part's INSTANCE, without really removing it first. */ - void removePart(AEPartLocation side, boolean suppressUpdate); + void removePart(@Nullable Direction side, boolean suppressUpdate); /** * something changed, might want to send a packet to clients to update state. @@ -156,7 +147,7 @@ public interface IPartHost extends ICustomCableConnection { * * @return true of the part host is receiving redstone from an external source. */ - boolean hasRedstone(AEPartLocation side); + boolean hasRedstone(@Nullable Direction side); /** * returns false if this block contains any parts or facades, true other wise. diff --git a/src/api/java/appeng/api/parts/SelectedPart.java b/src/api/java/appeng/api/parts/SelectedPart.java index 372f73c95c6..281ee09fbcf 100644 --- a/src/api/java/appeng/api/parts/SelectedPart.java +++ b/src/api/java/appeng/api/parts/SelectedPart.java @@ -23,7 +23,10 @@ package appeng.api.parts; -import appeng.api.util.AEPartLocation; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.core.Direction; /** * Reports a selected part from the IPartHost @@ -42,23 +45,24 @@ public class SelectedPart { public final IFacadePart facade; /** - * side the part is mounted too, or {@link AEPartLocation}.UNKNOWN for cables. + * side the part is mounted too, or null for cables. */ - public final AEPartLocation side; + @Nullable + public final Direction side; public SelectedPart() { this.part = null; this.facade = null; - this.side = AEPartLocation.INTERNAL; + this.side = null; } - public SelectedPart(final IPart part, final AEPartLocation side) { + public SelectedPart(final IPart part, final Direction side) { this.part = part; this.facade = null; this.side = side; } - public SelectedPart(final IFacadePart facade, final AEPartLocation side) { + public SelectedPart(final IFacadePart facade, @Nonnull Direction side) { this.part = null; this.facade = facade; this.side = side; diff --git a/src/api/java/appeng/api/util/AEPartLocation.java b/src/api/java/appeng/api/util/AEPartLocation.java deleted file mode 100644 index 17092df8794..00000000000 --- a/src/api/java/appeng/api/util/AEPartLocation.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.api.util; - -import javax.annotation.Nullable; - -import net.minecraft.core.Direction; - -/** - * Stand in for previous Forge Direction, Several uses of this class are simply legacy where as some uses of this class - * are intended. - */ -public enum AEPartLocation { - /** - * Negative Y - */ - DOWN(0, -1, 0), - - /** - * Positive Y - */ - UP(0, 1, 0), - - /** - * Negative Z - */ - NORTH(0, 0, -1), - - /** - * Positive Z - */ - SOUTH(0, 0, 1), - - /** - * Negative X - */ - WEST(-1, 0, 0), - - /** - * Posative X - */ - EAST(1, 0, 0), - - /** - * Center or inside of the block. - */ - INTERNAL(0, 0, 0); - - public final int xOffset; - public final int yOffset; - public final int zOffset; - - private static final Direction[] directions = { Direction.DOWN, Direction.UP, Direction.NORTH, Direction.SOUTH, - Direction.WEST, Direction.EAST, null }; - private static final int[] OPPOSITES = { 1, 0, 3, 2, 5, 4, 6 }; - - public static final AEPartLocation[] SIDE_LOCATIONS = { DOWN, UP, NORTH, SOUTH, WEST, EAST }; - - private AEPartLocation(final int x, final int y, final int z) { - this.xOffset = x; - this.yOffset = y; - this.zOffset = z; - } - - /** - * @return Part Location - */ - public static AEPartLocation fromOrdinal(final int id) { - if (id >= 0 && id < SIDE_LOCATIONS.length) { - return SIDE_LOCATIONS[id]; - } - - return INTERNAL; - } - - /** - * 100% chance of success. - * - * @param side - * @return proper Part Location for a facing enum. - */ - public static AEPartLocation fromFacing(@Nullable final Direction side) { - if (side == null) { - return INTERNAL; - } - return values()[side.ordinal()]; - } - - /** - * @return Opposite Part Location, INTERNAL remains INTERNAL. - */ - public AEPartLocation getOpposite() { - return fromOrdinal(OPPOSITES[this.ordinal()]); - } - - /** - * @return EnumFacing Equivalence, if Center returns null. - */ - public Direction getDirection() { - return directions[this.ordinal()]; - } - -} diff --git a/src/api/java/appeng/api/util/WorldCoord.java b/src/api/java/appeng/api/util/WorldCoord.java index b364cc46359..d5d6241e46c 100644 --- a/src/api/java/appeng/api/util/WorldCoord.java +++ b/src/api/java/appeng/api/util/WorldCoord.java @@ -24,6 +24,7 @@ package appeng.api.util; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.level.block.entity.BlockEntity; /** @@ -53,10 +54,10 @@ public WorldCoord(final BlockPos pos) { this.z = pos.getZ(); } - public WorldCoord subtract(final AEPartLocation direction, final int length) { - this.x -= direction.xOffset * length; - this.y -= direction.yOffset * length; - this.z -= direction.zOffset * length; + public WorldCoord subtract(final Direction direction, final int length) { + this.x -= direction.getStepX() * length; + this.y -= direction.getStepY() * length; + this.z -= direction.getStepZ() * length; return this; } @@ -95,7 +96,7 @@ public BlockPos getBlockPos() { /** * Will Return NULL if it's at some diagonal! */ - public AEPartLocation directionTo(final WorldCoord loc) { + public Direction directionTo(final WorldCoord loc) { final int ox = this.x - loc.x; final int oy = this.y - loc.y; final int oz = this.z - loc.z; @@ -104,28 +105,28 @@ public AEPartLocation directionTo(final WorldCoord loc) { final int ylen = Math.abs(oy); final int zlen = Math.abs(oz); - if (loc.isEqual(this.copy().add(AEPartLocation.EAST, xlen))) { - return AEPartLocation.EAST; + if (loc.isEqual(this.copy().add(Direction.EAST, xlen))) { + return Direction.EAST; } - if (loc.isEqual(this.copy().add(AEPartLocation.WEST, xlen))) { - return AEPartLocation.WEST; + if (loc.isEqual(this.copy().add(Direction.WEST, xlen))) { + return Direction.WEST; } - if (loc.isEqual(this.copy().add(AEPartLocation.NORTH, zlen))) { - return AEPartLocation.NORTH; + if (loc.isEqual(this.copy().add(Direction.NORTH, zlen))) { + return Direction.NORTH; } - if (loc.isEqual(this.copy().add(AEPartLocation.SOUTH, zlen))) { - return AEPartLocation.SOUTH; + if (loc.isEqual(this.copy().add(Direction.SOUTH, zlen))) { + return Direction.SOUTH; } - if (loc.isEqual(this.copy().add(AEPartLocation.UP, ylen))) { - return AEPartLocation.UP; + if (loc.isEqual(this.copy().add(Direction.UP, ylen))) { + return Direction.UP; } - if (loc.isEqual(this.copy().add(AEPartLocation.DOWN, ylen))) { - return AEPartLocation.DOWN; + if (loc.isEqual(this.copy().add(Direction.DOWN, ylen))) { + return Direction.DOWN; } return null; @@ -135,10 +136,10 @@ public boolean isEqual(final WorldCoord c) { return this.x == c.x && this.y == c.y && this.z == c.z; } - public WorldCoord add(final AEPartLocation direction, final int length) { - this.x += direction.xOffset * length; - this.y += direction.yOffset * length; - this.z += direction.zOffset * length; + public WorldCoord add(final Direction direction, final int length) { + this.x += direction.getStepX() * length; + this.y += direction.getStepY() * length; + this.z += direction.getStepZ() * length; return this; } diff --git a/src/main/java/appeng/block/networking/CableBusBlock.java b/src/main/java/appeng/block/networking/CableBusBlock.java index a65678124d2..5cab4e141c7 100644 --- a/src/main/java/appeng/block/networking/CableBusBlock.java +++ b/src/main/java/appeng/block/networking/CableBusBlock.java @@ -72,7 +72,6 @@ import appeng.api.parts.PartItemStack; import appeng.api.parts.SelectedPart; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.block.AEBaseEntityBlock; import appeng.blockentity.AEBaseBlockEntity; import appeng.blockentity.networking.CableBusBlockEntity; @@ -281,7 +280,7 @@ public BlockState getFacadeState(BlockGetter level, BlockPos pos, Direction side if (side != null) { IFacadeContainer container = this.fc(level, pos); if (container != null) { - IFacadePart facade = container.getFacade(AEPartLocation.fromFacing(side)); + IFacadePart facade = container.getFacade(side); if (facade != null) { return facade.getBlockState(); } diff --git a/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java b/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java index 6441273fa21..061a95155d2 100644 --- a/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java +++ b/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java @@ -52,7 +52,6 @@ import appeng.api.networking.ticking.TickingRequest; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.blockentity.grid.AENetworkInvBlockEntity; import appeng.blockentity.inventory.AppEngInternalInventory; @@ -87,7 +86,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity private final IItemHandler internalInv = new WrapperChainedItemHandler(this.gridInv, this.patternInv); private final UpgradeInventory upgrades; private boolean isPowered = false; - private AEPartLocation pushDirection = AEPartLocation.INTERNAL; + private Direction pushDirection = null; private ItemStack myPattern = ItemStack.EMPTY; private ICraftingPatternDetails myPlan = null; private double progress = 0; @@ -122,7 +121,7 @@ public boolean pushPattern(final ICraftingPatternDetails patternDetails, final C if (isEmpty && patternDetails.isCraftable()) { this.forcePlan = true; this.myPlan = patternDetails; - this.pushDirection = AEPartLocation.fromFacing(where); + this.pushDirection = where; for (int x = 0; x < table.getContainerSize(); x++) { this.gridInv.setStackInSlot(x, table.getItem(x)); @@ -219,7 +218,7 @@ public void load(final CompoundTag data) { if (ph != null && ph.isCraftable()) { this.forcePlan = true; this.myPlan = ph; - this.pushDirection = AEPartLocation.fromOrdinal(data.getInt("pushDirection")); + this.pushDirection = Direction.values()[data.getInt("pushDirection")]; } } } @@ -253,7 +252,7 @@ private void recalculatePlan() { this.forcePlan = false; this.myPlan = null; this.myPattern = ItemStack.EMPTY; - this.pushDirection = AEPartLocation.INTERNAL; + this.pushDirection = null; } this.updateSleepiness(); @@ -382,7 +381,7 @@ public TickRateModulation tickingRequest(final IGridNode node, int ticksSinceLas if (ItemHandlerUtil.isEmpty(this.patternInv)) { this.forcePlan = false; this.myPlan = null; - this.pushDirection = AEPartLocation.INTERNAL; + this.pushDirection = null; } this.ejectHeldItems(); @@ -431,12 +430,12 @@ private int userPower(final int ticksPassed, final int bonusValue, final double } private void pushOut(ItemStack output) { - if (this.pushDirection == AEPartLocation.INTERNAL) { + if (this.pushDirection == null) { for (final Direction d : Direction.values()) { output = this.pushTo(output, d); } } else { - output = this.pushTo(output, this.pushDirection.getDirection()); + output = this.pushTo(output, this.pushDirection); } if (output.isEmpty() && this.forcePlan) { diff --git a/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java b/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java index 976635069d6..680da595960 100644 --- a/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java +++ b/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java @@ -49,7 +49,6 @@ import appeng.api.parts.SelectedPart; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; import appeng.blockentity.AEBaseBlockEntity; import appeng.client.render.cablebus.CableBusRenderState; @@ -164,7 +163,7 @@ public boolean canBeRotated() { } @Override - public void getDrops(final Level level, final BlockPos pos, final List drops) { + public void getDrops(final Level level, final BlockPos pos, final List drops) { this.getCableBus().getDrops(drops); } @@ -191,28 +190,23 @@ public IFacadeContainer getFacadeContainer() { } @Override - public boolean canAddPart(final ItemStack is, final AEPartLocation side) { + public boolean canAddPart(final ItemStack is, final Direction side) { return this.getCableBus().canAddPart(is, side); } @Override - public AEPartLocation addPart(final ItemStack is, final AEPartLocation side, final Player player, + public boolean addPart(final ItemStack is, final Direction side, final Player player, final InteractionHand hand) { return this.getCableBus().addPart(is, side, player, hand); } - @Override - public IPart getPart(final AEPartLocation side) { - return this.cb.getPart(side); - } - @Override public IPart getPart(final Direction side) { - return this.getCableBus().getPart(side); + return this.cb.getPart(side); } @Override - public void removePart(final AEPartLocation side, final boolean suppressUpdate) { + public void removePart(@Nullable Direction side, final boolean suppressUpdate) { this.getCableBus().removePart(side, suppressUpdate); } @@ -253,7 +247,7 @@ public void partChanged() { } @Override - public boolean hasRedstone(final AEPartLocation side) { + public boolean hasRedstone(final Direction side) { return this.getCableBus().hasRedstone(side); } @@ -298,9 +292,8 @@ private void setCableBus(final CableBusContainer cb) { } @Override - public LazyOptional getCapability(Capability capabilityClass, @Nullable Direction fromSide) { + public LazyOptional getCapability(Capability capabilityClass, @Nullable Direction partLocation) { // Note that null will be translated to INTERNAL here - AEPartLocation partLocation = AEPartLocation.fromFacing(fromSide); IPart part = this.getPart(partLocation); LazyOptional result = part == null ? LazyOptional.empty() : part.getCapability(capabilityClass); @@ -309,7 +302,7 @@ public LazyOptional getCapability(Capability capabilityClass, @Nullabl return result; } - return super.getCapability(capabilityClass, fromSide); + return super.getCapability(capabilityClass, partLocation); } @Nonnull diff --git a/src/main/java/appeng/client/render/effects/EnergyFx.java b/src/main/java/appeng/client/render/effects/EnergyFx.java index 06d28367542..9e1410b5474 100644 --- a/src/main/java/appeng/client/render/effects/EnergyFx.java +++ b/src/main/java/appeng/client/render/effects/EnergyFx.java @@ -116,9 +116,9 @@ public Particle createParticle(EnergyParticleData data, ClientLevel level, doubl result.setMotionY((float) ySpeed); result.setMotionZ((float) zSpeed); if (data.forItem) { - result.x += -0.2 * data.direction.xOffset; - result.y += -0.2 * data.direction.yOffset; - result.z += -0.2 * data.direction.zOffset; + result.x += -0.2 * data.direction.getStepX(); + result.y += -0.2 * data.direction.getStepY(); + result.z += -0.2 * data.direction.getStepZ(); result.quadSize *= 0.8f; } return result; diff --git a/src/main/java/appeng/client/render/effects/EnergyParticleData.java b/src/main/java/appeng/client/render/effects/EnergyParticleData.java index 9e973cc6876..1e9101d2986 100644 --- a/src/main/java/appeng/client/render/effects/EnergyParticleData.java +++ b/src/main/java/appeng/client/render/effects/EnergyParticleData.java @@ -23,22 +23,21 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleOptions.Deserializer; import net.minecraft.core.particles.ParticleType; import net.minecraft.network.FriendlyByteBuf; -import appeng.api.util.AEPartLocation; - public class EnergyParticleData implements ParticleOptions { - public static final EnergyParticleData FOR_BLOCK = new EnergyParticleData(false, AEPartLocation.INTERNAL); + public static final EnergyParticleData FOR_BLOCK = new EnergyParticleData(false, null); public final boolean forItem; - public final AEPartLocation direction; + public final Direction direction; - public EnergyParticleData(boolean forItem, AEPartLocation direction) { + public EnergyParticleData(boolean forItem, Direction direction) { this.forItem = forItem; this.direction = direction; } @@ -50,14 +49,14 @@ public EnergyParticleData fromCommand(ParticleType particleT reader.expect(' '); boolean forItem = reader.readBoolean(); reader.expect(' '); - AEPartLocation direction = AEPartLocation.valueOf(reader.readString().toUpperCase(Locale.ROOT)); + Direction direction = Direction.valueOf(reader.readString().toUpperCase(Locale.ROOT)); return new EnergyParticleData(forItem, direction); } @Override public EnergyParticleData fromNetwork(ParticleType particleTypeIn, FriendlyByteBuf buffer) { boolean forItem = buffer.readBoolean(); - AEPartLocation direction = AEPartLocation.values()[buffer.readByte()]; + Direction direction = Direction.values()[buffer.readByte()]; return new EnergyParticleData(forItem, direction); } }; diff --git a/src/main/java/appeng/client/render/effects/MatterCannonFX.java b/src/main/java/appeng/client/render/effects/MatterCannonFX.java index 1e3255f10e7..566ac0b03f5 100644 --- a/src/main/java/appeng/client/render/effects/MatterCannonFX.java +++ b/src/main/java/appeng/client/render/effects/MatterCannonFX.java @@ -24,12 +24,11 @@ import net.minecraft.client.particle.ParticleRenderType; import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.particle.TextureSheetParticle; +import net.minecraft.core.Direction; import net.minecraft.core.particles.SimpleParticleType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import appeng.api.util.AEPartLocation; - public class MatterCannonFX extends TextureSheetParticle { public MatterCannonFX(final ClientLevel level, final double x, final double y, final double z, @@ -47,7 +46,7 @@ public MatterCannonFX(final ClientLevel level, final double x, final double y, f this.pickSprite(sprite); } - public void fromItem(final AEPartLocation d) { + public void fromItem(final Direction d) { this.quadSize *= 1.2f; } diff --git a/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java b/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java index 8718d43e954..20d62f6b88a 100644 --- a/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java +++ b/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java @@ -23,6 +23,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -37,7 +38,6 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.registries.GameData; -import appeng.api.util.AEPartLocation; import appeng.client.render.effects.EnergyParticleData; import appeng.core.AELog; import appeng.core.AppEngClient; @@ -53,14 +53,14 @@ public class BlockTransitionEffectPacket extends BasePacket { private final BlockPos pos; private final BlockState blockState; - private final AEPartLocation direction; + private final Direction direction; private final SoundMode soundMode; public enum SoundMode { BLOCK, FLUID, NONE } - public BlockTransitionEffectPacket(BlockPos pos, BlockState blockState, AEPartLocation direction, + public BlockTransitionEffectPacket(BlockPos pos, BlockState blockState, Direction direction, SoundMode soundMode) { this.pos = pos; this.blockState = blockState; @@ -91,7 +91,7 @@ public BlockTransitionEffectPacket(final FriendlyByteBuf stream) { blockState = Blocks.AIR.defaultBlockState(); } this.blockState = blockState; - this.direction = AEPartLocation.fromOrdinal(stream.readByte()); + this.direction = Direction.values()[stream.readByte()]; this.soundMode = SoundMode.values()[stream.readByte()]; } @@ -113,9 +113,9 @@ private void spawnParticles() { double x = pos.getX() + Platform.getRandomFloat(); double y = pos.getY() + Platform.getRandomFloat(); double z = pos.getZ() + Platform.getRandomFloat(); - double speedX = 0.1f * this.direction.xOffset; - double speedY = 0.1f * this.direction.yOffset; - double speedZ = 0.1f * this.direction.zOffset; + double speedX = 0.1f * this.direction.getStepX(); + double speedY = 0.1f * this.direction.getStepY(); + double speedZ = 0.1f * this.direction.getStepZ(); Minecraft.getInstance().particleEngine.createParticle(data, x, y, z, speedX, speedY, speedZ); } diff --git a/src/main/java/appeng/core/sync/packets/ItemTransitionEffectPacket.java b/src/main/java/appeng/core/sync/packets/ItemTransitionEffectPacket.java index 0f92a38b0d7..5d98285bb01 100644 --- a/src/main/java/appeng/core/sync/packets/ItemTransitionEffectPacket.java +++ b/src/main/java/appeng/core/sync/packets/ItemTransitionEffectPacket.java @@ -21,12 +21,12 @@ import io.netty.buffer.Unpooled; import net.minecraft.client.Minecraft; +import net.minecraft.core.Direction; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import appeng.api.util.AEPartLocation; import appeng.client.render.effects.EnergyParticleData; import appeng.core.AppEngClient; import appeng.core.sync.BasePacket; @@ -41,9 +41,9 @@ public class ItemTransitionEffectPacket extends BasePacket { private final double x; private final double y; private final double z; - private final AEPartLocation d; + private final Direction d; - public ItemTransitionEffectPacket(double x, double y, double z, AEPartLocation direction) { + public ItemTransitionEffectPacket(double x, double y, double z, Direction direction) { this.x = x; this.y = y; this.z = z; @@ -64,7 +64,7 @@ public ItemTransitionEffectPacket(final FriendlyByteBuf stream) { this.x = stream.readFloat(); this.y = stream.readFloat(); this.z = stream.readFloat(); - this.d = AEPartLocation.fromOrdinal(stream.readByte()); + this.d = Direction.values()[stream.readByte()]; } @Override @@ -77,9 +77,9 @@ public void clientPacketData(final INetworkInfo network, final Player player) { double x = this.x + Platform.getRandomFloat() * 0.5 - 0.25; double y = this.y + Platform.getRandomFloat() * 0.5 - 0.25; double z = this.z + Platform.getRandomFloat() * 0.5 - 0.25; - double speedX = 0.1f * this.d.xOffset; - double speedY = 0.1f * this.d.yOffset; - double speedZ = 0.1f * this.d.zOffset; + double speedX = 0.1f * this.d.getStepX(); + double speedY = 0.1f * this.d.getStepY(); + double speedZ = 0.1f * this.d.getStepZ(); Minecraft.getInstance().particleEngine.createParticle(data, x, y, z, speedX, speedY, speedZ); } } diff --git a/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java b/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java index 1d1c2e37f73..1b20ef4cb1f 100644 --- a/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java +++ b/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java @@ -67,12 +67,11 @@ public PartPlacementPacket(final BlockPos pos, final Direction face, final float @Override public void serverPacketData(final INetworkInfo manager, final ServerPlayer player) { - final ServerPlayer sender = (ServerPlayer) player; - AppEng.instance().setPartInteractionPlayer(sender); + AppEng.instance().setPartInteractionPlayer(player); try { PartPlacement.setEyeHeight(this.eyeHeight); - PartPlacement.place(sender.getItemInHand(this.hand), new BlockPos(this.x, this.y, this.z), - Direction.values()[this.face], sender, this.hand, sender.level, + PartPlacement.place(player.getItemInHand(this.hand), new BlockPos(this.x, this.y, this.z), + Direction.values()[this.face], player, this.hand, player.level, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0); } finally { AppEng.instance().setPartInteractionPlayer(null); diff --git a/src/main/java/appeng/debug/DebugCardItem.java b/src/main/java/appeng/debug/DebugCardItem.java index 76eb835273d..d1cc4de977e 100644 --- a/src/main/java/appeng/debug/DebugCardItem.java +++ b/src/main/java/appeng/debug/DebugCardItem.java @@ -45,7 +45,6 @@ import appeng.api.networking.ticking.ITickManager; import appeng.api.parts.IPart; import appeng.api.parts.IPartHost; -import appeng.api.util.AEPartLocation; import appeng.blockentity.networking.ControllerBlockEntity; import appeng.hooks.ticking.TickHandler; import appeng.items.AEBaseItem; @@ -176,7 +175,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { var te = level.getBlockEntity(pos); if (te instanceof IPartHost partHost) { - final IPart center = partHost.getPart(AEPartLocation.INTERNAL); + final IPart center = partHost.getPart(null); partHost.markForUpdate(); if (center != null) { final GridNode n = (GridNode) center.getGridNode(); diff --git a/src/main/java/appeng/debug/DebugPartPlacerItem.java b/src/main/java/appeng/debug/DebugPartPlacerItem.java index 49a560a90b2..826c243a189 100644 --- a/src/main/java/appeng/debug/DebugPartPlacerItem.java +++ b/src/main/java/appeng/debug/DebugPartPlacerItem.java @@ -37,7 +37,6 @@ import appeng.api.parts.IPart; import appeng.api.parts.IPartHost; import appeng.api.parts.PartItemStack; -import appeng.api.util.AEPartLocation; import appeng.items.AEBaseItem; import appeng.items.parts.ColoredPartItem; import appeng.items.parts.PartItem; @@ -77,7 +76,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { Util.NIL_UUID); return InteractionResult.FAIL; } - IPart cable = center.getPart(AEPartLocation.INTERNAL); + IPart cable = center.getPart(null); if (cable == null) { player.sendMessage(new TextComponent("Clicked part host must have an INSIDE part"), Util.NIL_UUID); return InteractionResult.FAIL; @@ -108,13 +107,12 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { continue; } - if (partHost.addPart(cable.getItemStack(PartItemStack.PICK), AEPartLocation.INTERNAL, player, - null) == null) { + if (!partHost.addPart(cable.getItemStack(PartItemStack.PICK), null, player, null)) { continue; } for (Direction dir : perpendicularFaces) { ItemStack itemStack = new ItemStack(item, 1); - partHost.addPart(itemStack, AEPartLocation.fromFacing(dir), player, null); + partHost.addPart(itemStack, dir, player, null); } } diff --git a/src/main/java/appeng/facade/FacadeContainer.java b/src/main/java/appeng/facade/FacadeContainer.java index ade8adc8a5c..3388ea13022 100644 --- a/src/main/java/appeng/facade/FacadeContainer.java +++ b/src/main/java/appeng/facade/FacadeContainer.java @@ -20,7 +20,9 @@ import java.io.IOException; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -28,14 +30,12 @@ import appeng.api.parts.IFacadeContainer; import appeng.api.parts.IFacadePart; import appeng.api.parts.IPartHost; -import appeng.api.util.AEPartLocation; import appeng.core.definitions.AEItems; import appeng.items.parts.FacadeItem; import appeng.parts.CableBusStorage; public class FacadeContainer implements IFacadeContainer { - private final int facades = 6; private final CableBusStorage storage; private final Runnable changeCallback; @@ -47,7 +47,7 @@ public FacadeContainer(final CableBusStorage cbs, Runnable changeCallback) { @Override public boolean addFacade(final IFacadePart a) { if (this.getFacade(a.getSide()) == null) { - this.storage.setFacade(a.getSide().ordinal(), a); + this.storage.setFacade(a.getSide(), a); this.notifyChange(); return true; } @@ -55,9 +55,9 @@ public boolean addFacade(final IFacadePart a) { } @Override - public void removeFacade(final IPartHost host, final AEPartLocation side) { - if (side != null && side != AEPartLocation.INTERNAL && this.storage.getFacade(side.ordinal()) != null) { - this.storage.setFacade(side.ordinal(), null); + public void removeFacade(final IPartHost host, final Direction side) { + if (side != null && this.storage.getFacade(side) != null) { + this.storage.removeFacade(side); this.notifyChange(); if (host != null) { host.markForUpdate(); @@ -66,36 +66,38 @@ public void removeFacade(final IPartHost host, final AEPartLocation side) { } @Override - public IFacadePart getFacade(final AEPartLocation s) { - return this.storage.getFacade(s.ordinal()); + public IFacadePart getFacade(final Direction side) { + return this.storage.getFacade(side); } - @Override - public void rotateLeft() { - final IFacadePart[] newFacades = new FacadePart[6]; - - newFacades[AEPartLocation.UP.ordinal()] = this.storage.getFacade(AEPartLocation.UP.ordinal()); - newFacades[AEPartLocation.DOWN.ordinal()] = this.storage.getFacade(AEPartLocation.DOWN.ordinal()); - - newFacades[AEPartLocation.EAST.ordinal()] = this.storage.getFacade(AEPartLocation.NORTH.ordinal()); - newFacades[AEPartLocation.SOUTH.ordinal()] = this.storage.getFacade(AEPartLocation.EAST.ordinal()); + private String getNbtKey(Direction side) { + return "facade:" + side.ordinal(); + } - newFacades[AEPartLocation.WEST.ordinal()] = this.storage.getFacade(AEPartLocation.SOUTH.ordinal()); - newFacades[AEPartLocation.NORTH.ordinal()] = this.storage.getFacade(AEPartLocation.WEST.ordinal()); + @Override + public void readFromNBT(final CompoundTag c) { + for (var side : Direction.values()) { + this.storage.removeFacade(side); - for (int x = 0; x < this.facades; x++) { - this.storage.setFacade(x, newFacades[x]); + String key = getNbtKey(side); + if (c.contains(key, Tag.TAG_COMPOUND)) { + var is = ItemStack.of(c.getCompound(key)); + if (!is.isEmpty()) { + if (is.getItem() instanceof IFacadeItem facadeItem) { + this.storage.setFacade(side, facadeItem.createPartFromItemStack(is, side)); + } + } + } } - this.notifyChange(); } @Override public void writeToNBT(final CompoundTag c) { - for (int x = 0; x < this.facades; x++) { - if (this.storage.getFacade(x) != null) { - final CompoundTag data = new CompoundTag(); - this.storage.getFacade(x).getItemStack().save(data); - c.put("facade:" + x, data); + for (var side : Direction.values()) { + if (this.storage.getFacade(side) != null) { + var data = new CompoundTag(); + this.storage.getFacade(side).getItemStack().save(data); + c.put(getNbtKey(side), data); } } } @@ -106,69 +108,49 @@ public boolean readFromStream(final FriendlyByteBuf out) throws IOException { boolean changed = false; - for (int x = 0; x < this.facades; x++) { - final AEPartLocation side = AEPartLocation.fromOrdinal(x); - final int ix = 1 << x; + for (var side : Direction.values()) { + final int ix = 1 << side.ordinal(); if ((facadeSides & ix) == ix) { - final int id = Math.abs(out.readInt()); + final int id = out.readVarInt(); final FacadeItem ifa = AEItems.FACADE.asItem(); final ItemStack facade = ifa.createFromID(id); if (facade != null) { - changed = changed || this.storage.getFacade(x) == null; - this.storage.setFacade(x, ifa.createPartFromItemStack(facade, side)); + changed = changed || this.storage.getFacade(side) == null; + this.storage.setFacade(side, ifa.createPartFromItemStack(facade, side)); } } else { - changed = changed || this.storage.getFacade(x) != null; - this.storage.setFacade(x, null); + changed = changed || this.storage.getFacade(side) != null; + this.storage.removeFacade(side); } } return changed; } - @Override - public void readFromNBT(final CompoundTag c) { - for (int x = 0; x < this.facades; x++) { - this.storage.setFacade(x, null); - - final CompoundTag t = c.getCompound("facade:" + x); - if (t != null) { - final ItemStack is = ItemStack.of(t); - if (!is.isEmpty()) { - final Item i = is.getItem(); - if (i instanceof IFacadeItem) { - this.storage.setFacade(x, - ((IFacadeItem) i).createPartFromItemStack(is, AEPartLocation.fromOrdinal(x))); - } - } - } - } - } - @Override public void writeToStream(final FriendlyByteBuf out) throws IOException { int facadeSides = 0; - for (int x = 0; x < this.facades; x++) { - if (this.getFacade(AEPartLocation.fromOrdinal(x)) != null) { - facadeSides |= 1 << x; + for (var side : Direction.values()) { + if (this.getFacade(side) != null) { + facadeSides |= 1 << side.ordinal(); } } out.writeByte((byte) facadeSides); - for (int x = 0; x < this.facades; x++) { - final IFacadePart part = this.getFacade(AEPartLocation.fromOrdinal(x)); + for (var side : Direction.values()) { + final IFacadePart part = this.getFacade(side); if (part != null) { final int itemID = Item.getId(part.getItem()); - out.writeInt(itemID * (part.notAEFacade() ? -1 : 1)); + out.writeVarInt(itemID); } } } @Override public boolean isEmpty() { - for (int x = 0; x < this.facades; x++) { - if (this.storage.getFacade(x) != null) { + for (var side : Direction.values()) { + if (this.storage.getFacade(side) != null) { return false; } } diff --git a/src/main/java/appeng/facade/FacadePart.java b/src/main/java/appeng/facade/FacadePart.java index a1ea62de1ad..b13cef01382 100644 --- a/src/main/java/appeng/facade/FacadePart.java +++ b/src/main/java/appeng/facade/FacadePart.java @@ -18,6 +18,11 @@ package appeng.facade; +import java.util.Objects; + +import javax.annotation.Nonnull; + +import net.minecraft.core.Direction; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -26,17 +31,15 @@ import appeng.api.parts.IFacadePart; import appeng.api.parts.IPartCollisionHelper; -import appeng.api.util.AEPartLocation; public class FacadePart implements IFacadePart { private final ItemStack facade; - private final AEPartLocation side; + private final Direction side; - public FacadePart(final ItemStack facade, final AEPartLocation side) { - if (facade == null) { - throw new IllegalArgumentException("Facade Part constructed on null item."); - } + public FacadePart(@Nonnull ItemStack facade, @Nonnull Direction side) { + Objects.requireNonNull(side, "side"); + Objects.requireNonNull(facade, "facade"); this.facade = facade.copy(); this.facade.setCount(1); this.side = side; @@ -59,7 +62,7 @@ public void getBoxes(final IPartCollisionHelper ch, boolean itemEntity) { } @Override - public AEPartLocation getSide() { + public Direction getSide() { return this.side; } @@ -72,11 +75,6 @@ public Item getItem() { return is.getItem(); } - @Override - public boolean notAEFacade() { - return !(this.facade.getItem() instanceof IFacadeItem); - } - @Override public ItemStack getTextureItem() { final Item maybeFacade = this.facade.getItem(); diff --git a/src/main/java/appeng/facade/IFacadeItem.java b/src/main/java/appeng/facade/IFacadeItem.java index 223286b90a3..b2490704f3c 100644 --- a/src/main/java/appeng/facade/IFacadeItem.java +++ b/src/main/java/appeng/facade/IFacadeItem.java @@ -18,14 +18,15 @@ package appeng.facade; +import javax.annotation.Nonnull; + +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import appeng.api.util.AEPartLocation; - public interface IFacadeItem { - FacadePart createPartFromItemStack(ItemStack is, AEPartLocation side); + FacadePart createPartFromItemStack(ItemStack is, @Nonnull Direction side); ItemStack getTextureItem(ItemStack is); diff --git a/src/main/java/appeng/hooks/MatterCannonDispenseItemBehavior.java b/src/main/java/appeng/hooks/MatterCannonDispenseItemBehavior.java index 45f790a1eb7..aaef0397f15 100644 --- a/src/main/java/appeng/hooks/MatterCannonDispenseItemBehavior.java +++ b/src/main/java/appeng/hooks/MatterCannonDispenseItemBehavior.java @@ -19,12 +19,12 @@ package appeng.hooks; import net.minecraft.core.BlockSource; +import net.minecraft.core.Direction; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.DispenserBlock; -import appeng.api.util.AEPartLocation; import appeng.items.tools.powered.MatterCannonItem; import appeng.util.Platform; @@ -35,10 +35,10 @@ protected ItemStack execute(final BlockSource dispenser, ItemStack dispensedItem final Item i = dispensedItem.getItem(); if (i instanceof MatterCannonItem tm) { var direction = dispenser.getBlockState().getValue(DispenserBlock.FACING); - AEPartLocation dir = AEPartLocation.INTERNAL; - for (var d : AEPartLocation.SIDE_LOCATIONS) { - if (direction.getStepX() == d.xOffset && direction.getStepY() == d.yOffset - && direction.getStepZ() == d.zOffset) { + Direction dir = null; + for (var d : Direction.values()) { + if (direction.getStepX() == d.getStepX() && direction.getStepY() == d.getStepY() + && direction.getStepZ() == d.getStepZ()) { dir = d; } } @@ -47,7 +47,7 @@ protected ItemStack execute(final BlockSource dispenser, ItemStack dispensedItem var p = Platform.getPlayer(level); Platform.configurePlayer(p, dir, dispenser.getEntity()); - p.setPos(p.getX() + dir.xOffset, p.getY() + dir.yOffset, p.getZ() + dir.zOffset); + p.setPos(p.getX() + dir.getStepX(), p.getY() + dir.getStepY(), p.getZ() + dir.getStepZ()); dispensedItem = tm.use(level, p, null).getObject(); } diff --git a/src/main/java/appeng/integration/modules/waila/tile/CableBusDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/CableBusDataProvider.java index 5921d7b1802..7a9a682232b 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/CableBusDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/CableBusDataProvider.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import net.minecraft.ChatFormatting; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -46,7 +47,6 @@ import appeng.api.parts.IPartHost; import appeng.api.parts.PartItemStack; import appeng.api.parts.SelectedPart; -import appeng.api.util.AEPartLocation; import appeng.block.networking.CableBusBlock; import appeng.blockentity.networking.CableBusBlockEntity; import appeng.integration.modules.waila.part.ChannelDataProvider; @@ -54,6 +54,7 @@ import appeng.integration.modules.waila.part.IPartDataProvider; import appeng.integration.modules.waila.part.P2PStateDataProvider; import appeng.integration.modules.waila.part.StorageMonitorDataProvider; +import appeng.util.Platform; public final class CableBusDataProvider { @@ -162,7 +163,7 @@ public void appendServerData(CompoundTag serverData, ServerPlayer serverPlayer, } var partTag = new CompoundTag(); - for (var location : AEPartLocation.values()) { + for (var location : Platform.DIRECTIONS_WITH_NULL) { var part = cableBus.getPart(location); if (part == null) { continue; @@ -182,8 +183,8 @@ public void appendServerData(CompoundTag serverData, ServerPlayer serverPlayer, } } - private static String getPartDataName(AEPartLocation location) { - return "cableBusPart" + location.name(); + private static String getPartDataName(@Nullable Direction location) { + return "cableBusPart" + (location == null ? "center" : location.name()); } @FunctionalInterface diff --git a/src/main/java/appeng/items/parts/FacadeItem.java b/src/main/java/appeng/items/parts/FacadeItem.java index 7c7ceee98cc..7a7ddc603d1 100644 --- a/src/main/java/appeng/items/parts/FacadeItem.java +++ b/src/main/java/appeng/items/parts/FacadeItem.java @@ -21,6 +21,7 @@ import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; @@ -43,7 +44,6 @@ import appeng.api.AEApi; import appeng.api.ids.AETags; import appeng.api.parts.IAlphaPassItem; -import appeng.api.util.AEPartLocation; import appeng.core.AEConfig; import appeng.core.definitions.AEItems; import appeng.facade.FacadePart; @@ -126,7 +126,7 @@ public ItemStack createFacadeForItemUnchecked(final ItemStack itemStack) { } @Override - public FacadePart createPartFromItemStack(final ItemStack is, final AEPartLocation side) { + public FacadePart createPartFromItemStack(ItemStack is, Direction side) { final ItemStack in = this.getTextureItem(is); if (!in.isEmpty()) { return new FacadePart(is, side); diff --git a/src/main/java/appeng/me/cluster/MBCalculator.java b/src/main/java/appeng/me/cluster/MBCalculator.java index 20b45b3433a..935cfa16dac 100644 --- a/src/main/java/appeng/me/cluster/MBCalculator.java +++ b/src/main/java/appeng/me/cluster/MBCalculator.java @@ -22,11 +22,11 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import appeng.api.util.AEPartLocation; import appeng.core.AELog; public abstract class MBCalculator, TCluster extends IAECluster> { @@ -176,7 +176,7 @@ private boolean isValidBlockEntityAt(final Level level, final int x, final int y public abstract boolean checkMultiblockScale(BlockPos min, BlockPos max); private boolean verifyUnownedRegion(final ServerLevel level, final BlockPos min, final BlockPos max) { - for (final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction side : Direction.values()) { if (this.verifyUnownedRegionInner(level, min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ(), side)) { @@ -225,8 +225,7 @@ public void disconnect() { public abstract boolean isValidBlockEntity(BlockEntity te); private boolean verifyUnownedRegionInner(final ServerLevel level, int minX, int minY, int minZ, int maxX, int maxY, - int maxZ, - final AEPartLocation side) { + int maxZ, final Direction side) { switch (side) { case WEST: minX -= 1; @@ -252,7 +251,7 @@ private boolean verifyUnownedRegionInner(final ServerLevel level, int minX, int maxY += 1; minY = maxY; break; - case INTERNAL: + default: return false; } diff --git a/src/main/java/appeng/menu/MenuLocator.java b/src/main/java/appeng/menu/MenuLocator.java index 4267661cb90..ae25562be90 100644 --- a/src/main/java/appeng/menu/MenuLocator.java +++ b/src/main/java/appeng/menu/MenuLocator.java @@ -34,7 +34,6 @@ import net.minecraft.world.level.block.entity.BlockEntity; import appeng.api.parts.IPartHost; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; import appeng.parts.AEBasePart; @@ -67,14 +66,14 @@ private enum Type { private final int itemIndex; private final ResourceLocation worldId; private final BlockPos blockPos; - private final AEPartLocation side; + private final Direction side; - private MenuLocator(Type type, int itemIndex, Level level, BlockPos blockPos, AEPartLocation side) { + private MenuLocator(Type type, int itemIndex, Level level, BlockPos blockPos, Direction side) { this(type, itemIndex, level.dimension().location(), blockPos, side); } private MenuLocator(Type type, int itemIndex, ResourceLocation worldId, BlockPos blockPos, - AEPartLocation side) { + Direction side) { this.type = type; this.itemIndex = itemIndex; this.worldId = worldId; @@ -93,7 +92,7 @@ public static MenuLocator forBlockEntitySide(BlockEntity te, Direction side) { if (te.getLevel() == null) { throw new IllegalArgumentException("Cannot open a block entity that is not in a level"); } - return new MenuLocator(Type.PART, -1, te.getLevel(), te.getBlockPos(), AEPartLocation.fromFacing(side)); + return new MenuLocator(Type.PART, -1, te.getLevel(), te.getBlockPos(), side); } /** @@ -106,7 +105,7 @@ public static MenuLocator forItemUseContext(UseOnContext context) { throw new IllegalArgumentException("Cannot open a menu without a player"); } int slot = getPlayerInventorySlotFromHand(player, context.getHand()); - AEPartLocation side = AEPartLocation.fromFacing(context.getClickedFace()); + Direction side = context.getClickedFace(); return new MenuLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, player.level, context.getClickedPos(), side); @@ -167,7 +166,7 @@ public boolean hasSide() { return type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT; } - public AEPartLocation getSide() { + public Direction getSide() { Preconditions.checkState(hasSide()); return side; } @@ -205,10 +204,10 @@ public static MenuLocator read(FriendlyByteBuf buf) { return switch (type) { case 0 -> new MenuLocator(Type.PLAYER_INVENTORY, buf.readInt(), (ResourceLocation) null, null, null); case 1 -> new MenuLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, buf.readInt(), - buf.readResourceLocation(), buf.readBlockPos(), AEPartLocation.values()[buf.readByte()]); + buf.readResourceLocation(), buf.readBlockPos(), Direction.values()[buf.readByte()]); case 2 -> new MenuLocator(Type.BLOCK, -1, buf.readResourceLocation(), buf.readBlockPos(), null); case 3 -> new MenuLocator(Type.PART, -1, buf.readResourceLocation(), buf.readBlockPos(), - AEPartLocation.values()[buf.readByte()]); + Direction.values()[buf.readByte()]); default -> throw new DecoderException("ContainerLocator type out of range: " + type); }; } diff --git a/src/main/java/appeng/parts/AEBasePart.java b/src/main/java/appeng/parts/AEBasePart.java index 6727fbca530..904793db369 100644 --- a/src/main/java/appeng/parts/AEBasePart.java +++ b/src/main/java/appeng/parts/AEBasePart.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Random; +import javax.annotation.Nullable; + import com.google.common.base.Preconditions; import net.minecraft.CrashReportCategory; @@ -61,7 +63,6 @@ import appeng.api.parts.PartItemStack; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.blockentity.inventory.AppEngInternalAEInventory; import appeng.core.definitions.AEBlocks; @@ -82,7 +83,8 @@ public abstract class AEBasePart implements IPart, IActionHost, IUpgradeableHost private final ItemStack is; private BlockEntity blockEntity = null; private IPartHost host = null; - private AEPartLocation side = null; + @Nullable + private Direction side; public AEBasePart(final ItemStack is) { Preconditions.checkNotNull(is); @@ -241,7 +243,7 @@ public void addToWorld() { } @Override - public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity blockEntity) { + public void setPartHostInfo(final Direction side, final IPartHost host, final BlockEntity blockEntity) { this.setSide(side); this.blockEntity = blockEntity; this.host = host; @@ -435,7 +437,7 @@ public boolean onPartShiftActivate(final Player player, final InteractionHand ha @Override public void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { this.mainNode.setOwningPlayer(player); } @@ -449,11 +451,11 @@ public boolean requireDynamicRender() { return false; } - public AEPartLocation getSide() { + public Direction getSide() { return this.side; } - private void setSide(final AEPartLocation side) { + private void setSide(final Direction side) { this.side = side; } diff --git a/src/main/java/appeng/parts/BusCollisionHelper.java b/src/main/java/appeng/parts/BusCollisionHelper.java index 49b0bdf0424..fae1d14ab8e 100644 --- a/src/main/java/appeng/parts/BusCollisionHelper.java +++ b/src/main/java/appeng/parts/BusCollisionHelper.java @@ -24,7 +24,6 @@ import net.minecraft.world.phys.AABB; import appeng.api.parts.IPartCollisionHelper; -import appeng.api.util.AEPartLocation; public class BusCollisionHelper implements IPartCollisionHelper { @@ -45,47 +44,54 @@ public BusCollisionHelper(final List boxes, final Direction x, final Direc this.isVisual = visual; } - public BusCollisionHelper(final List boxes, final AEPartLocation s, final boolean visual) { + public BusCollisionHelper(final List boxes, final Direction s, final boolean visual) { this.boxes = boxes; this.isVisual = visual; - switch (s) { - case DOWN -> { - this.x = Direction.EAST; - this.y = Direction.NORTH; - this.z = Direction.DOWN; - } - case UP -> { - this.x = Direction.EAST; - this.y = Direction.SOUTH; - this.z = Direction.UP; - } - case EAST -> { - this.x = Direction.SOUTH; - this.y = Direction.UP; - this.z = Direction.EAST; - } - case WEST -> { - this.x = Direction.NORTH; - this.y = Direction.UP; - this.z = Direction.WEST; - } - case NORTH -> { - this.x = Direction.WEST; - this.y = Direction.UP; - this.z = Direction.NORTH; - } - case SOUTH -> { - this.x = Direction.EAST; - this.y = Direction.UP; - this.z = Direction.SOUTH; - } - default -> { - this.x = Direction.EAST; - this.y = Direction.UP; - this.z = Direction.SOUTH; + if (s == null) { + this.x = Direction.EAST; + this.y = Direction.UP; + this.z = Direction.SOUTH; + } else { + switch (s) { + case DOWN -> { + this.x = Direction.EAST; + this.y = Direction.NORTH; + this.z = Direction.DOWN; + } + case UP -> { + this.x = Direction.EAST; + this.y = Direction.SOUTH; + this.z = Direction.UP; + } + case EAST -> { + this.x = Direction.SOUTH; + this.y = Direction.UP; + this.z = Direction.EAST; + } + case WEST -> { + this.x = Direction.NORTH; + this.y = Direction.UP; + this.z = Direction.WEST; + } + case NORTH -> { + this.x = Direction.WEST; + this.y = Direction.UP; + this.z = Direction.NORTH; + } + case SOUTH -> { + this.x = Direction.EAST; + this.y = Direction.UP; + this.z = Direction.SOUTH; + } + default -> { + this.x = Direction.EAST; + this.y = Direction.UP; + this.z = Direction.SOUTH; + } } } + } @Override diff --git a/src/main/java/appeng/parts/CableBusContainer.java b/src/main/java/appeng/parts/CableBusContainer.java index 23734e9f964..890fbc6f218 100644 --- a/src/main/java/appeng/parts/CableBusContainer.java +++ b/src/main/java/appeng/parts/CableBusContainer.java @@ -66,7 +66,6 @@ import appeng.api.parts.SelectedPart; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; import appeng.client.render.cablebus.CableBusRenderState; import appeng.client.render.cablebus.CableCoreType; @@ -80,10 +79,11 @@ import appeng.util.InteractionUtil; import appeng.util.Platform; -public class CableBusContainer extends CableBusStorage implements AEMultiBlockEntity, ICableBusContainer { +public class CableBusContainer implements AEMultiBlockEntity, ICableBusContainer { private static final ThreadLocal IS_LOADING = new ThreadLocal<>(); private final EnumSet myLayerFlags = EnumSet.noneOf(LayerFlags.class); + private final CableBusStorage storage = new CableBusStorage(); private YesNo hasRedstone = YesNo.UNDECIDED; private IPartHost tcb; private boolean requiresDynamicRender = false; @@ -108,31 +108,13 @@ public void setHost(final IPartHost host) { this.tcb = host; } - public void rotateLeft() { - final IPart[] newSides = new IPart[6]; - - newSides[AEPartLocation.UP.ordinal()] = this.getSide(AEPartLocation.UP); - newSides[AEPartLocation.DOWN.ordinal()] = this.getSide(AEPartLocation.DOWN); - - newSides[AEPartLocation.EAST.ordinal()] = this.getSide(AEPartLocation.NORTH); - newSides[AEPartLocation.SOUTH.ordinal()] = this.getSide(AEPartLocation.EAST); - newSides[AEPartLocation.WEST.ordinal()] = this.getSide(AEPartLocation.SOUTH); - newSides[AEPartLocation.NORTH.ordinal()] = this.getSide(AEPartLocation.WEST); - - for (final AEPartLocation dir : AEPartLocation.SIDE_LOCATIONS) { - this.setSide(dir, newSides[dir.ordinal()]); - } - - this.getFacadeContainer().rotateLeft(); - } - @Override public IFacadeContainer getFacadeContainer() { - return new FacadeContainer(this, this::invalidateShapes); + return new FacadeContainer(this.storage, this::invalidateShapes); } @Override - public boolean canAddPart(ItemStack is, final AEPartLocation side) { + public boolean canAddPart(ItemStack is, final Direction side) { if (PartPlacement.isFacade(is, side) != null) { return true; } @@ -146,7 +128,7 @@ public boolean canAddPart(ItemStack is, final AEPartLocation side) { if (bp != null) { if (bp instanceof ICablePart) { boolean canPlace = true; - for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction d : Direction.values()) { if (this.getPart(d) != null && !this.getPart(d).canBePlacedOn(((ICablePart) bp).supportsBuses())) { canPlace = false; @@ -157,9 +139,9 @@ public boolean canAddPart(ItemStack is, final AEPartLocation side) { return false; } - return this.getPart(AEPartLocation.INTERNAL) == null; - } else if (!(bp instanceof ICablePart) && side != AEPartLocation.INTERNAL) { - final IPart cable = this.getPart(AEPartLocation.INTERNAL); + return this.getPart(null) == null; + } else if (!(bp instanceof ICablePart) && side != null) { + final IPart cable = this.getPart(null); if (cable != null && !bp.canBePlacedOn(((ICablePart) cable).supportsBuses())) { return false; } @@ -172,7 +154,7 @@ public boolean canAddPart(ItemStack is, final AEPartLocation side) { } @Override - public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nullable Player player, + public boolean addPart(ItemStack is, final Direction side, final @Nullable Player player, final @Nullable InteractionHand hand) { if (this.canAddPart(is, side) && is.getItem() instanceof IPartItembi) { @@ -182,7 +164,7 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu final IPart bp = bi.createPart(is); if (bp instanceof ICablePart) { boolean canPlace = true; - for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction d : Direction.values()) { if (this.getPart(d) != null && !this.getPart(d).canBePlacedOn(((ICablePart) bp).supportsBuses())) { canPlace = false; @@ -190,15 +172,15 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu } if (!canPlace) { - return null; + return false; } - if (this.getPart(AEPartLocation.INTERNAL) != null) { - return null; + if (this.getPart(null) != null) { + return false; } - this.setCenter((ICablePart) bp); - bp.setPartHostInfo(AEPartLocation.INTERNAL, this, this.tcb.getBlockEntity()); + this.storage.setCenter((ICablePart) bp); + bp.setPartHostInfo(null, this, this.tcb.getBlockEntity()); if (player != null) { bp.onPlacement(player, hand, is, side); @@ -208,9 +190,9 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu bp.addToWorld(); } - final IGridNode cn = this.getCenter().getGridNode(); + final IGridNode cn = this.storage.getCenter().getGridNode(); if (cn != null) { - for (final AEPartLocation ins : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction ins : Direction.values()) { final IPart sbp = this.getPart(ins); if (sbp != null) { final IGridNode sn = sbp.getGridNode(); @@ -221,8 +203,8 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu AELog.debug(e); bp.removeFromWorld(); - this.setCenter(null); - return null; + this.storage.setCenter(null); + return false; } } } @@ -234,14 +216,14 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu this.markForUpdate(); this.markForSave(); this.partChanged(); - return AEPartLocation.INTERNAL; - } else if (bp != null && !(bp instanceof ICablePart) && side != AEPartLocation.INTERNAL) { - final IPart cable = this.getPart(AEPartLocation.INTERNAL); + return true; + } else if (bp != null && !(bp instanceof ICablePart) && side != null) { + final IPart cable = this.getPart(null); if (cable != null && !bp.canBePlacedOn(((ICablePart) cable).supportsBuses())) { - return null; + return false; } - this.setSide(side, bp); + this.storage.setPart(side, bp); bp.setPartHostInfo(side, this, this.getBlockEntity()); if (player != null) { @@ -252,8 +234,8 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu bp.addToWorld(); } - if (this.getCenter() != null) { - final IGridNode cn = this.getCenter().getGridNode(); + if (this.storage.getCenter() != null) { + final IGridNode cn = this.storage.getCenter().getGridNode(); final IGridNode sn = bp.getGridNode(); if (cn != null && sn != null) { @@ -263,8 +245,8 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu AELog.debug(e); bp.removeFromWorld(); - this.setSide(side, null); - return null; + this.storage.removePart(side); + return false; } } } @@ -275,37 +257,32 @@ public AEPartLocation addPart(ItemStack is, final AEPartLocation side, final @Nu this.markForUpdate(); this.markForSave(); this.partChanged(); - return side; + return true; } } - return null; + return false; } @Override - public IPart getPart(final AEPartLocation partLocation) { - if (partLocation == AEPartLocation.INTERNAL) { - return this.getCenter(); + public IPart getPart(final Direction partLocation) { + if (partLocation == null) { + return this.storage.getCenter(); } - return this.getSide(partLocation); - } - - @Override - public IPart getPart(final Direction side) { - return this.getSide(AEPartLocation.fromFacing(side)); + return this.storage.getPart(partLocation); } @Override - public void removePart(final AEPartLocation side, final boolean suppressUpdate) { - if (side == AEPartLocation.INTERNAL) { - if (this.getCenter() != null) { - this.getCenter().removeFromWorld(); + public void removePart(@Nullable Direction side, final boolean suppressUpdate) { + if (side == null) { + if (this.storage.getCenter() != null) { + this.storage.getCenter().removeFromWorld(); } - this.setCenter(null); + this.storage.setCenter(null); } else { - if (this.getSide(side) != null) { - this.getSide(side).removeFromWorld(); + if (this.getPart(side) != null) { + this.getPart(side).removeFromWorld(); } - this.setSide(side, null); + this.storage.removePart(side); } if (!suppressUpdate) { @@ -341,8 +318,8 @@ public BlockEntity getBlockEntity() { @Override public AEColor getColor() { - if (this.getCenter() != null) { - final ICablePart c = this.getCenter(); + if (this.storage.getCenter() != null) { + final ICablePart c = this.storage.getCenter(); return c.getCableColor(); } return AEColor.TRANSPARENT; @@ -360,7 +337,7 @@ public boolean isBlocked(final Direction side) { @Override public SelectedPart selectPart(final Vec3 pos) { - for (final AEPartLocation side : AEPartLocation.values()) { + for (final Direction side : Platform.DIRECTIONS_WITH_NULL) { final IPart p = this.getPart(side); if (p != null) { final List boxes = new ArrayList<>(); @@ -378,7 +355,7 @@ public SelectedPart selectPart(final Vec3 pos) { if (AEApi.partHelper().getCableRenderMode().opaqueFacades) { final IFacadeContainer fc = this.getFacadeContainer(); - for (final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction side : Direction.values()) { final IFacadePart p = fc.getFacade(side); if (p != null) { final List boxes = new ArrayList<>(); @@ -405,11 +382,11 @@ public void markForSave() { @Override public void partChanged() { - if (this.getCenter() == null) { + if (this.storage.getCenter() == null) { final List facades = new ArrayList<>(); final IFacadeContainer fc = this.getFacadeContainer(); - for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction d : Direction.values()) { final IFacadePart fp = fc.getFacade(d); if (fp != null) { facades.add(fp.getItemStack()); @@ -438,7 +415,7 @@ public void partChanged() { } @Override - public boolean hasRedstone(final AEPartLocation side) { + public boolean hasRedstone(final Direction side) { if (this.hasRedstone == YesNo.UNDECIDED) { this.updateRedstone(); } @@ -449,13 +426,13 @@ public boolean hasRedstone(final AEPartLocation side) { @Override public boolean isEmpty() { final IFacadeContainer fc = this.getFacadeContainer(); - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { return false; } - if (s != AEPartLocation.INTERNAL) { + if (s != null) { final IFacadePart fp = fc.getFacade(s); if (fp != null) { return false; @@ -492,7 +469,7 @@ private void updateRedstone() { private void updateDynamicRender() { this.requiresDynamicRender = false; - for (final AEPartLocation s : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction s : Direction.values()) { final IPart p = this.getPart(s); if (p != null) { this.setRequiresDynamicRender(this.isRequiresDynamicRender() || p.requireDynamicRender()); @@ -501,7 +478,7 @@ private void updateDynamicRender() { } public void updateConnections() { - if (this.getCenter() != null) { + if (this.storage.getCenter() != null) { var sides = EnumSet.allOf(Direction.class); for (final Direction s : Direction.values()) { @@ -510,7 +487,7 @@ public void updateConnections() { } } - this.getCenter().setExposedOnSides(sides); + this.storage.getCenter().setExposedOnSides(sides); } } @@ -526,21 +503,21 @@ public void addToWorld() { // start with the center, then install the side parts into the grid. for (int x = 6; x >= 0; x--) { - final AEPartLocation s = AEPartLocation.fromOrdinal(x); + final Direction s = Platform.DIRECTIONS_WITH_NULL[x]; final IPart part = this.getPart(s); if (part != null) { part.setPartHostInfo(s, this, te); part.addToWorld(); - if (s != AEPartLocation.INTERNAL) { + if (s != null) { final IGridNode sn = part.getGridNode(); if (sn != null) { // this is a really stupid if statement, why was this // here? // if ( !sn.getConnections().iterator().hasNext() ) - final IPart center = this.getPart(AEPartLocation.INTERNAL); + final IPart center = this.getPart(null); if (center != null) { final IGridNode cn = center.getGridNode(); if (cn != null) { @@ -569,7 +546,7 @@ public void removeFromWorld() { this.inWorld = false; - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { part.removeFromWorld(); @@ -590,8 +567,8 @@ public IGridNode getGridNode(final Direction side) { } } - if (this.getCenter() != null) { - return this.getCenter().getGridNode(); + if (this.storage.getCenter() != null) { + return this.storage.getCenter().getGridNode(); } return null; @@ -605,8 +582,8 @@ public AECableType getCableConnectionType(Direction dir) { return part.getExternalCableConnectionType(); } - if (this.getCenter() != null) { - final ICablePart c = this.getCenter(); + if (this.storage.getCenter() != null) { + final ICablePart c = this.storage.getCenter(); return c.getCableConnectionType(); } return AECableType.NONE; @@ -614,8 +591,8 @@ public AECableType getCableConnectionType(Direction dir) { @Override public float getCableConnectionLength(AECableType cable) { - return this.getPart(AEPartLocation.INTERNAL) instanceof ICablePart - ? this.getPart(AEPartLocation.INTERNAL).getCableConnectionLength(cable) + return this.getPart(null) instanceof ICablePart + ? this.getPart(null).getCableConnectionLength(cable) : -1; } @@ -639,7 +616,7 @@ public boolean canConnectRedstone(final Direction opposite) { @Override public void onEntityCollision(final Entity entity) { - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { part.onEntityCollision(entity); @@ -678,7 +655,7 @@ public boolean clicked(Player player, InteractionHand hand, Vec3 hitVec) { public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { this.hasRedstone = YesNo.UNDECIDED; - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { part.onNeighborChanged(level, pos, neighbor); @@ -691,7 +668,7 @@ public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor @Override public boolean isLadder(final LivingEntity entity) { - for (final AEPartLocation side : AEPartLocation.values()) { + for (final Direction side : Platform.DIRECTIONS_WITH_NULL) { final IPart p = this.getPart(side); if (p != null && p.isLadder(entity)) { return true; @@ -703,7 +680,7 @@ public boolean isLadder(final LivingEntity entity) { @Override public void animateTick(final Level level, final BlockPos pos, final Random r) { - for (final AEPartLocation side : AEPartLocation.values()) { + for (final Direction side : Platform.DIRECTIONS_WITH_NULL) { final IPart p = this.getPart(side); if (p != null) { p.animateTick(level, pos, r); @@ -715,7 +692,7 @@ public void animateTick(final Level level, final BlockPos pos, final Random r) { public int getLightValue() { int light = 0; - for (final AEPartLocation d : AEPartLocation.values()) { + for (final Direction d : Platform.DIRECTIONS_WITH_NULL) { final IPart p = this.getPart(d); if (p != null) { light = Math.max(p.getLightLevel(), light); @@ -728,7 +705,7 @@ public int getLightValue() { public void writeToStream(final FriendlyByteBuf data) throws IOException { int sides = 0; for (int x = 0; x < 7; x++) { - final IPart p = this.getPart(AEPartLocation.fromOrdinal(x)); + final IPart p = this.getPart(Platform.DIRECTIONS_WITH_NULL[x]); if (p != null) { sides |= 1 << x; } @@ -737,7 +714,7 @@ public void writeToStream(final FriendlyByteBuf data) throws IOException { data.writeByte((byte) sides); for (int x = 0; x < 7; x++) { - final IPart p = this.getPart(AEPartLocation.fromOrdinal(x)); + final IPart p = this.getPart(Platform.DIRECTIONS_WITH_NULL[x]); if (p != null) { final ItemStack is = p.getItemStack(PartItemStack.NETWORK); @@ -755,8 +732,8 @@ public boolean readFromStream(final FriendlyByteBuf data) throws IOException { boolean updateBlock = false; - for (int x = 0; x < 7; x++) { - AEPartLocation side = AEPartLocation.fromOrdinal(x); + for (int x = 0; x <= Direction.values().length; x++) { + Direction side = Platform.DIRECTIONS_WITH_NULL[x]; if ((sides & 1 << x) == 1 << x) { IPart p = this.getPart(side); @@ -771,8 +748,8 @@ public boolean readFromStream(final FriendlyByteBuf data) throws IOException { } } else { this.removePart(side, false); - side = this.addPart(new ItemStack(myItem, 1), side, null, null); - if (side != null) { + var partAdded = this.addPart(new ItemStack(myItem, 1), side, null, null); + if (partAdded) { p = this.getPart(side); p.readFromStream(data); } else { @@ -796,7 +773,7 @@ public void writeToNBT(final CompoundTag data) { data.putInt("hasRedstone", this.hasRedstone.ordinal()); final IFacadeContainer fc = this.getFacadeContainer(); - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { fc.writeToNBT(data); final IPart part = this.getPart(s); @@ -807,18 +784,21 @@ public void writeToNBT(final CompoundTag data) { final CompoundTag extra = new CompoundTag(); part.writeToNBT(extra); - data.put("def:" + this.getSide(part).ordinal(), def); - data.put("extra:" + this.getSide(part).ordinal(), extra); + var side = this.getSide(part); + var id = side == null ? "center" : side.name(); + + data.put("def:" + id, def); + data.put("extra:" + id, extra); } } } - private AEPartLocation getSide(final IPart part) { - if (this.getCenter() == part) { - return AEPartLocation.INTERNAL; + private Direction getSide(final IPart part) { + if (this.storage.getCenter() == part) { + return null; } else { - for (final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS) { - if (this.getSide(side) == part) { + for (final Direction side : Direction.values()) { + if (this.getPart(side) == part) { return side; } } @@ -834,11 +814,11 @@ public void readFromNBT(final CompoundTag data) { this.hasRedstone = YesNo.values()[data.getInt("hasRedstone")]; } - for (int x = 0; x < 7; x++) { - AEPartLocation side = AEPartLocation.fromOrdinal(x); + for (var side : Platform.DIRECTIONS_WITH_NULL) { + var id = side == null ? "center" : side.name(); - String defKey = "def:" + side.ordinal(); - String extraKey = "extra:" + side.ordinal(); + String defKey = "def:" + id; + String extraKey = "extra:" + id; if (data.contains(defKey, Tag.TAG_COMPOUND) && data.contains(extraKey, Tag.TAG_COMPOUND)) { final CompoundTag def = data.getCompound(defKey); @@ -855,8 +835,8 @@ public void readFromNBT(final CompoundTag data) { p.readFromNBT(extra); } else { this.removePart(side, true); - side = this.addPart(iss, side, null, null); - if (side != null) { + var partAdded = this.addPart(iss, side, null, null); + if (partAdded) { p = this.getPart(side); p.readFromNBT(extra); } else { @@ -873,14 +853,14 @@ public void readFromNBT(final CompoundTag data) { } public List getDrops(final List drops) { - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { drops.add(part.getItemStack(PartItemStack.BREAK)); part.getDrops(drops, false); } - if (s != AEPartLocation.INTERNAL) { + if (s != null) { final IFacadePart fp = this.getFacadeContainer().getFacade(s); if (fp != null) { drops.add(fp.getItemStack()); @@ -892,7 +872,7 @@ public List getDrops(final List drops) { } public List getNoDrops(final List drops) { - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPart part = this.getPart(s); if (part != null) { part.getDrops(drops, false); @@ -904,7 +884,7 @@ public List getNoDrops(final List drops) { @Override public boolean recolourBlock(final Direction side, final AEColor colour, final Player who) { - final IPart cable = this.getPart(AEPartLocation.INTERNAL); + final IPart cable = this.getPart(null); if (cable != null) { final ICablePart pc = (ICablePart) cable; return pc.changeColor(colour, who); @@ -922,7 +902,7 @@ private void setRequiresDynamicRender(final boolean requiresDynamicRender) { @Override public CableBusRenderState getRenderState() { - final CablePart cable = (CablePart) this.getCenter(); + final CablePart cable = (CablePart) this.storage.getCenter(); final CableBusRenderState renderState = new CableBusRenderState(); @@ -989,8 +969,7 @@ public CableBusRenderState getRenderState() { // This will add the part's bounding boxes to the render state, which is // required for facades - final AEPartLocation loc = AEPartLocation.fromFacing(facing); - final IPartCollisionHelper bch = new BusCollisionHelper(renderState.getBoundingBoxes(), loc, true); + final IPartCollisionHelper bch = new BusCollisionHelper(renderState.getBoundingBoxes(), facing, true); part.getBoxes(bch); // Some attachments want a thicker cable than glass, account for that @@ -1013,7 +992,7 @@ public CableBusRenderState getRenderState() { private FacadeRenderState getFacadeRenderState(Direction side) { // Store the "masqueraded" itemstack for the given side, if there is a facade - final IFacadePart facade = this.getFacade(side.ordinal()); + final IFacadePart facade = this.storage.getFacade(side); if (facade != null) { final ItemStack textureItem = facade.getTextureItem(); @@ -1065,7 +1044,7 @@ private VoxelShape createShape(boolean forCollision, boolean forItemEntity) { final List boxes = new ArrayList<>(); final IFacadeContainer fc = this.getFacadeContainer(); - for (final AEPartLocation s : AEPartLocation.values()) { + for (final Direction s : Platform.DIRECTIONS_WITH_NULL) { final IPartCollisionHelper bch = new BusCollisionHelper(boxes, s, !forCollision); final IPart part = this.getPart(s); @@ -1074,7 +1053,7 @@ private VoxelShape createShape(boolean forCollision, boolean forItemEntity) { } if ((AEApi.partHelper().getCableRenderMode().opaqueFacades || forCollision) - && s != AEPartLocation.INTERNAL) { + && s != null) { final IFacadePart fp = fc.getFacade(s); if (fp != null) { fp.getBoxes(bch, forItemEntity); diff --git a/src/main/java/appeng/parts/CableBusStorage.java b/src/main/java/appeng/parts/CableBusStorage.java index b430c118e4c..2d5442a7041 100644 --- a/src/main/java/appeng/parts/CableBusStorage.java +++ b/src/main/java/appeng/parts/CableBusStorage.java @@ -18,20 +18,25 @@ package appeng.parts; +import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.core.Direction; + import appeng.api.implementations.parts.ICablePart; import appeng.api.parts.IFacadePart; import appeng.api.parts.IPart; -import appeng.api.util.AEPartLocation; /** * Thin data storage to optimize memory usage for cables. */ public class CableBusStorage { + @Nullable private ICablePart center; - private IPart[] sides; + @Nullable + private IPart[] parts; + @Nullable private IFacadePart[] facades; protected ICablePart getCenter() { @@ -42,80 +47,84 @@ protected void setCenter(final ICablePart center) { this.center = center; } - protected IPart getSide(final AEPartLocation side) { - final int x = side.ordinal(); - if (this.sides != null && this.sides.length > x) { - return this.sides[x]; + protected IPart getPart(@Nonnull Direction side) { + if (this.parts == null) { + return null; } - return null; + var index = side.ordinal(); + return this.parts[index]; } - protected void setSide(final AEPartLocation side, final IPart part) { - final int x = side.ordinal(); - - if (this.sides != null && this.sides.length > x && part == null) { - this.sides[x] = null; - this.sides = this.shrink(this.sides, true); - } else if (part != null) { - this.sides = this.grow(this.sides, x, true); - this.sides[x] = part; + protected void setPart(@Nonnull Direction side, final IPart part) { + if (this.parts == null) { + this.parts = new IPart[Direction.values().length]; } + + var index = side.ordinal(); + this.parts[index] = part; } - private T[] shrink(final T[] in, final boolean parts) { - int newSize = -1; - for (int x = 0; x < in.length; x++) { - if (in[x] != null) { - newSize = x; - } + protected void removePart(@Nonnull Direction side) { + if (this.parts == null) { + return; } - if (newSize == -1) { - return null; - } + var index = side.ordinal(); + this.parts[index] = null; - newSize++; - if (newSize == in.length) { - return in; + if (isNullArray(this.parts)) { + this.parts = null; } + } - final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]); - System.arraycopy(in, 0, newArray, 0, newSize); + public IFacadePart getFacade(@Nonnull Direction side) { + if (this.facades == null) { + return null; + } - return newArray; + var index = side.ordinal(); + return this.facades[index]; } - private T[] grow(final T[] in, final int newValue, final boolean parts) { - if (in != null && in.length > newValue) { - return in; + public void setFacade(@Nonnull Direction side, @Nullable final IFacadePart facade) { + if (facade == null) { + removeFacade(side); + return; } - final int newSize = newValue + 1; - - final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]); - if (in != null) { - System.arraycopy(in, 0, newArray, 0, in.length); + if (facades == null) { + this.facades = new IFacadePart[Direction.values().length]; } - return newArray; + var index = side.ordinal(); + this.facades[index] = facade; } - public IFacadePart getFacade(final int x) { - if (this.facades != null && this.facades.length > x) { - return this.facades[x]; + public void removeFacade(@Nonnull Direction side) { + if (this.facades == null) { + return; } - return null; + var index = side.ordinal(); + this.facades[index] = null; + + if (isNullArray(this.facades)) { + this.facades = null; + } } - public void setFacade(final int x, @Nullable final IFacadePart facade) { - if (this.facades != null && this.facades.length > x && facade == null) { - this.facades[x] = null; - this.facades = this.shrink(this.facades, false); - } else { - this.facades = this.grow(this.facades, x, false); - this.facades[x] = facade; + private static boolean isNullArray(T[] array) { + if (array == null) { + return true; } + + for (var o : array) { + if (o != null) { + return false; + } + } + + return true; } } diff --git a/src/main/java/appeng/parts/PartPlacement.java b/src/main/java/appeng/parts/PartPlacement.java index f9e8e47a987..40eb5dca7d9 100644 --- a/src/main/java/appeng/parts/PartPlacement.java +++ b/src/main/java/appeng/parts/PartPlacement.java @@ -55,7 +55,6 @@ import appeng.api.parts.IPartItem; import appeng.api.parts.PartItemStack; import appeng.api.parts.SelectedPart; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; import appeng.core.AppEng; import appeng.core.definitions.AEBlocks; @@ -146,15 +145,15 @@ public static InteractionResult place(final ItemStack held, final BlockPos pos, } if (!held.isEmpty()) { - final IFacadePart fp = isFacade(held, AEPartLocation.fromFacing(side)); + final IFacadePart fp = isFacade(held, side); if (fp != null) { if (host != null) { if (!level.isClientSide) { - if (host.getPart(AEPartLocation.INTERNAL) == null) { + if (host.getPart(null) == null) { return InteractionResult.FAIL; } - if (host.canAddPart(held, AEPartLocation.fromFacing(side)) + if (host.canAddPart(held, side) && host.getFacadeContainer().addFacade(fp)) { host.markForSave(); host.markForUpdate(); @@ -252,7 +251,7 @@ public static InteractionResult place(final ItemStack held, final BlockPos pos, .sendToServer(new PartPlacementPacket(pos, side, getEyeOffset(player), hand)); return InteractionResult.sidedSuccess(level.isClientSide()); } - } else if (host != null && !host.canAddPart(held, AEPartLocation.fromFacing(side))) { + } else if (host != null && !host.canAddPart(held, side)) { return InteractionResult.FAIL; } } @@ -261,7 +260,7 @@ public static InteractionResult place(final ItemStack held, final BlockPos pos, return InteractionResult.PASS; } - if (!host.canAddPart(held, AEPartLocation.fromFacing(side))) { + if (!host.canAddPart(held, side)) { if (pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM) { te_pos = pos.relative(side); @@ -295,8 +294,8 @@ public static InteractionResult place(final ItemStack held, final BlockPos pos, return InteractionResult.FAIL; } - final AEPartLocation mySide = host.addPart(held, AEPartLocation.fromFacing(side), player, hand); - if (mySide != null) { + final var partAdded = host.addPart(held, side, player, hand); + if (partAdded) { BlockState blockState = level.getBlockState(pos); final SoundType ss = multiPart.block().getSoundType(blockState, level, pos, player); @@ -334,7 +333,7 @@ private static SelectedPart selectPart(final Player player, final IPartHost host } } - public static IFacadePart isFacade(final ItemStack held, final AEPartLocation side) { + public static IFacadePart isFacade(final ItemStack held, final Direction side) { if (held.getItem() instanceof IFacadeItem) { return ((IFacadeItem) held.getItem()).createPartFromItemStack(held, side); } diff --git a/src/main/java/appeng/parts/automation/AbstractFormationPlanePart.java b/src/main/java/appeng/parts/automation/AbstractFormationPlanePart.java index 78b77043e85..232e04a4175 100644 --- a/src/main/java/appeng/parts/automation/AbstractFormationPlanePart.java +++ b/src/main/java/appeng/parts/automation/AbstractFormationPlanePart.java @@ -19,6 +19,7 @@ package appeng.parts.automation; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; @@ -34,7 +35,6 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.helpers.IPriorityHost; @@ -94,11 +94,11 @@ public PlaneConnections getConnections() { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (pos.relative(this.getSide()).equals(neighbor)) { final BlockEntity te = this.getHost().getBlockEntity(); - final AEPartLocation side = this.getSide(); + final Direction side = this.getSide(); - final BlockPos tePos = te.getBlockPos().relative(side.getDirection()); + final BlockPos tePos = te.getBlockPos().relative(side); this.blocked = !level.getBlockState(tePos).getMaterial().isReplaceable(); } else { diff --git a/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java b/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java index ec687d5425b..1343752df52 100644 --- a/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java +++ b/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java @@ -126,7 +126,7 @@ public PlaneConnections getConnections() { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (pos.relative(this.getSide()).equals(neighbor)) { this.refresh(); } else { connectionHelper.updateConnections(); @@ -276,7 +276,7 @@ private TickRateModulation breakBlock(final boolean modulate) { final BlockEntity te = this.getBlockEntity(); final ServerLevel level = (ServerLevel) te.getLevel(); - final BlockPos pos = te.getBlockPos().relative(this.getSide().getDirection()); + final BlockPos pos = te.getBlockPos().relative(this.getSide()); final IEnergyService energy = grid.getEnergyService(); final BlockState blockState = level.getBlockState(pos); diff --git a/src/main/java/appeng/parts/automation/FluidAnnihilationPlanePart.java b/src/main/java/appeng/parts/automation/FluidAnnihilationPlanePart.java index 6c5c89da5b8..cc6e1730b2e 100644 --- a/src/main/java/appeng/parts/automation/FluidAnnihilationPlanePart.java +++ b/src/main/java/appeng/parts/automation/FluidAnnihilationPlanePart.java @@ -98,7 +98,7 @@ public PlaneConnections getConnections() { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (pos.relative(this.getSide()).equals(neighbor)) { this.refresh(); } else { connectionHelper.updateConnections(); @@ -127,7 +127,7 @@ private TickRateModulation pickupFluid(IGrid grid) { final BlockEntity te = this.getBlockEntity(); final Level level = te.getLevel(); - final BlockPos pos = te.getBlockPos().relative(this.getSide().getDirection()); + final BlockPos pos = te.getBlockPos().relative(this.getSide()); BlockState blockstate = level.getBlockState(pos); if (blockstate.getBlock() instanceof BucketPickup) { diff --git a/src/main/java/appeng/parts/automation/FluidExportBusPart.java b/src/main/java/appeng/parts/automation/FluidExportBusPart.java index 8205300d0df..c83e8dfbb3c 100644 --- a/src/main/java/appeng/parts/automation/FluidExportBusPart.java +++ b/src/main/java/appeng/parts/automation/FluidExportBusPart.java @@ -99,7 +99,7 @@ protected TickRateModulation doBusWork() { LazyOptional fhOpt = LazyOptional.empty(); if (te != null) { fhOpt = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, - this.getSide().getDirection().getOpposite()); + this.getSide().getOpposite()); } if (fhOpt.isPresent()) { var grid = getMainNode().getGrid(); diff --git a/src/main/java/appeng/parts/automation/FluidFormationPlanePart.java b/src/main/java/appeng/parts/automation/FluidFormationPlanePart.java index 47fcf5d6e2c..75c0470d71f 100644 --- a/src/main/java/appeng/parts/automation/FluidFormationPlanePart.java +++ b/src/main/java/appeng/parts/automation/FluidFormationPlanePart.java @@ -25,6 +25,7 @@ import javax.annotation.Nonnull; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; @@ -56,7 +57,6 @@ import appeng.api.storage.StorageChannels; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IItemList; -import appeng.api.util.AEPartLocation; import appeng.core.definitions.AEParts; import appeng.helpers.IConfigurableFluidInventory; import appeng.items.parts.PartModels; @@ -118,8 +118,8 @@ public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSo final BlockEntity te = this.getHost().getBlockEntity(); final Level level = te.getLevel(); - final AEPartLocation side = this.getSide(); - final BlockPos pos = te.getBlockPos().relative(side.getDirection()); + final Direction side = this.getSide(); + final BlockPos pos = te.getBlockPos().relative(side); final BlockState state = level.getBlockState(pos); if (this.canReplace(level, state, pos)) { diff --git a/src/main/java/appeng/parts/automation/FluidImportBusPart.java b/src/main/java/appeng/parts/automation/FluidImportBusPart.java index cb004ed9136..bf8bde1770b 100644 --- a/src/main/java/appeng/parts/automation/FluidImportBusPart.java +++ b/src/main/java/appeng/parts/automation/FluidImportBusPart.java @@ -99,7 +99,7 @@ protected TickRateModulation doBusWork() { final BlockEntity te = this.getConnectedTE(); if (te != null) { LazyOptional fhOpt = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, - this.getSide().getDirection().getOpposite()); + this.getSide().getOpposite()); if (fhOpt.isPresent()) { var grid = getMainNode().getGrid(); diff --git a/src/main/java/appeng/parts/automation/FluidLevelEmitterPart.java b/src/main/java/appeng/parts/automation/FluidLevelEmitterPart.java index 59b8437037a..259478b0dbe 100644 --- a/src/main/java/appeng/parts/automation/FluidLevelEmitterPart.java +++ b/src/main/java/appeng/parts/automation/FluidLevelEmitterPart.java @@ -21,6 +21,7 @@ import java.util.Random; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.particles.DustParticleOptions; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -50,7 +51,6 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.core.AppEng; import appeng.helpers.IConfigurableFluidInventory; @@ -189,7 +189,7 @@ private void updateState() { final BlockEntity te = this.getHost().getBlockEntity(); this.prevState = isOn; Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos()); - Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos().relative(this.getSide().getDirection())); + Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos().relative(this.getSide())); } } @@ -270,11 +270,11 @@ public void getBoxes(final IPartCollisionHelper bch) { @Override public void animateTick(final Level level, final BlockPos pos, final Random r) { if (this.isLevelEmitterOn()) { - final AEPartLocation d = this.getSide(); + final Direction d = this.getSide(); - final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d0 = d.getStepX() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d1 = d.getStepY() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d2 = d.getStepZ() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; level.addParticle(DustParticleOptions.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D); diff --git a/src/main/java/appeng/parts/automation/FormationPlanePart.java b/src/main/java/appeng/parts/automation/FormationPlanePart.java index 76c4c8d2567..5a397f0f0b7 100644 --- a/src/main/java/appeng/parts/automation/FormationPlanePart.java +++ b/src/main/java/appeng/parts/automation/FormationPlanePart.java @@ -62,7 +62,6 @@ import appeng.api.storage.StorageChannels; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; -import appeng.api.util.AEPartLocation; import appeng.blockentity.inventory.AppEngInternalAEInventory; import appeng.core.AEConfig; import appeng.core.definitions.AEParts; @@ -193,9 +192,9 @@ public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final BlockEntity te = this.getHost().getBlockEntity(); final Level level = te.getLevel(); - final AEPartLocation side = this.getSide(); + final Direction side = this.getSide(); - final BlockPos placePos = te.getBlockPos().relative(side.getDirection()); + final BlockPos placePos = te.getBlockPos().relative(side); if (level.getBlockState(placePos).getMaterial().isReplaceable()) { if (placeBlock == YesNo.YES) { @@ -210,7 +209,7 @@ public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, if (type == Actionable.MODULATE) { // The side the plane is attached to will be considered the look direction // in terms of placing an item - Direction lookDirection = side.getDirection(); + Direction lookDirection = side; PlaneDirectionalPlaceContext context = new PlaneDirectionalPlaceContext(level, player, placePos, lookDirection, is, lookDirection.getOpposite()); @@ -256,7 +255,7 @@ public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, return input; } - private static boolean spawnItemEntity(Level level, BlockEntity te, AEPartLocation side, ItemStack is) { + private static boolean spawnItemEntity(Level level, BlockEntity te, Direction side, ItemStack is) { // The center of the block the plane is located in final double centerX = te.getBlockPos().getX() + .5; final double centerY = te.getBlockPos().getY(); @@ -280,7 +279,7 @@ private static boolean spawnItemEntity(Level level, BlockEntity te, AEPartLocati // When spawning downwards, we have to take into account that it spawns it at // their "feet" and not center like x or z. So we move it up to be flush with // the plane - final double additionalYOffset = side.yOffset == -1 ? 1 - entity.getBbHeight() : 0; + final double additionalYOffset = side.getStepY() == -1 ? 1 - entity.getBbHeight() : 0; // Calculate the maximum spawn area so an entity hitbox will always be inside // the block. @@ -292,15 +291,15 @@ private static boolean spawnItemEntity(Level level, BlockEntity te, AEPartLocati // Spawn it 0.8 blocks away from the center pos when facing in this direction // Every other direction will select a position in a .5 block area around the // block center. - final double offsetX = side.xOffset == 0 // + final double offsetX = side.getStepX() == 0 // ? RANDOM_OFFSET.nextFloat() * spawnAreaWidth - spawnAreaWidth / 2 - : side.xOffset * (.525 + entity.getBbWidth() / 2); - final double offsetY = side.yOffset == 0 // + : side.getStepX() * (.525 + entity.getBbWidth() / 2); + final double offsetY = side.getStepY() == 0 // ? RANDOM_OFFSET.nextFloat() * spawnAreaHeight - : side.yOffset + additionalYOffset; - final double offsetZ = side.zOffset == 0 // + : side.getStepY() + additionalYOffset; + final double offsetZ = side.getStepZ() == 0 // ? RANDOM_OFFSET.nextFloat() * spawnAreaWidth - spawnAreaWidth / 2 - : side.zOffset * (.525 + entity.getBbWidth() / 2); + : side.getStepZ() * (.525 + entity.getBbWidth() / 2); final double absoluteX = centerX + offsetX; final double absoluteY = centerY + offsetY; @@ -308,7 +307,7 @@ private static boolean spawnItemEntity(Level level, BlockEntity te, AEPartLocati // Set to correct position and slow the motion down a bit entity.setPos(absoluteX, absoluteY, absoluteZ); - entity.setDeltaMovement(side.xOffset * .1, side.yOffset * 0.1, side.zOffset * 0.1); + entity.setDeltaMovement(side.getStepX() * .1, side.getStepY() * 0.1, side.getStepZ() * 0.1); // Try to spawn it and destroy it in case it's not possible if (!level.addFreshEntity(entity)) { diff --git a/src/main/java/appeng/parts/automation/LevelEmitterPart.java b/src/main/java/appeng/parts/automation/LevelEmitterPart.java index 7b893ce96d4..1b89420e816 100644 --- a/src/main/java/appeng/parts/automation/LevelEmitterPart.java +++ b/src/main/java/appeng/parts/automation/LevelEmitterPart.java @@ -22,6 +22,7 @@ import java.util.Random; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.particles.DustParticleOptions; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -65,7 +66,6 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.blockentity.inventory.AppEngInternalAEInventory; import appeng.core.AppEng; @@ -159,7 +159,7 @@ private void updateState() { final BlockEntity te = this.getHost().getBlockEntity(); this.prevState = isOn; Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos()); - Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos().relative(this.getSide().getDirection())); + Platform.notifyBlocksOfNeighbors(te.getLevel(), te.getBlockPos().relative(this.getSide())); } } @@ -364,11 +364,11 @@ public int isProvidingWeakPower() { @Override public void animateTick(final Level level, final BlockPos pos, final Random r) { if (this.isLevelEmitterOn()) { - final AEPartLocation d = this.getSide(); + final Direction d = this.getSide(); - final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d0 = d.getStepX() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d1 = d.getStepY() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; + final double d2 = d.getStepZ() * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; level.addParticle(DustParticleOptions.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D); diff --git a/src/main/java/appeng/parts/automation/PlaneConnectionHelper.java b/src/main/java/appeng/parts/automation/PlaneConnectionHelper.java index dcfc02c5098..d1cad11ad8a 100644 --- a/src/main/java/appeng/parts/automation/PlaneConnectionHelper.java +++ b/src/main/java/appeng/parts/automation/PlaneConnectionHelper.java @@ -28,7 +28,6 @@ import appeng.api.parts.IPart; import appeng.api.parts.IPartCollisionHelper; import appeng.api.parts.IPartHost; -import appeng.api.util.AEPartLocation; import appeng.parts.AEBasePart; /** @@ -48,7 +47,7 @@ public PlaneConnectionHelper(AEBasePart part) { */ public PlaneConnections getConnections() { BlockEntity hostBlockEntity = getHostBlockEntity(); - AEPartLocation side = part.getSide(); + Direction side = part.getSide(); final Direction facingRight, facingUp; switch (side) { @@ -77,7 +76,6 @@ public PlaneConnections getConnections() { facingUp = Direction.UP; break; default: - case INTERNAL: return PlaneConnections.of(false, false, false, false); } diff --git a/src/main/java/appeng/parts/automation/SharedFluidBusPart.java b/src/main/java/appeng/parts/automation/SharedFluidBusPart.java index 82f3c6bd3b7..eb305ea8369 100644 --- a/src/main/java/appeng/parts/automation/SharedFluidBusPart.java +++ b/src/main/java/appeng/parts/automation/SharedFluidBusPart.java @@ -107,7 +107,7 @@ public void getBoxes(IPartCollisionHelper bch) { protected BlockEntity getConnectedTE() { BlockEntity self = this.getHost().getBlockEntity(); - return Platform.getTickingBlockEntity(getLevel(), self.getBlockPos().relative(this.getSide().getDirection())); + return Platform.getTickingBlockEntity(getLevel(), self.getBlockPos().relative(this.getSide())); } protected int calculateAmountToSend() { @@ -181,7 +181,7 @@ protected boolean canDoBusWork() { } var self = this.getHost().getBlockEntity(); - var targetPos = self.getBlockPos().relative(getSide().getDirection()); + var targetPos = self.getBlockPos().relative(getSide()); return Platform.areBlockEntitiesTicking(self.getLevel(), targetPos); } diff --git a/src/main/java/appeng/parts/automation/SharedItemBusPart.java b/src/main/java/appeng/parts/automation/SharedItemBusPart.java index 5ba350ad44c..b884abfd584 100644 --- a/src/main/java/appeng/parts/automation/SharedItemBusPart.java +++ b/src/main/java/appeng/parts/automation/SharedItemBusPart.java @@ -84,9 +84,9 @@ public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor protected InventoryAdaptor getHandler() { final BlockEntity self = this.getHost().getBlockEntity(); final BlockEntity target = Platform.getTickingBlockEntity(getLevel(), - self.getBlockPos().relative(this.getSide().getDirection())); + self.getBlockPos().relative(this.getSide())); - return InventoryAdaptor.getAdaptor(target, this.getSide().getDirection().getOpposite()); + return InventoryAdaptor.getAdaptor(target, this.getSide().getOpposite()); } protected int availableSlots() { @@ -122,7 +122,7 @@ protected boolean canDoBusWork() { } var self = this.getHost().getBlockEntity(); - var targetPos = self.getBlockPos().relative(getSide().getDirection()); + var targetPos = self.getBlockPos().relative(getSide()); return Platform.areBlockEntitiesTicking(self.getLevel(), targetPos); } diff --git a/src/main/java/appeng/parts/misc/AbstractStorageBusPart.java b/src/main/java/appeng/parts/misc/AbstractStorageBusPart.java index a65bbec4388..59c05722aab 100644 --- a/src/main/java/appeng/parts/misc/AbstractStorageBusPart.java +++ b/src/main/java/appeng/parts/misc/AbstractStorageBusPart.java @@ -49,7 +49,6 @@ import appeng.api.storage.cells.ICellProvider; import appeng.api.storage.data.IAEStack; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.blockentity.misc.ItemInterfaceBlockEntity; import appeng.capabilities.Capabilities; @@ -202,7 +201,7 @@ public final float getCableConnectionLength(AECableType cable) { @Override public final void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (pos.relative(this.getSide()).equals(neighbor)) { var te = level.getBlockEntity(neighbor); // In case the TE was destroyed, we have to do a full reset immediately. @@ -261,7 +260,7 @@ private void doCacheReset() { private IMEInventory getInventoryWrapper(BlockEntity target) { - var targetSide = this.getSide().getDirection().getOpposite(); + var targetSide = this.getSide().getOpposite(); // Prioritize a handler to directly link to another ME network var accessorOpt = target.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide); @@ -297,7 +296,7 @@ private int createHandlerHash(BlockEntity target) { return 0; } - var targetSide = this.getSide().getDirection().getOpposite(); + var targetSide = this.getSide().getOpposite(); var accessorOpt = target.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide); @@ -318,7 +317,7 @@ public final MEInventoryHandler getInternalHandler() { this.cached = true; var self = this.getHost().getBlockEntity(); var target = self.getLevel() - .getBlockEntity(self.getBlockPos().relative(this.getSide().getDirection())); + .getBlockEntity(self.getBlockPos().relative(this.getSide())); var newHandlerHash = this.createHandlerHash(target); if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) { @@ -341,7 +340,7 @@ public final MEInventoryHandler getInternalHandler() { } if (inv != null) { - this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite()); + this.checkInterfaceVsStorageBus(target, this.getSide()); this.handler = new MEInventoryHandler<>(inv, getStorageChannel()); @@ -391,7 +390,7 @@ public final MEInventoryHandler getInternalHandler() { return this.handler; } - private void checkInterfaceVsStorageBus(final BlockEntity target, final AEPartLocation side) { + private void checkInterfaceVsStorageBus(final BlockEntity target, final Direction side) { IGridNode targetNode = null; if (target instanceof ItemInterfaceBlockEntity interfaceBlockEntity) { diff --git a/src/main/java/appeng/parts/misc/CableAnchorPart.java b/src/main/java/appeng/parts/misc/CableAnchorPart.java index bf4e3d04a2d..6cc59f62dc0 100644 --- a/src/main/java/appeng/parts/misc/CableAnchorPart.java +++ b/src/main/java/appeng/parts/misc/CableAnchorPart.java @@ -23,6 +23,7 @@ import java.util.Random; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -44,7 +45,6 @@ import appeng.api.parts.IPartModel; import appeng.api.parts.PartItemStack; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.parts.PartModel; @@ -61,7 +61,7 @@ public class CableAnchorPart implements IPart { private ItemStack is = ItemStack.EMPTY; private IPartHost host = null; - private AEPartLocation mySide = AEPartLocation.UP; + private Direction mySide = Direction.UP; public CableAnchorPart(final ItemStack is) { this.is = is; @@ -113,7 +113,7 @@ public int getLightLevel() { @Override public boolean isLadder(final LivingEntity entity) { - return this.mySide.yOffset == 0 && (entity.horizontalCollision || !entity.isOnGround()); + return this.mySide.getStepY() == 0 && (entity.horizontalCollision || !entity.isOnGround()); } @Override @@ -167,7 +167,7 @@ public IGridNode getExternalFacingNode() { } @Override - public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity blockEntity) { + public void setPartHostInfo(final Direction side, final IPartHost host, final BlockEntity blockEntity) { this.host = host; this.mySide = side; } @@ -199,7 +199,7 @@ public void animateTick(final Level level, final BlockPos pos, final Random r) { @Override public void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { } diff --git a/src/main/java/appeng/parts/misc/FluidInterfacePart.java b/src/main/java/appeng/parts/misc/FluidInterfacePart.java index 79836a05f0f..d15f6ffa210 100644 --- a/src/main/java/appeng/parts/misc/FluidInterfacePart.java +++ b/src/main/java/appeng/parts/misc/FluidInterfacePart.java @@ -145,7 +145,7 @@ public > IMEMonitor getInventory(IStorageChannel cha @Override public EnumSet getTargets() { - return EnumSet.of(this.getSide().getDirection()); + return EnumSet.of(this.getSide()); } @Override @@ -176,7 +176,7 @@ public void setPriority(final int newValue) { @Override public LazyOptional getCapability(Capability capabilityClass) { - return this.duality.getCapability(capabilityClass, this.getSide().getDirection()); + return this.duality.getCapability(capabilityClass, this.getSide()); } @Override diff --git a/src/main/java/appeng/parts/misc/ItemInterfacePart.java b/src/main/java/appeng/parts/misc/ItemInterfacePart.java index 4e00f829712..06ee999b9a9 100644 --- a/src/main/java/appeng/parts/misc/ItemInterfacePart.java +++ b/src/main/java/appeng/parts/misc/ItemInterfacePart.java @@ -191,7 +191,7 @@ public DualityItemInterface getInterfaceDuality() { @Override public EnumSet getTargets() { - return EnumSet.of(this.getSide().getDirection()); + return EnumSet.of(this.getSide()); } @Override @@ -222,7 +222,7 @@ public IPartModel getStaticModels() { @Override public LazyOptional getCapability(Capability capabilityClass) { - return this.duality.getCapability(capabilityClass, this.getSide().getDirection()); + return this.duality.getCapability(capabilityClass, this.getSide()); } @Override diff --git a/src/main/java/appeng/parts/misc/ToggleBusPart.java b/src/main/java/appeng/parts/misc/ToggleBusPart.java index d4b64864190..37186a7a78b 100644 --- a/src/main/java/appeng/parts/misc/ToggleBusPart.java +++ b/src/main/java/appeng/parts/misc/ToggleBusPart.java @@ -21,6 +21,7 @@ import java.util.EnumSet; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; @@ -38,7 +39,6 @@ import appeng.api.parts.IPartHost; import appeng.api.parts.IPartModel; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.core.AELog; import appeng.core.AppEng; import appeng.items.parts.PartModels; @@ -137,9 +137,9 @@ public void addToWorld() { } @Override - public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity blockEntity) { + public void setPartHostInfo(final Direction side, final IPartHost host, final BlockEntity blockEntity) { super.setPartHostInfo(side, host, blockEntity); - this.outerNode.setExposedOnSides(EnumSet.of(side.getDirection())); + this.outerNode.setExposedOnSides(EnumSet.of(side)); } @Override @@ -154,7 +154,7 @@ public float getCableConnectionLength(AECableType cable) { @Override public void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { super.onPlacement(player, hand, held, side); this.getOuterNode().setOwningPlayer(player); } diff --git a/src/main/java/appeng/parts/networking/CablePart.java b/src/main/java/appeng/parts/networking/CablePart.java index a3ebce33594..f872be29b13 100644 --- a/src/main/java/appeng/parts/networking/CablePart.java +++ b/src/main/java/appeng/parts/networking/CablePart.java @@ -41,7 +41,6 @@ import appeng.api.parts.IPartHost; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.core.definitions.AEParts; import appeng.items.parts.ColoredPartItem; import appeng.parts.AEBasePart; @@ -136,8 +135,8 @@ public boolean changeColor(final AEColor newColor, final Player who) { return true; } - this.getHost().removePart(AEPartLocation.INTERNAL, true); - this.getHost().addPart(newPart, AEPartLocation.INTERNAL, who, null); + this.getHost().removePart(null, true); + this.getHost().addPart(newPart, null, who, null); return true; } } @@ -166,7 +165,7 @@ public void getBoxes(final IPartCollisionHelper bch) { final IPartHost ph = this.getHost(); if (ph != null) { - for (final AEPartLocation dir : AEPartLocation.SIDE_LOCATIONS) { + for (final Direction dir : Direction.values()) { var p = ph.getPart(dir); if (p != null) { var dist = p.getCableConnectionLength(this.getCableConnectionType()); @@ -266,7 +265,7 @@ public void writeToStream(final FriendlyByteBuf data) throws IOException { } if (n.isPowered()) { - flags |= 1 << AEPartLocation.INTERNAL.ordinal(); + flags |= 1 << Direction.values().length; } } @@ -288,7 +287,7 @@ public boolean readFromStream(final FriendlyByteBuf data) throws IOException { boolean channelsChanged = false; - this.powered = (cs & (1 << AEPartLocation.INTERNAL.ordinal())) != 0; + this.powered = (cs & (1 << Direction.values().length)) != 0; var connections = EnumSet.noneOf(Direction.class); for (var d : Direction.values()) { diff --git a/src/main/java/appeng/parts/networking/QuartzFiberPart.java b/src/main/java/appeng/parts/networking/QuartzFiberPart.java index cbd92791f3d..803fe396702 100644 --- a/src/main/java/appeng/parts/networking/QuartzFiberPart.java +++ b/src/main/java/appeng/parts/networking/QuartzFiberPart.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.EnumSet; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; @@ -39,7 +40,6 @@ import appeng.api.parts.IPartHost; import appeng.api.parts.IPartModel; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.me.service.EnergyService; @@ -98,9 +98,9 @@ public void addToWorld() { } @Override - public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity blockEntity) { + public void setPartHostInfo(final Direction side, final IPartHost host, final BlockEntity blockEntity) { super.setPartHostInfo(side, host, blockEntity); - this.outerNode.setExposedOnSides(EnumSet.of(side.getDirection())); + this.outerNode.setExposedOnSides(EnumSet.of(side)); } @Override @@ -115,7 +115,7 @@ public float getCableConnectionLength(AECableType cable) { @Override public void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { super.onPlacement(player, hand, held, side); this.outerNode.setOwningPlayer(player); } diff --git a/src/main/java/appeng/parts/p2p/CapabilityP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/CapabilityP2PTunnelPart.java index 2ed6ecd263e..647d377ccbd 100644 --- a/src/main/java/appeng/parts/p2p/CapabilityP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/CapabilityP2PTunnelPart.java @@ -95,7 +95,7 @@ protected C get() { var te = self.getLevel().getBlockEntity(getFacingPos()); if (te != null) { - return te.getCapability(capability, getSide().getOpposite().getDirection()) + return te.getCapability(capability, getSide().getOpposite()) .orElse(emptyHandler); } } @@ -120,7 +120,7 @@ public void close() { * The position right in front of this P2P tunnel. */ private BlockPos getFacingPos() { - return getHost().getLocation().getPos().relative(getSide().getDirection()); + return getHost().getLocation().getPos().relative(getSide()); } /** diff --git a/src/main/java/appeng/parts/p2p/LightP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/LightP2PTunnelPart.java index 7d9094ab832..b575e863f55 100644 --- a/src/main/java/appeng/parts/p2p/LightP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/LightP2PTunnelPart.java @@ -94,7 +94,7 @@ private boolean doWork() { final BlockEntity te = this.getBlockEntity(); final Level level = te.getLevel(); - final int newLevel = level.getMaxLocalRawBrightness(te.getBlockPos().relative(this.getSide().getDirection())); + final int newLevel = level.getMaxLocalRawBrightness(te.getBlockPos().relative(this.getSide())); if (this.lastValue != newLevel && this.getMainNode().isActive()) { this.lastValue = newLevel; @@ -108,7 +108,7 @@ private boolean doWork() { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (this.isOutput() && pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (this.isOutput() && pos.relative(this.getSide()).equals(neighbor)) { this.opacity = -1; this.getHost().markForUpdate(); } else { @@ -134,7 +134,7 @@ private int blockLight(final int emit) { if (this.opacity < 0) { final BlockEntity te = this.getBlockEntity(); this.opacity = 255 - - te.getLevel().getMaxLocalRawBrightness(te.getBlockPos().relative(this.getSide().getDirection())); + - te.getLevel().getMaxLocalRawBrightness(te.getBlockPos().relative(this.getSide())); } return (int) (emit * (this.opacity / 255.0f)); diff --git a/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java index f0392ae5428..0aa2b8def58 100644 --- a/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; @@ -40,7 +41,6 @@ import appeng.api.parts.IPartHost; import appeng.api.parts.IPartModel; import appeng.api.util.AECableType; -import appeng.api.util.AEPartLocation; import appeng.core.AELog; import appeng.core.settings.TickRates; import appeng.hooks.ticking.TickHandler; @@ -116,9 +116,9 @@ public void addToWorld() { } @Override - public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity blockEntity) { + public void setPartHostInfo(final Direction side, final IPartHost host, final BlockEntity blockEntity) { super.setPartHostInfo(side, host, blockEntity); - this.outerNode.setExposedOnSides(EnumSet.of(side.getDirection())); + this.outerNode.setExposedOnSides(EnumSet.of(side)); } @Override @@ -128,7 +128,7 @@ public IGridNode getExternalFacingNode() { @Override public void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { super.onPlacement(player, hand, held, side); this.outerNode.setOwningPlayer(player); } diff --git a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java index 90592a4763f..2ea1b12b876 100644 --- a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java @@ -45,7 +45,6 @@ import appeng.api.parts.PartItemStack; import appeng.api.util.AECableType; import appeng.api.util.AEColor; -import appeng.api.util.AEPartLocation; import appeng.client.render.cablebus.P2PTunnelFrequencyModelData; import appeng.core.AEConfig; import appeng.core.definitions.AEParts; @@ -182,8 +181,8 @@ public boolean onPartActivate(final Player player, final InteractionHand hand, f final IPart testPart = ((IPartItem) newType.getItem()).createPart(newType); if (testPart instanceof P2PTunnelPart) { this.getHost().removePart(this.getSide(), true); - final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand); - final IPart newBus = this.getHost().getPart(dir); + final boolean dir = this.getHost().addPart(newType, this.getSide(), player, hand); + final IPart newBus = this.getHost().getPart(this.getSide()); if (newBus instanceof P2PTunnelPartnewTunnel) { newTunnel.setOutput(true); @@ -223,8 +222,8 @@ public boolean onPartActivate(final Player player, final InteractionHand hand, f final short myFreq = this.getFrequency(); this.getHost().removePart(this.getSide(), true); - final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand); - final IPart newBus = this.getHost().getPart(dir); + final var partAdded = this.getHost().addPart(newType, this.getSide(), player, hand); + final IPart newBus = this.getHost().getPart(this.getSide()); if (newBus instanceof P2PTunnelPart newTunnel) { newTunnel.setOutput(oldOutput); diff --git a/src/main/java/appeng/parts/p2p/RedstoneP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/RedstoneP2PTunnelPart.java index 99e648ab3c9..e204f745a62 100644 --- a/src/main/java/appeng/parts/p2p/RedstoneP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/RedstoneP2PTunnelPart.java @@ -118,12 +118,12 @@ public void onTunnelNetworkChange() { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { if (!this.isOutput()) { - final BlockPos target = this.getBlockEntity().getBlockPos().relative(this.getSide().getDirection()); + final BlockPos target = this.getBlockEntity().getBlockPos().relative(this.getSide()); final BlockState state = this.getBlockEntity().getLevel().getBlockState(target); final Block b = state.getBlock(); if (b != null && !this.isOutput()) { - Direction srcSide = this.getSide().getDirection(); + Direction srcSide = this.getSide(); if (b instanceof RedStoneWireBlock) { srcSide = Direction.UP; } diff --git a/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java b/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java index 948e7581e8a..52bc5399d7d 100644 --- a/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java +++ b/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java @@ -232,7 +232,7 @@ public void renderDynamic(float partialTicks, PoseStack poseStack, MultiBufferSo poseStack.pushPose(); poseStack.translate(0.5, 0.5, 0.5); // Move into the center of the block - Direction facing = this.getSide().getDirection(); + Direction facing = this.getSide(); TesrRenderHelper.rotateToFace(poseStack, facing, this.getSpin()); diff --git a/src/main/java/appeng/parts/reporting/AbstractReportingPart.java b/src/main/java/appeng/parts/reporting/AbstractReportingPart.java index c95f38c975b..3f37817980d 100644 --- a/src/main/java/appeng/parts/reporting/AbstractReportingPart.java +++ b/src/main/java/appeng/parts/reporting/AbstractReportingPart.java @@ -23,6 +23,7 @@ import javax.annotation.Nonnull; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.util.Mth; @@ -41,7 +42,6 @@ import appeng.api.networking.IGridNodeListener; import appeng.api.parts.IPartCollisionHelper; import appeng.api.parts.IPartModel; -import appeng.api.util.AEPartLocation; import appeng.parts.AEBasePart; import appeng.util.InteractionUtil; @@ -99,7 +99,7 @@ public final void getBoxes(final IPartCollisionHelper bch) { @Override public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { - if (pos.relative(this.getSide().getDirection()).equals(neighbor)) { + if (pos.relative(this.getSide()).equals(neighbor)) { this.opacity = -1; this.getHost().markForUpdate(); } @@ -178,11 +178,11 @@ public boolean onPartActivate(final Player player, final InteractionHand hand, f @Override public final void onPlacement(final Player player, final InteractionHand hand, final ItemStack held, - final AEPartLocation side) { + final Direction side) { super.onPlacement(player, hand, held, side); final byte rotation = (byte) (Mth.floor(player.getYRot() * 4F / 360F + 2.5D) & 3); - if (side == AEPartLocation.UP || side == AEPartLocation.DOWN) { + if (side == Direction.UP || side == Direction.DOWN) { this.spin = rotation; } } @@ -191,7 +191,7 @@ private int blockLight(final int emit) { if (this.opacity < 0) { final BlockEntity te = this.getBlockEntity(); Level level = te.getLevel(); - BlockPos pos = te.getBlockPos().relative(this.getSide().getDirection()); + BlockPos pos = te.getBlockPos().relative(this.getSide()); this.opacity = 255 - level.getBlockState(pos).getLightBlock(level, pos); } diff --git a/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java b/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java index 5b8f8500366..d7444c46729 100644 --- a/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java +++ b/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java @@ -207,7 +207,7 @@ private void extractItem(final Player player, int count) { if (!newItems.isEmpty()) { final BlockEntity te = this.getBlockEntity(); final List list = Collections.singletonList(newItems); - Platform.spawnDrops(player.level, te.getBlockPos().relative(this.getSide().getDirection()), list); + Platform.spawnDrops(player.level, te.getBlockPos().relative(this.getSide()), list); } if (player.containerMenu != null) { diff --git a/src/main/java/appeng/spatial/CachedPlane.java b/src/main/java/appeng/spatial/CachedPlane.java index dc27f705951..901fe52cc56 100644 --- a/src/main/java/appeng/spatial/CachedPlane.java +++ b/src/main/java/appeng/spatial/CachedPlane.java @@ -22,6 +22,7 @@ import java.util.List; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacket; import net.minecraft.server.level.ServerLevel; @@ -40,7 +41,6 @@ import appeng.api.ids.AETags; import appeng.api.movable.BlockEntityMoveStrategies; import appeng.api.movable.IBlockEntityMoveStrategy; -import appeng.api.util.AEPartLocation; import appeng.api.util.WorldCoord; import appeng.core.AELog; import appeng.core.definitions.AEBlocks; @@ -230,8 +230,8 @@ void swap(final CachedPlane dst) { private void markForUpdate(final int x, final int y, final int z) { this.updates.add(new WorldCoord(x, y, z)); - for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) { - this.updates.add(new WorldCoord(x + d.xOffset, y + d.yOffset, z + d.zOffset)); + for (final Direction d : Direction.values()) { + this.updates.add(new WorldCoord(x + d.getStepX(), y + d.getStepY(), z + d.getStepZ())); } } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 6c9698cf02e..173c9743ee9 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -91,7 +91,6 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; -import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalBlockPos; import appeng.core.AEConfig; import appeng.core.AELog; @@ -130,6 +129,9 @@ public static ItemComparisonHelper itemComparisons() { private static final P2PHelper P2P_HELPER = new P2PHelper(); + public static final Direction[] DIRECTIONS_WITH_NULL = new Direction[] { Direction.DOWN, Direction.UP, + Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, null }; + public static P2PHelper p2p() { return P2P_HELPER; } @@ -423,104 +425,6 @@ public static T pickRandom(final Collection outs) { return Iterables.get(outs, index, null); } - public static AEPartLocation rotateAround(final AEPartLocation forward, final AEPartLocation axis) { - if (axis == AEPartLocation.INTERNAL || forward == AEPartLocation.INTERNAL) { - return forward; - } - - switch (forward) { - case DOWN: - switch (axis) { - case DOWN: - return forward; - case UP: - return forward; - case NORTH: - return AEPartLocation.EAST; - case SOUTH: - return AEPartLocation.WEST; - case EAST: - return AEPartLocation.NORTH; - case WEST: - return AEPartLocation.SOUTH; - default: - break; - } - break; - case UP: - switch (axis) { - case NORTH: - return AEPartLocation.WEST; - case SOUTH: - return AEPartLocation.EAST; - case EAST: - return AEPartLocation.SOUTH; - case WEST: - return AEPartLocation.NORTH; - default: - break; - } - break; - case NORTH: - switch (axis) { - case UP: - return AEPartLocation.WEST; - case DOWN: - return AEPartLocation.EAST; - case EAST: - return AEPartLocation.UP; - case WEST: - return AEPartLocation.DOWN; - default: - break; - } - break; - case SOUTH: - switch (axis) { - case UP: - return AEPartLocation.EAST; - case DOWN: - return AEPartLocation.WEST; - case EAST: - return AEPartLocation.DOWN; - case WEST: - return AEPartLocation.UP; - default: - break; - } - break; - case EAST: - switch (axis) { - case UP: - return AEPartLocation.NORTH; - case DOWN: - return AEPartLocation.SOUTH; - case NORTH: - return AEPartLocation.UP; - case SOUTH: - return AEPartLocation.DOWN; - default: - break; - } - case WEST: - switch (axis) { - case UP: - return AEPartLocation.SOUTH; - case DOWN: - return AEPartLocation.NORTH; - case NORTH: - return AEPartLocation.DOWN; - case SOUTH: - return AEPartLocation.UP; - default: - break; - } - default: - break; - } - return forward; - } - public static Direction rotateAround(final Direction forward, final Direction axis) { switch (forward) { case DOWN: @@ -835,7 +739,7 @@ private static boolean checkPlayerPermissions(final IGrid grid, final int player return gs.hasPermission(playerID, SecurityPermissions.BUILD); } - public static void configurePlayer(final Player player, final AEPartLocation side, final BlockEntity blockEntity) { + public static void configurePlayer(final Player player, final Direction side, final BlockEntity blockEntity) { float pitch = 0.0f; float yaw = 0.0f; // player.yOffset = 1.8f; @@ -854,14 +758,14 @@ public static void configurePlayer(final Player player, final AEPartLocation sid case SOUTH: yaw = 0.0f; break; - case INTERNAL: - break; case UP: pitch = 90.0f; break; case WEST: yaw = 90.0f; break; + default: + break; } player.moveTo(blockEntity.getBlockPos().getX() + 0.5, blockEntity.getBlockPos().getY() + 0.5,