made progress in path marker implementation, for #1490

This commit is contained in:
SpaceToad 2014-03-15 16:59:47 +01:00
parent f7c5c1cbae
commit b4bd4c1e08
12 changed files with 191 additions and 173 deletions

View file

@ -49,7 +49,6 @@ import buildcraft.core.CoreIconProvider;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.DefaultProps;
import buildcraft.core.EntityEnergyLaser;
import buildcraft.core.EntityPowerLaser;
import buildcraft.core.InterModComms;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.ItemRobot;
@ -304,10 +303,8 @@ public class BuildCraftCore extends BuildCraftMod {
EntityRegistry.registerModEntity(EntityRobotPicker.class, "bcRobotPicker", EntityIds.ROBOT_PICKER, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityRobotBuilder.class, "bcRobotBuilder", EntityIds.ROBOT_BUILDER, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityRobotUrbanism.class, "bcRobotUrbanism", EntityIds.ROBOT_URBANISM, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityPowerLaser.class, "bcLaser", EntityIds.LASER, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityEnergyLaser.class, "bcEnergyLaser", EntityIds.ENERGY_LASER, instance, 50, 1, true);
EntityList.classToStringMapping.remove(EntityRobotBuilder.class);
EntityList.classToStringMapping.remove(EntityPowerLaser.class);
EntityList.classToStringMapping.remove(EntityEnergyLaser.class);
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcRobot");
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser");

View file

@ -11,10 +11,14 @@ package buildcraft.api.core;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.core.network.NetworkData;
public class Position {
@NetworkData
public double x, y, z;
@NetworkData
public ForgeDirection orientation;
public Position(double ci, double cj, double ck) {

View file

@ -48,11 +48,13 @@ public class BlockBuilder extends BlockContainer {
@Override
public IIcon getIcon(int i, int j) {
if (j == 0 && i == 3)
if (j == 0 && i == 3) {
return blockTextureFront;
}
if (i == j)
if (i == j) {
return blockTextureFront;
}
switch (i) {
case 1:
@ -66,8 +68,9 @@ public class BlockBuilder extends BlockContainer {
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
// Drop through if the player is sneaking
if (entityplayer.isSneaking())
if (entityplayer.isSneaking()) {
return false;
}
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
@ -92,14 +95,14 @@ public class BlockBuilder extends BlockContainer {
world.markBlockForUpdate(i, j, k);
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
return true;
} else {
if (!world.isRemote) {
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BUILDER, world, i, j, k);
}
return true;
return true;
}
}

View file

@ -25,5 +25,6 @@ public class BuilderProxyClient extends BuilderProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker());
}
}

View file

@ -0,0 +1,72 @@
/**
* 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.builders;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import buildcraft.core.DefaultProps;
import buildcraft.core.EntityLaser;
import buildcraft.core.LaserData;
import buildcraft.core.render.RenderLaser;
public class RenderPathMarker extends TileEntitySpecialRenderer {
private ModelBase model = new ModelBase() {
};
private ModelRenderer box;
private static final ResourceLocation CHAMBER_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/chamber2.png");
public RenderPathMarker() {
box = new ModelRenderer(model, 0, 1);
box.addBox(-8F, -8F, -8F, 16, 4, 16);
box.rotationPointX = 8;
box.rotationPointY = 8;
box.rotationPointZ = 8;
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
TilePathMarker marker = (TilePathMarker) tileentity;
if (marker != null) {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslated(x, y, z);
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
for (LaserData laser : marker.lasers) {
if (laser != null) {
GL11.glPushMatrix();
RenderLaser
.doRenderLaser(
TileEntityRendererDispatcher.instance.field_147553_e,
laser, EntityLaser.LASER_TEXTURES[3]);
GL11.glPopMatrix();
}
}
//GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}

View file

@ -21,19 +21,17 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.SchematicToBuild;
import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.BlockIndex;
import buildcraft.core.Box;
import buildcraft.core.Box.Kind;
import buildcraft.core.EntityLaser;
import buildcraft.core.IBoxProvider;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.IMachine;
import buildcraft.core.LaserData;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
@ -48,8 +46,7 @@ import buildcraft.core.network.RPCSide;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.Utils;
public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
IPowerReceptor, IMachine, IBoxProvider {
public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IMachine, IBoxProvider {
private final ItemStack items[] = new ItemStack[28];
@ -58,11 +55,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
@NetworkData
public Box box = new Box();
private PowerHandler powerHandler;
private LinkedList<BlockIndex> path;
private LinkedList<EntityLaser> pathLasers;
@NetworkData
private LinkedList<LaserData> pathLasers;
private EntityRobot builderRobot;
@ -70,6 +66,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
private SafeTimeTracker debugBuildTracker = new SafeTimeTracker(5);
@MjBattery (maxReceivedPerCycle = 25)
public double mjStored = 0;
private class PathIterator {
public Iterator<BlockIndex> currentIterator;
@ -192,9 +191,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
public TileBuilder() {
super();
powerHandler = new PowerHandler(this, Type.MACHINE);
powerHandler.configure(25, 25, 25, 25);
box.kind = Kind.STRIPES;
}
@ -240,22 +236,20 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
}
public void createLasersForPath() {
/*pathLasers = new LinkedList<EntityLaser>();
pathLasers = new LinkedList<LaserData>();
BlockIndex previous = null;
for (BlockIndex b : path) {
if (previous != null) {
EntityPowerLaser laser = new EntityPowerLaser(worldObj, new Position(previous.i + 0.5, previous.j + 0.5, previous.k + 0.5), new Position(
LaserData laser = new LaserData(new Position(previous.x + 0.5,
previous.y + 0.5, previous.z + 0.5), new Position(
b.x + 0.5, b.y + 0.5, b.z + 0.5));
laser.setTexture(DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png");
laser.show();
worldObj.spawnEntityInWorld(laser);
pathLasers.add(laser);
}
previous = b;
}*/
}
}
public BptBuilderBase instanciateBluePrint(int x, int y, int z, ForgeDirection o) {
@ -302,41 +296,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
return result;
}
@Override
public void doWork(PowerHandler workProvider) {
if (worldObj.isRemote) {
return;
}
if (done) {
return;
//}// else if (builderRobot != null && !builderRobot.readyToBuild()) {
// return;
} else if (powerHandler.useEnergy(25, 25, true) < 25) {
return;
}
iterateBpt();
/* Temp fix to make Builders impotent as the World Destroyers they are
if (bluePrintBuilder != null && !bluePrintBuilder.done) {
if (!box.isInitialized()) {
box.initialize(bluePrintBuilder);
}
if (builderRobot == null) {
builderRobot = new EntityRobot(worldObj, box);
worldObj.spawnEntityInWorld(builderRobot);
}
box.createLasers(worldObj, LaserKind.Stripes);
builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)),
bluePrintBuilder.getContext());
}
*/
}
public void iterateBpt() {
if (items[0] == null || !(items[0].getItem() instanceof ItemBlueprint)) {
if (bluePrintBuilder != null) {
@ -543,8 +502,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
builderRobot.setDead();
builderRobot = null;
}
cleanPathLasers();
}
@Override
@ -579,9 +536,42 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
builderRobot = null;
}
if (!worldObj.isRemote) {
debugForceBlueprintCompletion();
if (worldObj.isRemote) {
return;
}
iterateBpt();
debugForceBlueprintCompletion();
if (done) {
return;
//}// else if (builderRobot != null && !builderRobot.readyToBuild()) {
// return;
} else if (mjStored < 25) {
return;
}
/* Temp fix to make Builders impotent as the World Destroyers they are
if (bluePrintBuilder != null && !bluePrintBuilder.done) {
if (!box.isInitialized()) {
box.initialize(bluePrintBuilder);
}
if (builderRobot == null) {
builderRobot = new EntityRobot(worldObj, box);
worldObj.spawnEntityInWorld(builderRobot);
}
box.createLasers(worldObj, LaserKind.Stripes);
builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)),
bluePrintBuilder.getContext());
}
*/
mjStored = 0;
}
@Override
@ -599,16 +589,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
return true;
}
public void cleanPathLasers() {
if (pathLasers != null) {
for (EntityLaser laser : pathLasers) {
laser.setDead();
}
pathLasers = null;
}
}
public boolean isBuildingBlueprint() {
return getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint;
}
@ -674,11 +654,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
return new Box (this).extendToEncompass(box).getBoundingBox();
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerHandler.getPowerReceiver();
}
public void debugForceBlueprintCompletion () {
if (!debugBuildTracker.markTimeIfDelay(worldObj)) {
return;

View file

@ -8,15 +8,6 @@
*/
package buildcraft.builders;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.core.Position;
import buildcraft.core.BlockIndex;
import buildcraft.core.EntityLaser;
import buildcraft.core.EntityPowerLaser;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.NetworkData;
import buildcraft.core.proxy.CoreProxy;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
@ -25,18 +16,30 @@ import java.util.TreeSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.api.core.Position;
import buildcraft.core.BlockIndex;
import buildcraft.core.LaserData;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.PacketUpdate;
public class TilePathMarker extends TileMarker {
public EntityLaser lasers[] = new EntityLaser[2];
public int x0, y0, z0, x1, y1, z1;
public boolean loadLink0 = false, loadLink1 = false;
public @NetworkData
boolean tryingToConnect = false;
@NetworkData
public LaserData lasers[] = new LaserData [2];
@NetworkData
public boolean tryingToConnect = false;
public TilePathMarker links[] = new TilePathMarker[2];
public static int searchSize = 64; // TODO: this should be moved to default props
// TODO: this should be moved to default props
// A list with the pathMarkers that aren't fully connected
// It only contains markers within the loaded chunks
public static int searchSize = 64;
private static LinkedList<TilePathMarker> availableMarkers = new LinkedList<TilePathMarker>();
public boolean isFullyConnected() {
@ -47,7 +50,7 @@ public class TilePathMarker extends TileMarker {
return links[0] == pathMarker || links[1] == pathMarker;
}
public void connect(TilePathMarker marker, EntityLaser laser) {
public void connect(TilePathMarker marker, LaserData laser) {
if (lasers[0] == null) {
lasers[0] = laser;
links[0] = marker;
@ -62,26 +65,29 @@ public class TilePathMarker extends TileMarker {
}
public void createLaserAndConnect(TilePathMarker pathMarker) {
if (worldObj.isRemote) {
return;
}
EntityPowerLaser 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();
LaserData laser = new LaserData
(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.setTexture(0);
worldObj.spawnEntityInWorld(laser);
LaserData laser2 = new LaserData (laser.head, laser.tail);
laser2.isVisible = false;
connect(pathMarker, laser);
pathMarker.connect(this, laser);
pathMarker.connect(this, laser2);
}
// Searches the availableMarkers list for the nearest available that is within searchSize
/**
* Searches the availableMarkers list for the nearest available that is
* within searchSize
*/
private TilePathMarker findNearestAvailablePathMarker() {
TilePathMarker nearestAvailable = null;
double nearestDistance = 0, distance; // The initialization of nearestDistance is only to make the compiler shut up
// The initialization of nearestDistance is only to make the compiler shut up
double nearestDistance = 0, distance;
for (TilePathMarker t : availableMarkers) {
if (t == this || t == this.links[0] || t == this.links[1] || t.getWorldObj().provider.dimensionId != this.getWorldObj().provider.dimensionId) {
@ -110,7 +116,9 @@ public class TilePathMarker extends TileMarker {
return;
}
tryingToConnect = !tryingToConnect; // Allow the user to stop the path marker from searching for new path markers to connect
// Allow the user to stop the path marker from searching for new path markers to connect
tryingToConnect = !tryingToConnect;
sendNetworkUpdate();
}
@ -127,9 +135,13 @@ public class TilePathMarker extends TileMarker {
if (nearestPathMarker != null) {
createLaserAndConnect(nearestPathMarker);
tryingToConnect = false;
sendNetworkUpdate();
}
tryingToConnect = false;
sendNetworkUpdate();
getWorld().markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord,
xCoord, yCoord, zCoord);
}
}
@ -164,14 +176,12 @@ public class TilePathMarker extends TileMarker {
public void invalidate() {
super.invalidate();
if (lasers[0] != null) {
if (links[0] != null) {
links[0].unlink(this);
lasers[0].setDead();
}
if (lasers[1] != null) {
if (links[1] != null) {
links[1].unlink(this);
lasers[1].setDead();
}
availableMarkers.remove(this);
@ -205,6 +215,8 @@ public class TilePathMarker extends TileMarker {
loadLink1 = false;
}
sendNetworkUpdate();
}
private void unlink(TilePathMarker tile) {
@ -221,6 +233,8 @@ public class TilePathMarker extends TileMarker {
if (!isFullyConnected() && !availableMarkers.contains(this) && !worldObj.isRemote) {
availableMarkers.add(this);
}
sendNetworkUpdate();
}
@Override

View file

@ -1,54 +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.core;
import buildcraft.api.core.Position;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class EntityPowerLaser extends EntityLaser {
private byte texture;
public EntityPowerLaser(World world) {
super(world);
}
public EntityPowerLaser(World world, Position head, Position tail) {
super(world, head, tail);
}
@Override
protected void entityInit() {
super.entityInit();
dataWatcher.addObject(15, (byte) 0);
}
@Override
public ResourceLocation getTexture() {
return LASER_TEXTURES[texture];
}
public void setTexture(int texture) {
this.texture = (byte) texture;
needsUpdate = true;
}
@Override
protected void updateDataClient() {
super.updateDataClient();
texture = dataWatcher.getWatchableObjectByte(15);
}
@Override
protected void updateDataServer() {
super.updateDataServer();
dataWatcher.updateObject(15, texture);
}
}

View file

@ -10,13 +10,18 @@ package buildcraft.core;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.core.Position;
import buildcraft.core.network.NetworkData;
public class LaserData {
@NetworkData
public Position head = new Position (0, 0, 0), tail = new Position(0, 0, 0);
@NetworkData
public boolean isVisible = true;
public double renderSize = 0;
public double angleY = 0;
public double angleZ = 0;
public boolean isVisible = true;
public double wavePosition = 0;
public int laserTexAnimation = 0;

View file

@ -30,10 +30,8 @@ import buildcraft.BuildCraftCore;
import buildcraft.api.core.LaserKind;
import buildcraft.core.EntityBlock;
import buildcraft.core.EntityEnergyLaser;
import buildcraft.core.EntityPowerLaser;
import buildcraft.core.render.RenderEnergyLaser;
import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderLaser;
import buildcraft.core.render.RenderRobot;
import buildcraft.core.render.RenderingEntityBlocks;
import buildcraft.core.render.RenderingMarkers;
@ -73,16 +71,18 @@ public class CoreProxyClient extends CoreProxy {
@SuppressWarnings("rawtypes")
@Override
public void feedSubBlocks(Block block, CreativeTabs tab, List itemList) {
if (block == null)
if (block == null) {
return;
}
block.getSubBlocks(Item.getItemFromBlock(block), tab, itemList);
}
@Override
public String getItemDisplayName(ItemStack stack) {
if (stack.getItem() == null)
if (stack.getItem() == null) {
return "";
}
return stack.getDisplayName();
}
@ -111,7 +111,6 @@ public class CoreProxyClient extends CoreProxy {
@Override
public void initializeEntityRendering() {
RenderingRegistry.registerEntityRenderingHandler(EntityBlock.class, RenderEntityBlock.INSTANCE);
RenderingRegistry.registerEntityRenderingHandler(EntityPowerLaser.class, new RenderLaser());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyLaser.class, new RenderEnergyLaser());
RenderingRegistry.registerEntityRenderingHandler(EntityRobot.class, new RenderRobot());
RenderingRegistry.registerEntityRenderingHandler(EntityRobotBuilder.class, new RenderRobot());

View file

@ -27,7 +27,7 @@ public class RenderBox {
for (LaserData l : box.lasersData) {
l.update();
GL11.glPushMatrix();
GL11.glTranslated(l.head.x + 0.5F, l.head.y + 0.5F, l.head.z + 0.5F);
GL11.glTranslated(0.5F, 0.5F, 0.5F);
RenderLaser.doRenderLaser(t, l, texture);
GL11.glPopMatrix();
}

View file

@ -99,8 +99,9 @@ public class RenderLaser extends Render {
}
private void doRender(EntityLaser laser, double x, double y, double z, float f, float f1) {
if (!laser.isVisible() || laser.getTexture() == null)
if (!laser.isVisible() || laser.getTexture() == null) {
return;
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
@ -166,6 +167,7 @@ public class RenderLaser extends Render {
GL11.glPushMatrix();
GL11.glTranslated(laser.head.x, laser.head.y, laser.head.z);
laser.update();
GL11.glRotatef((float) laser.angleZ, 0, 1, 0);