implemented synchronization of box kind

This commit is contained in:
SpaceToad 2014-02-20 09:31:33 +01:00
parent 84d3cd6948
commit 880fc11c4f
4 changed files with 66 additions and 10 deletions

View file

@ -19,11 +19,23 @@ public class AnchoredBox {
@NetworkData
public float x1, y1, z1;
public enum Kind {
LASER_RED,
LASER_YELLOW,
LASER_GREEN,
LASER_BLUE,
STRIPES
}
@NetworkData
public Kind kind = Kind.LASER_RED;
public void setP2 (float x2, float y2, float z2) {
box.initialize(x1, y1, z1, x2, y2, z2);
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setByte("kind", (byte) kind.ordinal());
nbt.setFloat("anchorX", x1);
nbt.setFloat("anchorY", y1);
nbt.setFloat("anchorZ", z1);
@ -32,6 +44,7 @@ public class AnchoredBox {
}
public void readFromNBT(NBTTagCompound nbt) {
kind = Kind.values() [nbt.getShort("kind")];
x1 = nbt.getFloat("anchorX");
y1 = nbt.getFloat("anchorY");
z1 = nbt.getFloat("anchorZ");

View file

@ -19,7 +19,11 @@ import buildcraft.core.render.RenderBox;
public class RenderUrbanist extends TileEntitySpecialRenderer {
private static final ResourceLocation CHAMBER_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/chamber2.png");
private static final ResourceLocation LASER_RED = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png");
private static final ResourceLocation LASER_YELLOW = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_2.png");
private static final ResourceLocation LASER_GREEN = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_3.png");
private static final ResourceLocation LASER_BLUE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_4.png");
private static final ResourceLocation STRIPES = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/stripes.png");
public RenderUrbanist() {
}
@ -38,7 +42,28 @@ public class RenderUrbanist extends TileEntitySpecialRenderer {
for (AnchoredBox b : urbanist.frames) {
GL11.glPushMatrix();
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
RenderBox.doRender(TileEntityRendererDispatcher.instance.field_147553_e, b.box, x, y, z, f, 0);
ResourceLocation texture = LASER_RED;
switch (b.kind) {
case LASER_RED:
texture = LASER_RED;
break;
case LASER_YELLOW:
texture = LASER_YELLOW;
break;
case LASER_GREEN:
texture = LASER_GREEN;
break;
case LASER_BLUE:
texture = LASER_BLUE;
break;
case STRIPES:
texture = STRIPES;
break;
}
RenderBox.doRender(TileEntityRendererDispatcher.instance.field_147553_e, texture, b.box, x, y, z, f, 0);
GL11.glPopMatrix();
}

View file

@ -23,6 +23,7 @@ import net.minecraft.util.AxisAlignedBB;
import buildcraft.builders.blueprints.BlueprintBuilder;
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
import buildcraft.builders.filler.pattern.FillerPattern;
import buildcraft.builders.urbanism.AnchoredBox.Kind;
import buildcraft.core.Box;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.NetworkData;
@ -110,6 +111,8 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
p2y = y;
p2z = z;
// TODO: this is OK in SMP, but the frame actually needs to be
// broadcasted to all players
createFrame(x, y, z);
RPCHandler.rpcServer(this, "createFrame", x, y, z);
}
@ -127,6 +130,8 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
p2y = y;
p2z = z;
// TODO: this is OK in SMP, but the frame actually needs to be
// broadcasted to all players
moveFrame(x, y, z);
RPCHandler.rpcServer(this, "moveFrame", x, y, z);
}
@ -134,13 +139,25 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
public class FrameTask {
int nbOfTasks;
//EntityFrame frame;
AnchoredBox frame;
public void taskDone () {
nbOfTasks--;
if (nbOfTasks <= 0) {
// frame.setDead();
frames.remove(frame);
}
}
}
@RPC (RPCSide.CLIENT)
public void setFrameKind (int id, int kind) {
if (id < frames.size()) {
AnchoredBox b = frames.get(id);
if (b != null) {
System.out.println ("SWITCH " + id + " TO " + kind);
b.kind = Kind.values()[kind];
}
}
}
@ -160,8 +177,12 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
newFrame.setKind(Kind.STRIPES);
worldObj.spawnEntityInWorld(newFrame);
*/
FrameTask task = new FrameTask();
//task.frame = newFrame;
task.frame = frames.get(frames.size() - 1);
task.frame.kind = Kind.STRIPES;
RPCHandler.rpcBroadcastPlayers(this, "setFrameKind", frames.size() - 1,
Kind.STRIPES.ordinal());
for (SchematicBuilder b : schematics) {
if (!b.isComplete()) {

View file

@ -14,14 +14,11 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import buildcraft.core.Box;
import buildcraft.core.DefaultProps;
import buildcraft.core.LaserData;
public class RenderBox {
private static final ResourceLocation LASER_TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png");
public static void doRender(TextureManager t, Box box, double x, double y, double z, float f, float f1) {
public static void doRender(TextureManager t, ResourceLocation texture, Box box, double x, double y, double z, float f, float f1) {
GL11.glPushMatrix();
GL11.glDisable(2896 /* GL_LIGHTING */);
GL11.glTranslated(x, y, z);
@ -32,7 +29,7 @@ public class RenderBox {
l.update();
GL11.glPushMatrix();
GL11.glTranslated(l.head.x, l.head.y, l.head.z);
RenderLaser.doRenderLaser(t, l, LASER_TEXTURE);
RenderLaser.doRenderLaser(t, l, texture);
GL11.glPopMatrix();
}