Skip to content

Commit

Permalink
Closes #5256: Replace AEPartLocation with Direction (#5385)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
yueh authored Aug 22, 2021
1 parent c64e0f4 commit 390b0bf
Show file tree
Hide file tree
Showing 61 changed files with 518 additions and 788 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
15 changes: 6 additions & 9 deletions src/api/java/appeng/api/parts/IFacadeContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/api/java/appeng/api/parts/IFacadePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/api/java/appeng/api/parts/IPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.mojang.blaze3d.vertex.PoseStack;

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
41 changes: 16 additions & 25 deletions src/api/java/appeng/api/parts/IPartHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -49,56 +50,46 @@ 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
* "gone" and its never coming back; think about it.
*
* 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.
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 10 additions & 6 deletions src/api/java/appeng/api/parts/SelectedPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
119 changes: 0 additions & 119 deletions src/api/java/appeng/api/util/AEPartLocation.java

This file was deleted.

Loading

0 comments on commit 390b0bf

Please sign in to comment.