IPipePluggableItem added to allow other mods to easily place their pluggables on pipes, gates now use the Pluggable system for client-side sync
This commit is contained in:
parent
60af8ac978
commit
15736507ff
15 changed files with 118 additions and 305 deletions
|
@ -16,7 +16,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import buildcraft.api.core.EnumColor;
|
||||
import buildcraft.api.transport.IInjectable;
|
||||
|
||||
public interface IPipeContainer extends IInjectable {
|
||||
public interface IPipeContainer extends IInjectable, IPipePluggableContainer {
|
||||
|
||||
public enum PipeType {
|
||||
|
||||
|
@ -46,7 +46,4 @@ public interface IPipeContainer extends IInjectable {
|
|||
IPipe getNeighborPipe(ForgeDirection dir);
|
||||
|
||||
IPipe getPipe();
|
||||
|
||||
PipePluggable getPipePluggable(ForgeDirection direction);
|
||||
boolean hasPipePluggable(ForgeDirection direction);
|
||||
}
|
||||
|
|
8
api/buildcraft/api/pipes/IPipePluggableContainer.java
Normal file
8
api/buildcraft/api/pipes/IPipePluggableContainer.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package buildcraft.api.pipes;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IPipePluggableContainer {
|
||||
PipePluggable getPipePluggable(ForgeDirection direction);
|
||||
boolean hasPipePluggable(ForgeDirection direction);
|
||||
}
|
8
api/buildcraft/api/pipes/IPipePluggableItem.java
Normal file
8
api/buildcraft/api/pipes/IPipePluggableItem.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package buildcraft.api.pipes;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IPipePluggableItem {
|
||||
PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack);
|
||||
}
|
|
@ -52,6 +52,7 @@ import buildcraft.api.events.PipePlacedEvent;
|
|||
import buildcraft.api.events.RobotPlacementEvent;
|
||||
import buildcraft.api.gates.GateExpansions;
|
||||
import buildcraft.api.gates.IGateExpansion;
|
||||
import buildcraft.api.pipes.IPipePluggableItem;
|
||||
import buildcraft.api.pipes.PipePluggable;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
@ -71,8 +72,6 @@ import buildcraft.transport.gates.GateFactory;
|
|||
import buildcraft.transport.gates.GatePluggable;
|
||||
import buildcraft.transport.gates.ItemGate;
|
||||
import buildcraft.transport.render.PipeRendererWorld;
|
||||
import buildcraft.transport.utils.FacadeMatrix;
|
||||
|
||||
|
||||
public class BlockGenericPipe extends BlockBuildCraft {
|
||||
|
||||
|
@ -644,20 +643,8 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
pipe.container.setColor(-1);
|
||||
}
|
||||
return true;
|
||||
} else if (currentItem.getItem() instanceof ItemGate) {
|
||||
if (addOrStripGate(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) {
|
||||
return true;
|
||||
}
|
||||
} else if (currentItem.getItem() instanceof ItemPlug) {
|
||||
if (addOrStripPlug(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) {
|
||||
return true;
|
||||
}
|
||||
} else if (currentItem.getItem() instanceof ItemRobotStation) {
|
||||
if (addOrStripRobotStation(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) {
|
||||
return true;
|
||||
}
|
||||
} else if (currentItem.getItem() instanceof ItemFacade) {
|
||||
if (addOrStripFacade(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) {
|
||||
} else if (currentItem.getItem() instanceof IPipePluggableItem) {
|
||||
if (addOrStripPipePluggable(world, x, y, z, currentItem, player, ForgeDirection.getOrientation(side), pipe)) {
|
||||
return true;
|
||||
}
|
||||
} else if (currentItem.getItem () instanceof ItemRobot) {
|
||||
|
@ -725,35 +712,34 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean addOrStripGate(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
private boolean addOrStripPipePluggable(World world, int x, int y, int z, ItemStack stack, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
IPipePluggableItem pluggableItem = (IPipePluggableItem) stack.getItem();
|
||||
PipePluggable pluggable = pluggableItem.createPipePluggable(pipe, side, stack);
|
||||
if (pluggable == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
if (player.isSneaking()) {
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof GatePluggable) {
|
||||
if (pipe.container.hasGate(rayTraceResult.sideHit)) {
|
||||
return pipe.container.dropSideItems(rayTraceResult.sideHit);
|
||||
}
|
||||
if (pipe.container.hasPipePluggable(side) && rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pluggable.getClass().isInstance(pipe.container.getPipePluggable(rayTraceResult.sideHit))) {
|
||||
return pipe.container.dropSideItems(rayTraceResult.sideHit);
|
||||
}
|
||||
}
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (!pipe.hasGate(side) && addGate(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side)) {
|
||||
if (!pipe.container.hasPipePluggable(side)) {
|
||||
pipe.container.setPluggable(side, pluggable);
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addGate(EntityPlayer player, Pipe<?> pipe, ForgeDirection side) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (stack != null && stack.getItem() instanceof ItemGate && pipe.container.addGate(side, GateFactory.makeGate(pipe, stack, side))) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addOrStripWire(EntityPlayer player, Pipe<?> pipe, PipeWire color) {
|
||||
if (addWire(pipe, color)) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
|
@ -800,95 +786,8 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean addOrStripFacade(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
if (player.isSneaking()) {
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof FacadePluggable) {
|
||||
if (pipe.container.hasFacade(rayTraceResult.sideHit)) {
|
||||
return pipe.container.dropSideItems(rayTraceResult.sideHit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (addFacade(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addFacade(EntityPlayer player, Pipe<?> pipe, ForgeDirection side) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (stack != null && stack.getItem() instanceof ItemFacade && pipe.container.addFacade(side, ItemFacade.getFacadeStates(stack))) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addOrStripPlug(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
if (player.isSneaking()) {
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof PlugPluggable) {
|
||||
if (pipe.container.dropSideItems(rayTraceResult.sideHit)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (addPlug(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addOrStripRobotStation(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe<?> pipe) {
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
if (player.isSneaking()) {
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable
|
||||
&& pipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof RobotStationPluggable) {
|
||||
if (pipe.container.dropSideItems(rayTraceResult.sideHit)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
|
||||
if (addRobotStation(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addPlug(EntityPlayer player, Pipe<?> pipe, ForgeDirection side) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (pipe.container.addPlug(side)) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addRobotStation(EntityPlayer player, Pipe<?> pipe, ForgeDirection side) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (pipe.container.addRobotStation(side)) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean stripEquipment(World world, int x, int y, int z, EntityPlayer player, Pipe<?> pipe) {
|
||||
// Try to strip facades first
|
||||
// Try to strip pluggables first
|
||||
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
|
||||
if (rayTraceResult != null && rayTraceResult.hitPart != Part.Pipe) {
|
||||
if (pipe.container.dropSideItems(rayTraceResult.sideHit)) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import buildcraft.api.pipes.PipeWire;
|
|||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.transport.gates.GateDefinition.GateLogic;
|
||||
import buildcraft.transport.gates.GateDefinition.GateMaterial;
|
||||
import buildcraft.transport.gates.GatePluggable;
|
||||
import buildcraft.transport.gates.ItemGate;
|
||||
import buildcraft.transport.gates.StatementSlot;
|
||||
import buildcraft.transport.gui.ContainerGateInterface;
|
||||
|
@ -295,21 +296,6 @@ public final class Gate implements IGate, IStatementContainer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This code is aimed at being active on the client only, and moves
|
||||
* the internal position of the gate. There's no need to do that
|
||||
* or to synchronize that with the server as this is only for animation.
|
||||
*/
|
||||
public void updatePulse () {
|
||||
if (pipe.container.renderState.gateMatrix.isGatePulsing(direction) || pulseStage > 0.11F) {
|
||||
// if it is moving, or is still in a moved state, then complete
|
||||
// the current movement
|
||||
pulseStage = (pulseStage + 0.01F) % 1F;
|
||||
} else {
|
||||
pulseStage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATING
|
||||
public void tick() {
|
||||
for (GateExpansionController expansion : expansions.values()) {
|
||||
|
|
|
@ -36,6 +36,9 @@ import buildcraft.api.core.JavaTools;
|
|||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.facades.FacadeType;
|
||||
import buildcraft.api.facades.IFacadeItem;
|
||||
import buildcraft.api.pipes.IPipe;
|
||||
import buildcraft.api.pipes.IPipePluggableItem;
|
||||
import buildcraft.api.pipes.PipePluggable;
|
||||
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
|
||||
import buildcraft.api.pipes.IPipeContainer;
|
||||
import buildcraft.api.pipes.PipeWire;
|
||||
|
@ -45,7 +48,7 @@ import buildcraft.core.ItemBuildCraft;
|
|||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
||||
public class ItemFacade extends ItemBuildCraft implements IFacadeItem {
|
||||
public class ItemFacade extends ItemBuildCraft implements IFacadeItem, IPipePluggableItem {
|
||||
public static class FacadeState {
|
||||
public final Block block;
|
||||
public final int metadata;
|
||||
|
@ -210,29 +213,6 @@ public class ItemFacade extends ItemBuildCraft implements IFacadeItem {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
if (worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
Position pos = new Position(x, y, z, ForgeDirection.getOrientation(side));
|
||||
pos.moveForwards(1.0);
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||
if (!(tile instanceof TileGenericPipe)) {
|
||||
return false;
|
||||
}
|
||||
TileGenericPipe pipeTile = (TileGenericPipe) tile;
|
||||
|
||||
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), getFacadeStates(stack))) {
|
||||
stack.stackSize--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
for (Object o : Block.blockRegistry) {
|
||||
Block b = (Block) o;
|
||||
|
@ -605,4 +585,9 @@ public class ItemFacade extends ItemBuildCraft implements IFacadeItem {
|
|||
stack.setTagCompound(nbt);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) {
|
||||
return new FacadePluggable(getFacadeStates(stack));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,13 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.pipes.IPipe;
|
||||
import buildcraft.api.pipes.IPipeContainer;
|
||||
import buildcraft.api.pipes.IPipePluggableItem;
|
||||
import buildcraft.api.pipes.PipePluggable;
|
||||
import buildcraft.core.ItemBuildCraft;
|
||||
|
||||
public class ItemPlug extends ItemBuildCraft {
|
||||
public class ItemPlug extends ItemBuildCraft implements IPipePluggableItem {
|
||||
|
||||
public ItemPlug() {
|
||||
super();
|
||||
|
@ -51,4 +54,8 @@ public class ItemPlug extends ItemBuildCraft {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) {
|
||||
return new PlugPluggable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,17 +150,12 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
|
|||
actionStates.clear();
|
||||
|
||||
// Update the gate if we have any
|
||||
for (Gate gate : gates) {
|
||||
if (gate == null) {
|
||||
continue;
|
||||
}
|
||||
if (container.getWorldObj().isRemote) {
|
||||
// on client, only update the graphical pulse if needed
|
||||
gate.updatePulse();
|
||||
} else {
|
||||
// on server, do the internal gate update
|
||||
gate.resolveActions();
|
||||
gate.tick();
|
||||
if (!container.getWorldObj().isRemote) {
|
||||
for (Gate gate : gates) {
|
||||
if (gate != null) {
|
||||
gate.resolveActions();
|
||||
gate.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import io.netty.buffer.ByteBuf;
|
|||
|
||||
import buildcraft.api.core.ISerializable;
|
||||
import buildcraft.transport.utils.ConnectionMatrix;
|
||||
import buildcraft.transport.utils.GateMatrix;
|
||||
import buildcraft.transport.utils.TextureMatrix;
|
||||
import buildcraft.transport.utils.WireMatrix;
|
||||
|
||||
|
@ -21,7 +20,6 @@ public class PipeRenderState implements ISerializable {
|
|||
public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix();
|
||||
public final TextureMatrix textureMatrix = new TextureMatrix();
|
||||
public final WireMatrix wireMatrix = new WireMatrix();
|
||||
public final GateMatrix gateMatrix = new GateMatrix();
|
||||
public byte glassColor = -1;
|
||||
|
||||
private boolean dirty = true;
|
||||
|
@ -31,18 +29,16 @@ public class PipeRenderState implements ISerializable {
|
|||
pipeConnectionMatrix.clean();
|
||||
textureMatrix.clean();
|
||||
wireMatrix.clean();
|
||||
gateMatrix.clean();
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return dirty || pipeConnectionMatrix.isDirty()
|
||||
|| textureMatrix.isDirty() || wireMatrix.isDirty()
|
||||
|| gateMatrix.isDirty();
|
||||
|| textureMatrix.isDirty() || wireMatrix.isDirty();
|
||||
}
|
||||
|
||||
public boolean needsRenderUpdate() {
|
||||
return pipeConnectionMatrix.isDirty() || textureMatrix.isDirty()
|
||||
|| wireMatrix.isDirty() || gateMatrix.isDirty();
|
||||
|| wireMatrix.isDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +47,6 @@ public class PipeRenderState implements ISerializable {
|
|||
pipeConnectionMatrix.writeData(data);
|
||||
textureMatrix.writeData(data);
|
||||
wireMatrix.writeData(data);
|
||||
gateMatrix.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +55,5 @@ public class PipeRenderState implements ISerializable {
|
|||
pipeConnectionMatrix.readData(data);
|
||||
textureMatrix.readData(data);
|
||||
wireMatrix.readData(data);
|
||||
gateMatrix.readData(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import buildcraft.BuildCraftTransport;
|
|||
import buildcraft.api.core.render.ITextureStates;
|
||||
import buildcraft.api.pipes.IPipe;
|
||||
import buildcraft.api.pipes.IPipeContainer;
|
||||
import buildcraft.api.pipes.IPipePluggableItem;
|
||||
import buildcraft.api.pipes.IPipePluggableRenderer;
|
||||
import buildcraft.api.pipes.PipePluggable;
|
||||
import buildcraft.core.robots.DockingStation;
|
||||
|
@ -19,7 +20,7 @@ import buildcraft.core.utils.MatrixTranformations;
|
|||
/**
|
||||
* Created by asie on 12/15/14.
|
||||
*/
|
||||
public class RobotStationPluggable extends PipePluggable {
|
||||
public class RobotStationPluggable extends PipePluggable implements IPipePluggableItem {
|
||||
public class RobotStationPluggableRenderer implements IPipePluggableRenderer {
|
||||
private float zFightOffset = 1 / 4096.0F;
|
||||
|
||||
|
@ -246,4 +247,9 @@ public class RobotStationPluggable extends PipePluggable {
|
|||
public void readData(ByteBuf data) {
|
||||
this.renderState = RobotStationState.values()[data.readUnsignedByte()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) {
|
||||
return new RobotStationPluggable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -493,14 +493,6 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
}
|
||||
}
|
||||
|
||||
// Gate Textures and movement
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
|
||||
final Gate gate = pipe.gates[direction.ordinal()];
|
||||
renderState.gateMatrix.setIsGateExists(gate != null, direction);
|
||||
renderState.gateMatrix.setIsGateLit(gate != null && gate.isGateActive(), direction);
|
||||
renderState.gateMatrix.setIsGatePulsing(gate != null && gate.isGatePulsing(), direction);
|
||||
}
|
||||
|
||||
// Facades
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
|
||||
PipePluggable pluggable = sideProperties.pluggables[direction.ordinal()];
|
||||
|
@ -531,10 +523,12 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
|
||||
pluggableState.setPluggables(sideProperties.pluggables);
|
||||
|
||||
// TODO: Add way of signalizing render update via Pluggables
|
||||
|
||||
if (renderState.isDirty()) {
|
||||
renderState.clean();
|
||||
sendUpdateToClient();
|
||||
}
|
||||
sendUpdateToClient();
|
||||
}
|
||||
|
||||
public void initialize(Pipe<?> pipe) {
|
||||
|
@ -868,24 +862,6 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
|||
refreshRenderState = true;
|
||||
}
|
||||
|
||||
public boolean addFacade(ForgeDirection direction, FacadeState[] states) {
|
||||
return setPluggable(direction, new FacadePluggable(states));
|
||||
}
|
||||
|
||||
public boolean addPlug(ForgeDirection direction) {
|
||||
return setPluggable(direction, new PlugPluggable());
|
||||
}
|
||||
|
||||
public boolean addRobotStation(ForgeDirection direction) {
|
||||
return setPluggable(direction, new RobotStationPluggable());
|
||||
}
|
||||
|
||||
public boolean addGate(ForgeDirection direction, Gate gate) {
|
||||
gate.setDirection(direction);
|
||||
pipe.gates[direction.ordinal()] = gate;
|
||||
return setPluggable(direction, new GatePluggable(gate));
|
||||
}
|
||||
|
||||
public boolean hasFacade(ForgeDirection direction) {
|
||||
if (direction == null || direction == ForgeDirection.UNKNOWN) {
|
||||
return false;
|
||||
|
|
|
@ -23,6 +23,10 @@ public class GatePluggable extends PipePluggable {
|
|||
public GateDefinition.GateMaterial material;
|
||||
public GateDefinition.GateLogic logic;
|
||||
public IGateExpansion[] expansions;
|
||||
public boolean isLit, isPulsing;
|
||||
|
||||
public Gate realGate;
|
||||
private float pulseStage;
|
||||
|
||||
public GatePluggable() {
|
||||
}
|
||||
|
@ -64,6 +68,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());
|
||||
|
||||
final int expansionsSize = expansions.length;
|
||||
buf.writeInt(expansionsSize);
|
||||
|
@ -76,6 +82,8 @@ public class GatePluggable extends PipePluggable {
|
|||
public void readData(ByteBuf buf) {
|
||||
material = GateDefinition.GateMaterial.fromOrdinal(buf.readByte());
|
||||
logic = GateDefinition.GateLogic.fromOrdinal(buf.readByte());
|
||||
isLit = buf.readBoolean();
|
||||
isPulsing = buf.readBoolean();
|
||||
|
||||
final int expansionsSize = buf.readInt();
|
||||
expansions = new IGateExpansion[expansionsSize];
|
||||
|
@ -93,6 +101,17 @@ public class GatePluggable extends PipePluggable {
|
|||
return new ItemStack[] { gate };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IPipeContainer pipe, ForgeDirection direction) {
|
||||
if (isPulsing || pulseStage > 0.11F) {
|
||||
// if it is moving, or is still in a moved state, then complete
|
||||
// the current movement
|
||||
pulseStage = (pulseStage + 0.01F) % 1F;
|
||||
} else {
|
||||
pulseStage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedPipe(IPipeContainer pipe, ForgeDirection direction) {
|
||||
TileGenericPipe pipeReal = (TileGenericPipe) pipe;
|
||||
|
@ -102,6 +121,7 @@ public class GatePluggable extends PipePluggable {
|
|||
pipeReal.pipe.gates[direction.ordinal()] = GateFactory.makeGate(pipeReal.pipe, material, logic, direction);
|
||||
pipeReal.scheduleRenderUpdate();
|
||||
}
|
||||
this.realGate = pipeReal.pipe.gates[direction.ordinal()];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,4 +194,8 @@ public class GatePluggable extends PipePluggable {
|
|||
public IPipePluggableRenderer getRenderer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public float getPulseStage() {
|
||||
return pulseStage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,18 +31,22 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.gates.GateExpansions;
|
||||
import buildcraft.api.gates.IGateExpansion;
|
||||
import buildcraft.api.pipes.IPipe;
|
||||
import buildcraft.api.pipes.IPipePluggableItem;
|
||||
import buildcraft.api.pipes.IPipePluggableRenderer;
|
||||
import buildcraft.api.pipes.PipePluggable;
|
||||
import buildcraft.api.statements.StatementManager;
|
||||
import buildcraft.api.pipes.IPipeContainer;
|
||||
import buildcraft.core.ItemBuildCraft;
|
||||
import buildcraft.core.inventory.InvUtils;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
import buildcraft.transport.Gate;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.gates.GateDefinition.GateLogic;
|
||||
import buildcraft.transport.gates.GateDefinition.GateMaterial;
|
||||
|
||||
public class ItemGate extends ItemBuildCraft {
|
||||
public class ItemGate extends ItemBuildCraft implements IPipePluggableItem {
|
||||
|
||||
protected static final String NBT_TAG_MAT = "mat";
|
||||
protected static final String NBT_TAG_LOGIC = "logic";
|
||||
|
@ -259,4 +263,11 @@ public class ItemGate extends ItemBuildCraft {
|
|||
|
||||
StatementManager.registerIcons(iconRegister);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) {
|
||||
Pipe<?> realPipe = (Pipe<?>) pipe;
|
||||
|
||||
return new GatePluggable(GateFactory.makeGate(realPipe, stack, side));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import buildcraft.transport.PipeTransportItems;
|
|||
import buildcraft.transport.PipeTransportPower;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
import buildcraft.transport.gates.GatePluggable;
|
||||
|
||||
public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
||||
public static final float DISPLAY_MULTIPLIER = 0.1f;
|
||||
|
@ -477,14 +478,14 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
}
|
||||
|
||||
private void renderGates(TileGenericPipe pipe, double x, double y, double z) {
|
||||
for (Gate gate : pipe.pipe.gates) {
|
||||
if (gate != null) {
|
||||
renderGate(pipe, x, y, z, gate, gate.getDirection());
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (pipe.getPipePluggable(direction) instanceof GatePluggable) {
|
||||
renderGate(pipe, x, y, z, (GatePluggable) pipe.getPipePluggable(direction), direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderGate(TileGenericPipe pipe, double x, double y, double z, Gate gate, ForgeDirection direction) {
|
||||
private void renderGate(TileGenericPipe pipe, double x, double y, double z, GatePluggable gate, ForgeDirection direction) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
// GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
@ -499,7 +500,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
bindTexture(TextureMap.locationBlocksTexture);
|
||||
|
||||
IIcon iconLogic;
|
||||
if (pipe.renderState.gateMatrix.isGateLit(direction)) {
|
||||
if (gate.isLit) {
|
||||
iconLogic = gate.logic.getIconLit();
|
||||
} else {
|
||||
iconLogic = gate.logic.getIconDark();
|
||||
|
@ -512,7 +513,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
|
||||
float pulseStage = gate.getPulseStage() * 2F;
|
||||
|
||||
if (pipe.renderState.gateMatrix.isGatePulsing(direction) || pulseStage != 0) {
|
||||
if (gate.isPulsing || pulseStage != 0) {
|
||||
// Render pulsing gate
|
||||
float amplitude = 0.10F;
|
||||
float start = 0.01F;
|
||||
|
@ -531,7 +532,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
renderGate(pipe, materialIcon, 1, 0.13F, translateCenter, translateCenter, direction);
|
||||
}
|
||||
|
||||
for (IGateExpansion expansion : gate.expansions.keySet()) {
|
||||
for (IGateExpansion expansion : gate.expansions) {
|
||||
renderGate(pipe, expansion.getOverlayBlock(), 2, 0.13F, translateCenter, translateCenter, direction);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.transport.utils;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class GateMatrix {
|
||||
|
||||
private final boolean[] isGateLit = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private final boolean[] isGatePulsing = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private final boolean[] isGateExists = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private final int[] gateIconIndex = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private boolean dirty = false;
|
||||
|
||||
public GateMatrix() {
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return dirty;
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public void setIsGateLit(boolean gateLit, ForgeDirection direction) {
|
||||
if (isGateLit[direction.ordinal()] != gateLit) {
|
||||
isGateLit[direction.ordinal()] = gateLit;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGateLit(ForgeDirection direction) {
|
||||
return isGateLit[direction.ordinal()];
|
||||
}
|
||||
|
||||
public void setIsGatePulsing(boolean gatePulsing, ForgeDirection direction) {
|
||||
if (isGatePulsing[direction.ordinal()] != gatePulsing) {
|
||||
isGatePulsing[direction.ordinal()] = gatePulsing;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGatePulsing(ForgeDirection direction) {
|
||||
return isGatePulsing[direction.ordinal()];
|
||||
}
|
||||
|
||||
|
||||
public void setIsGateExists(boolean gateExists, ForgeDirection direction) {
|
||||
if (isGateExists[direction.ordinal()] != gateExists) {
|
||||
isGateExists[direction.ordinal()] = gateExists;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGateExists(ForgeDirection direction) {
|
||||
return isGateExists[direction.ordinal()];
|
||||
}
|
||||
|
||||
public void writeData(ByteBuf data) {
|
||||
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
|
||||
data.writeBoolean(isGateLit[i]);
|
||||
data.writeBoolean(isGatePulsing[i]);
|
||||
data.writeBoolean(isGateExists[i]);
|
||||
data.writeInt(gateIconIndex[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void readData(ByteBuf data) {
|
||||
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
|
||||
isGateLit[i] = data.readBoolean();
|
||||
isGatePulsing[i] = data.readBoolean();
|
||||
isGateExists[i] = data.readBoolean();
|
||||
gateIconIndex[i] = data.readInt();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue