diff --git a/common/buildcraft/builders/EventHandlerBuilders.java b/common/buildcraft/builders/EventHandlerBuilders.java index 0e89147e..25d74bf3 100644 --- a/common/buildcraft/builders/EventHandlerBuilders.java +++ b/common/buildcraft/builders/EventHandlerBuilders.java @@ -16,7 +16,13 @@ public class EventHandlerBuilders { @ForgeSubscribe public void handleWorldLoad(WorldEvent.Load event) { //When a world loads clean the list of available markers - TilePathMarker.clearAvailableMarkersList(); + + //For some reason, when loading a world this gets called 3 times from the + //server and one from the client. We don't want the client to clear the + //list because it happens after the initializations and therefore it re- + //moves the loaded path markers. + if (!event.world.getClass().equals(net.minecraft.src.WorldClient.class)) + TilePathMarker.clearAvailableMarkersList(); } } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index bd6d6e61..e628d0df 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -24,6 +24,7 @@ import buildcraft.core.BlockIndex; import buildcraft.core.Box; import buildcraft.core.DefaultProps; import buildcraft.core.EntityLaser; +import buildcraft.core.EntityPowerLaser; import buildcraft.core.EntityRobot; import buildcraft.core.IBuilderInventory; import buildcraft.core.IMachine; @@ -231,7 +232,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP for (BlockIndex b : path) { if (previous != null) { - EntityLaser laser = new EntityLaser(worldObj, + EntityLaser laser = new EntityPowerLaser(worldObj, new Position(previous.i + 0.5, previous.j + 0.5, previous.k + 0.5), new Position(b.i + 0.5, b.j + 0.5, b.k + 0.5)); diff --git a/common/buildcraft/builders/TilePathMarker.java b/common/buildcraft/builders/TilePathMarker.java index 0669f083..64bc09a0 100644 --- a/common/buildcraft/builders/TilePathMarker.java +++ b/common/buildcraft/builders/TilePathMarker.java @@ -8,6 +8,9 @@ import buildcraft.api.core.Position; import buildcraft.core.BlockIndex; import buildcraft.core.DefaultProps; import buildcraft.core.EntityLaser; +import buildcraft.core.EntityPowerLaser; +import buildcraft.core.network.PacketUpdate; +import buildcraft.core.network.TileNetworkData; import buildcraft.core.proxy.CoreProxy; import net.minecraft.src.NBTTagCompound; @@ -19,7 +22,7 @@ public class TilePathMarker extends TileMarker { public int x0, y0, z0, x1, y1, z1; public boolean loadLink0 = false, loadLink1 = false; - public boolean tryingToConnect = false; + public @TileNetworkData boolean tryingToConnect = false; public TilePathMarker links[] = new TilePathMarker[2]; public static int searchSize = 64; //TODO: this should be moved to default props @@ -28,9 +31,6 @@ public class TilePathMarker extends TileMarker { //It only contains markers within the loaded chunks private static LinkedList availableMarkers = new LinkedList(); - public TilePathMarker() { - availableMarkers.add(this); - } public boolean isFullyConnected() { return lasers[0] != null && lasers[1] != null; @@ -58,7 +58,7 @@ public class TilePathMarker extends TileMarker { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; - EntityLaser laser = new EntityLaser(worldObj, new Position(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5), new Position(pathMarker.xCoord + 0.5, pathMarker.yCoord + 0.5, pathMarker.zCoord + 0.5)); + EntityLaser laser = new EntityPowerLaser(worldObj, new Position(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5), new Position(pathMarker.xCoord + 0.5, pathMarker.yCoord + 0.5, pathMarker.zCoord + 0.5)); laser.show(); laser.setTexture(DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png"); @@ -93,17 +93,20 @@ public class TilePathMarker extends TileMarker { @Override public void tryConnection() { - if (isFullyConnected()) { + + if (CoreProxy.proxy.isRenderWorld(worldObj) || isFullyConnected()) return; - } tryingToConnect = !tryingToConnect; //Allow the user to stop the path marker from searching for new path markers to connect - worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); + sendNetworkUpdate(); } @Override public void updateEntity() { super.updateEntity(); + + if (CoreProxy.proxy.isRenderWorld(worldObj)) + return; if (tryingToConnect) { TilePathMarker nearestPathMarker = findNearestAvailablePathMarker(); @@ -111,7 +114,7 @@ public class TilePathMarker extends TileMarker { if (nearestPathMarker != null) { createLaserAndConnect(nearestPathMarker); tryingToConnect = false; - worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); + sendNetworkUpdate(); } } } @@ -155,9 +158,6 @@ public class TilePathMarker extends TileMarker { lasers[1].setDead(); } - lasers = new EntityLaser[2]; - links = new TilePathMarker[2]; - availableMarkers.remove(this); tryingToConnect = false; } @@ -166,6 +166,9 @@ public class TilePathMarker extends TileMarker { public void initialize() { super.initialize(); + if (CoreProxy.proxy.isSimulating(worldObj)) + availableMarkers.add(this); + if (loadLink0) { TileEntity e0 = worldObj.getBlockTileEntity(x0, y0, z0); @@ -197,8 +200,8 @@ public class TilePathMarker extends TileMarker { lasers[1] = null; links[1] = null; } - - if (!isFullyConnected() && !availableMarkers.contains(this)) + + if (!isFullyConnected() && !availableMarkers.contains(this) && CoreProxy.proxy.isSimulating(worldObj)) availableMarkers.add(this); } @@ -248,4 +251,15 @@ public class TilePathMarker extends TileMarker { public static void clearAvailableMarkersList() { availableMarkers.clear(); } + + @Override + public void handleUpdatePacket(PacketUpdate packet) { + boolean previousState = tryingToConnect; + + super.handleUpdatePacket(packet); + + if (previousState != tryingToConnect) { + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); + } + } } diff --git a/common/buildcraft/core/EntityLaser.java b/common/buildcraft/core/EntityLaser.java index 5894e15e..534cf77e 100644 --- a/common/buildcraft/core/EntityLaser.java +++ b/common/buildcraft/core/EntityLaser.java @@ -57,6 +57,7 @@ public class EntityLaser extends Entity { dataWatcher.addObject(14, Byte.valueOf((byte) 0)); + dataWatcher.addObject(16, ""); } protected void initServerSide() { @@ -76,6 +77,8 @@ public class EntityLaser extends Entity { dataWatcher.addObject(13, Integer.valueOf(encodeDouble(tail.z))); dataWatcher.addObject(14, Byte.valueOf((byte) 0)); + + dataWatcher.addObject(16, ""); } @Override @@ -121,6 +124,7 @@ public class EntityLaser extends Entity { tail.x = decodeDouble(dataWatcher.getWatchableObjectInt(11)); tail.y = decodeDouble(dataWatcher.getWatchableObjectInt(12)); tail.z = decodeDouble(dataWatcher.getWatchableObjectInt(13)); + texture = dataWatcher.getWatchableObjectString(16); } public void setPositions(Position head, Position tail) { @@ -154,6 +158,7 @@ public class EntityLaser extends Entity { public void setTexture(String texture) { this.texture = texture; + dataWatcher.updateObject(16, texture); } public String getTexture() { diff --git a/common/buildcraft/core/render/RenderLaser.java b/common/buildcraft/core/render/RenderLaser.java index 6f09b5bf..eeb6bea7 100644 --- a/common/buildcraft/core/render/RenderLaser.java +++ b/common/buildcraft/core/render/RenderLaser.java @@ -33,7 +33,7 @@ public class RenderLaser extends Render { private void doRender(EntityLaser laser, double x, double y, double z, float f, float f1) { - if (!laser.isVisible()) + if (!laser.isVisible() || laser.getTexture() == null) return; GL11.glPushMatrix();