fix a lot of the pluggable rewrite issues
This commit is contained in:
parent
6ad8e3c39a
commit
587f1ab3ac
5 changed files with 72 additions and 47 deletions
|
@ -715,28 +715,25 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
private boolean addOrStripPipePluggable(World world, int x, int y, int z, ItemStack stack, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
|
||||
ForgeDirection pSide = rayTraceResult.sideHit;
|
||||
if (pSide == ForgeDirection.UNKNOWN || pSide == null) {
|
||||
pSide = side;
|
||||
}
|
||||
ForgeDirection placementSide = rayTraceResult != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side;
|
||||
|
||||
IPipePluggableItem pluggableItem = (IPipePluggableItem) stack.getItem();
|
||||
PipePluggable pluggable = pluggableItem.createPipePluggable(pipe, rayTraceResult.sideHit, stack);
|
||||
PipePluggable pluggable = pluggableItem.createPipePluggable(pipe, placementSide, stack);
|
||||
|
||||
if (player.isSneaking()) {
|
||||
if (pipe.container.hasPipePluggable(pSide) && rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pluggable.getClass().isInstance(pipe.container.getPipePluggable(pSide))) {
|
||||
return pipe.container.dropSideItems(pSide);
|
||||
}
|
||||
}
|
||||
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (pluggable == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pipe.container.hasPipePluggable(pSide)) {
|
||||
pipe.container.setPluggable(pSide, pluggable);
|
||||
if (player.isSneaking()) {
|
||||
if (pipe.container.hasPipePluggable(side) && rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pluggable.getClass().isInstance(pipe.container.getPipePluggable(side))) {
|
||||
return pipe.container.dropSideItems(side);
|
||||
}
|
||||
}
|
||||
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (!pipe.container.hasPipePluggable(placementSide)) {
|
||||
pipe.container.setPluggable(placementSide, pluggable);
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
|
|
|
@ -152,7 +152,7 @@ public final class Gate implements IGate, IStatementContainer {
|
|||
|
||||
public void addGateExpansion(IGateExpansion expansion) {
|
||||
if (!expansions.containsKey(expansion)) {
|
||||
expansions.put(expansion, expansion.makeController(pipe.container));
|
||||
expansions.put(expansion, expansion.makeController(pipe != null ? pipe.container : null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -352,10 +352,11 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
// Attach callback
|
||||
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
|
||||
if (sideProperties.pluggables[i] != null) {
|
||||
sideProperties.pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
|
||||
pipe.eventBus.registerHandler(sideProperties.pluggables[i]);
|
||||
sideProperties.pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
|
||||
}
|
||||
}
|
||||
notifyBlockChanged();
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
|
@ -983,13 +984,17 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
break;
|
||||
}
|
||||
case 2: {
|
||||
// TODO: Add some kind of isDirty flag? I don't know...
|
||||
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
|
||||
sideProperties.pluggables = pluggableState.getPluggables();
|
||||
|
||||
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
|
||||
final PipePluggable pluggable = getPipePluggable(ForgeDirection.getOrientation(i));
|
||||
if (pluggable != null && pluggable instanceof GatePluggable) {
|
||||
final GatePluggable gatePluggable = (GatePluggable) pluggable;
|
||||
Gate gate = pipe.gates[i];
|
||||
if (gate == null || gate.logic != gatePluggable.logic || gate.material != gatePluggable.material) {
|
||||
pipe.gates[i] = GateFactory.makeGate(pipe, gatePluggable.material, gatePluggable.logic, ForgeDirection.getOrientation(i));
|
||||
if (gate == null || gate.logic != gatePluggable.getLogic() || gate.material != gatePluggable.getMaterial()) {
|
||||
pipe.gates[i] = GateFactory.makeGate(pipe, gatePluggable.getMaterial(), gatePluggable.getLogic(), ForgeDirection.getOrientation(i));
|
||||
}
|
||||
} else {
|
||||
pipe.gates[i] = null;
|
||||
|
@ -997,10 +1002,6 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
}
|
||||
|
||||
syncGateExpansions();
|
||||
|
||||
// TODO: Add some kind of isDirty flag? I don't know...
|
||||
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
|
||||
sideProperties.pluggables = pluggableState.getPluggables();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1014,8 +1015,8 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
continue;
|
||||
}
|
||||
GatePluggable gatePluggable = (GatePluggable) sideProperties.pluggables[i];
|
||||
if (gatePluggable.expansions.length > 0) {
|
||||
for (IGateExpansion expansion : gatePluggable.expansions) {
|
||||
if (gatePluggable.getExpansions().length > 0) {
|
||||
for (IGateExpansion expansion : gatePluggable.getExpansions()) {
|
||||
if (expansion != null) {
|
||||
if (!gate.expansions.containsKey(expansion)) {
|
||||
gate.addGateExpansion(expansion);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buildcraft.transport.gates;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -10,6 +11,7 @@ import net.minecraft.util.AxisAlignedBB;
|
|||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.gates.GateExpansions;
|
||||
import buildcraft.api.gates.IGate;
|
||||
import buildcraft.api.gates.IGateExpansion;
|
||||
import buildcraft.api.pipes.IPipeContainer;
|
||||
import buildcraft.api.pipes.IPipePluggableRenderer;
|
||||
|
@ -25,13 +27,18 @@ public class GatePluggable extends PipePluggable {
|
|||
public IGateExpansion[] expansions;
|
||||
public boolean isLit, isPulsing;
|
||||
|
||||
public Gate realGate;
|
||||
public Gate realGate, instantiatedGate;
|
||||
private float pulseStage;
|
||||
|
||||
public GatePluggable() {
|
||||
}
|
||||
|
||||
public GatePluggable(Gate gate) {
|
||||
instantiatedGate = gate;
|
||||
initFromGate(gate);
|
||||
}
|
||||
|
||||
private void initFromGate(Gate gate) {
|
||||
this.material = gate.material;
|
||||
this.logic = gate.logic;
|
||||
|
||||
|
@ -68,8 +75,8 @@ public class GatePluggable extends PipePluggable {
|
|||
public void writeData(ByteBuf buf) {
|
||||
buf.writeByte(material.ordinal());
|
||||
buf.writeByte(logic.ordinal());
|
||||
buf.writeBoolean(realGate.isGateActive());
|
||||
buf.writeBoolean(realGate.isGatePulsing());
|
||||
buf.writeBoolean(realGate != null ? realGate.isGateActive() : false);
|
||||
buf.writeBoolean(realGate != null ? realGate.isGatePulsing() : false);
|
||||
|
||||
final int expansionsSize = expansions.length;
|
||||
buf.writeInt(expansionsSize);
|
||||
|
@ -116,12 +123,20 @@ public class GatePluggable extends PipePluggable {
|
|||
public void onAttachedPipe(IPipeContainer pipe, ForgeDirection direction) {
|
||||
TileGenericPipe pipeReal = (TileGenericPipe) pipe;
|
||||
if (!pipeReal.getWorld().isRemote) {
|
||||
if (instantiatedGate != null) {
|
||||
pipeReal.pipe.gates[direction.ordinal()] = instantiatedGate;
|
||||
} else {
|
||||
Gate gate = pipeReal.pipe.gates[direction.ordinal()];
|
||||
if (gate == null || gate.material != material || gate.logic != logic) {
|
||||
pipeReal.pipe.gates[direction.ordinal()] = GateFactory.makeGate(pipeReal.pipe, material, logic, direction);
|
||||
for (IGateExpansion expansion : expansions) {
|
||||
pipeReal.pipe.gates[direction.ordinal()].addGateExpansion(expansion);
|
||||
}
|
||||
pipeReal.scheduleRenderUpdate();
|
||||
}
|
||||
this.realGate = pipeReal.pipe.gates[direction.ordinal()];
|
||||
}
|
||||
|
||||
realGate = pipeReal.pipe.gates[direction.ordinal()];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,4 +213,16 @@ public class GatePluggable extends PipePluggable {
|
|||
public float getPulseStage() {
|
||||
return pulseStage;
|
||||
}
|
||||
|
||||
public GateDefinition.GateMaterial getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public GateDefinition.GateLogic getLogic() {
|
||||
return logic;
|
||||
}
|
||||
|
||||
public IGateExpansion[] getExpansions() {
|
||||
return expansions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -501,9 +501,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
|
||||
IIcon iconLogic;
|
||||
if (gate.isLit) {
|
||||
iconLogic = gate.logic.getIconLit();
|
||||
iconLogic = gate.getLogic().getIconLit();
|
||||
} else {
|
||||
iconLogic = gate.logic.getIconDark();
|
||||
iconLogic = gate.getLogic().getIconDark();
|
||||
}
|
||||
|
||||
float translateCenter = 0;
|
||||
|
@ -527,12 +527,12 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
renderGate(pipe, iconLogic, 0, 0.13F, translateCenter, translateCenter, direction);
|
||||
}
|
||||
|
||||
IIcon materialIcon = gate.material.getIconBlock();
|
||||
IIcon materialIcon = gate.getMaterial().getIconBlock();
|
||||
if (materialIcon != null) {
|
||||
renderGate(pipe, materialIcon, 1, 0.13F, translateCenter, translateCenter, direction);
|
||||
}
|
||||
|
||||
for (IGateExpansion expansion : gate.expansions) {
|
||||
for (IGateExpansion expansion : gate.getExpansions()) {
|
||||
renderGate(pipe, expansion.getOverlayBlock(), 2, 0.13F, translateCenter, translateCenter, direction);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue