From b1bc60ed0b06d7786db7d3f0ff343c9dc0382218 Mon Sep 17 00:00:00 2001 From: psxlover Date: Fri, 14 Sep 2012 22:32:04 +0300 Subject: [PATCH 1/2] Fixed PathMarkers. It was using EntityLaser while a recent commit changed the renderer to work on EntityPowerLaser. Also the EntityLaser wasn't syncing the texture (another partial fix for #263) Also both the client and the server threads were manipulating the available pathMarker list. Now only the server side tiles are added. Finally synced the state of the pathMarkers (whether or not they are searching for a new marker to connect) --- .../builders/EventHandlerBuilders.java | 8 +++- common/buildcraft/builders/TileBuilder.java | 3 +- .../buildcraft/builders/TilePathMarker.java | 40 ++++++++++++++----- common/buildcraft/core/EntityLaser.java | 5 +++ .../buildcraft/core/render/RenderLaser.java | 2 +- 5 files changed, 44 insertions(+), 14 deletions(-) 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..6f027380 100644 --- a/common/buildcraft/builders/TilePathMarker.java +++ b/common/buildcraft/builders/TilePathMarker.java @@ -8,7 +8,11 @@ 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 cpw.mods.fml.common.FMLLog; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; @@ -19,7 +23,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 +32,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 +59,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 +94,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 +115,7 @@ public class TilePathMarker extends TileMarker { if (nearestPathMarker != null) { createLaserAndConnect(nearestPathMarker); tryingToConnect = false; - worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); + sendNetworkUpdate(); } } } @@ -166,6 +170,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 +204,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 +255,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(); From 6ebd570eb10c052bc9da6becb6c197c24b903dfa Mon Sep 17 00:00:00 2001 From: psxlover Date: Fri, 14 Sep 2012 22:47:45 +0300 Subject: [PATCH 2/2] Removed some useless code --- common/buildcraft/builders/TilePathMarker.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/common/buildcraft/builders/TilePathMarker.java b/common/buildcraft/builders/TilePathMarker.java index 6f027380..64bc09a0 100644 --- a/common/buildcraft/builders/TilePathMarker.java +++ b/common/buildcraft/builders/TilePathMarker.java @@ -12,7 +12,6 @@ import buildcraft.core.EntityPowerLaser; import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.TileNetworkData; import buildcraft.core.proxy.CoreProxy; -import cpw.mods.fml.common.FMLLog; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; @@ -159,9 +158,6 @@ public class TilePathMarker extends TileMarker { lasers[1].setDead(); } - lasers = new EntityLaser[2]; - links = new TilePathMarker[2]; - availableMarkers.remove(this); tryingToConnect = false; }