mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-25 20:22:23 +00:00
Restore replacing block with cable parts (#1654)
This commit is contained in:
1 parent
ac1c412e94
commit
be4e421073
3 files changed
+25
-47
No files matched your search
@@ -9,12 +9,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.implementations.parts.IPartCable;
|
||||
import appeng.api.parts.BusSupport;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.parts.networking.PartCable;
|
||||
|
||||
public abstract class AbstractRendererPreview {
|
||||
|
||||
@@ -132,59 +128,32 @@ public abstract class AbstractRendererPreview {
|
||||
.getTileEntity(ViewHelper.getPreviewX(), ViewHelper.getPreviewY(), ViewHelper.getPreviewZ());
|
||||
|
||||
if (!(te instanceof IPartHost partHost)) {
|
||||
return true;
|
||||
return !canPlaceBlockAt(
|
||||
ViewHelper.getWorld(),
|
||||
ViewHelper.getPreviewX(),
|
||||
ViewHelper.getPreviewY(),
|
||||
ViewHelper.getPreviewZ());
|
||||
}
|
||||
|
||||
IPart existingPart = partHost.getPart(ViewHelper.getPlacementSide());
|
||||
if (existingPart != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IPart centerPart = partHost.getPart(ForgeDirection.UNKNOWN);
|
||||
|
||||
if (centerPart instanceof PartCable cablePart) {
|
||||
BusSupport busSupport = cablePart.supportsBuses();
|
||||
return busSupport != BusSupport.CABLE && busSupport != BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
return !hasParts(partHost);
|
||||
return !partHost.canAddPart(ViewHelper.getCachedItemStack(), ViewHelper.getPlacementSide());
|
||||
}
|
||||
|
||||
protected boolean canPlace(World world, ForgeDirection side, int x, int y, int z) {
|
||||
if (!shouldPlaceOnNeighborBlock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int neighborX = x + side.offsetX;
|
||||
int neighborY = y + side.offsetY;
|
||||
int neighborZ = z + side.offsetZ;
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
TileEntity neighborTe = world.getTileEntity(neighborX, neighborY, neighborZ);
|
||||
boolean canPlaceOnNeighbor = canPlaceBlockAt(world, neighborX, neighborY, neighborZ);
|
||||
TileEntity te = world.getTileEntity(neighborX, neighborY, neighborZ);
|
||||
|
||||
if (!shouldPlaceOnNeighborBlock() && checkTe(te, side, canPlaceOnNeighbor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return checkTe(neighborTe, side, canPlaceOnNeighbor);
|
||||
}
|
||||
|
||||
protected boolean checkTe(TileEntity te, ForgeDirection side, boolean canPlaceOnNeighbor) {
|
||||
if (!(te instanceof IPartHost partHost)) {
|
||||
return canPlaceOnNeighbor;
|
||||
return canPlaceBlockAt(world, neighborX, neighborY, neighborZ);
|
||||
}
|
||||
|
||||
if (partHost.getPart(side) != null && !shouldPlaceOnNeighborBlock()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (partHost.getPart(side.getOpposite()) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IPart centerPart = partHost.getPart(ForgeDirection.UNKNOWN);
|
||||
if (centerPart instanceof IPartCable cable) {
|
||||
return cable.supportsBuses() == BusSupport.CABLE;
|
||||
}
|
||||
|
||||
return hasParts(partHost);
|
||||
return partHost.canAddPart(ViewHelper.getCachedItemStack(), side.getOpposite());
|
||||
}
|
||||
|
||||
protected void renderBase(double minXBase, double minYBase, double minZBase, double maxXBase, double maxYBase,
|
||||
|
||||
@@ -108,6 +108,10 @@ public class RendererCable extends AbstractRendererPreview implements IRenderPre
|
||||
|
||||
private boolean handleNullTileEntity(boolean isDense, TileEntity neighborTe, World world, ForgeDirection side,
|
||||
int x, int y, int z) {
|
||||
if (canPlaceBlockAt(world, x, y, z)) {
|
||||
setPreviewOffset(x, y, z, ForgeDirection.UNKNOWN);
|
||||
return true;
|
||||
}
|
||||
setPreviewOffset(x, y, z, side);
|
||||
if (neighborTe instanceof IPartHost partHost) {
|
||||
IPart centerPart = partHost.getPart(ForgeDirection.UNKNOWN);
|
||||
|
||||
@@ -49,6 +49,7 @@ import appeng.core.sync.packets.PacketPartInteraction;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.core.sync.packets.PacketRequestResync;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.fmp.FMPPlacementHelper;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBuildCraftTransport;
|
||||
@@ -220,8 +221,8 @@ public class PartPlacement {
|
||||
|
||||
IPartHost host = getOrCreateHost(world.getTileEntity(x, y, z), player, side.ordinal());
|
||||
|
||||
// Try to add the part to the target block
|
||||
if (host != null && tryPlace(held, player, world, x, y, z, side, host)) return true;
|
||||
// Try to add the part to the target block, or replace a replaceable block like grass
|
||||
if (tryPlace(held, player, world, x, y, z, side, host)) return true;
|
||||
|
||||
// If that didn't work, we try to place on the face of the target block
|
||||
int tx = x + side.offsetX;
|
||||
@@ -236,7 +237,7 @@ public class PartPlacement {
|
||||
}
|
||||
|
||||
public static boolean tryPlace(ItemStack held, EntityPlayer player, World world, int x, int y, int z,
|
||||
ForgeDirection side, IPartHost host) {
|
||||
ForgeDirection side, @Nullable IPartHost host) {
|
||||
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
|
||||
if (!world.canMineBlock(player, x, y, z)) {
|
||||
return false;
|
||||
@@ -271,6 +272,10 @@ public class PartPlacement {
|
||||
host = getExistingHost(world.getTileEntity(x, y, z));
|
||||
if (host == null) return false;
|
||||
}
|
||||
// FMP does not support client side prediction, assume placement is successful on the client side to stop
|
||||
// interaction pipeline on the client side. Item use is the last item in the pipeline, we possibly skip
|
||||
// some offhand client prediction here as well but this only happen when we place on FMP blocks.
|
||||
if (world.isRemote && host instanceof FMPPlacementHelper) return true;
|
||||
final ForgeDirection mySide = host.addPart(held, side, player);
|
||||
if (mySide != null) {
|
||||
if (world.isRemote && host.getPart(mySide) instanceof PartCable cable) {
|
||||
|
||||
Reference in new issue
Block a user