Merge pull request #265 from psxlover/Fixpathmarkers
Fixed PathMarkers.
This commit is contained in:
commit
394175c6eb
5 changed files with 43 additions and 17 deletions
|
@ -16,6 +16,12 @@ public class EventHandlerBuilders {
|
|||
@ForgeSubscribe
|
||||
public void handleWorldLoad(WorldEvent.Load event) {
|
||||
//When a world loads clean the list of available markers
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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<TilePathMarker> availableMarkers = new LinkedList<TilePathMarker>();
|
||||
|
||||
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,25 +93,28 @@ 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();
|
||||
|
||||
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);
|
||||
|
||||
|
@ -198,7 +201,7 @@ public class TilePathMarker extends TileMarker {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue