Further progress for entity support, #1517.

This commit is contained in:
SpaceToad 2014-03-22 14:47:42 +01:00
parent 583d09d82e
commit 1af2a7ece5
16 changed files with 150 additions and 46 deletions

View file

@ -11,6 +11,11 @@ package buildcraft;
import java.io.File;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityMinecartChest;
import net.minecraft.entity.item.EntityMinecartEmpty;
import net.minecraft.entity.item.EntityMinecartFurnace;
import net.minecraft.entity.item.EntityMinecartHopper;
import net.minecraft.entity.item.EntityMinecartTNT;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@ -61,6 +66,7 @@ import buildcraft.builders.schematics.SchematicIgnore;
import buildcraft.builders.schematics.SchematicIgnoreMeta;
import buildcraft.builders.schematics.SchematicInventory;
import buildcraft.builders.schematics.SchematicLever;
import buildcraft.builders.schematics.SchematicMinecart;
import buildcraft.builders.schematics.SchematicPiston;
import buildcraft.builders.schematics.SchematicPortal;
import buildcraft.builders.schematics.SchematicPumpkin;
@ -239,6 +245,12 @@ public class BuildCraftBuilders extends BuildCraftMod {
// Standard entities
SchematicRegistry.registerSchematicEntity(EntityMinecartEmpty.class, SchematicMinecart.class);
SchematicRegistry.registerSchematicEntity(EntityMinecartFurnace.class, SchematicMinecart.class);
SchematicRegistry.registerSchematicEntity(EntityMinecartTNT.class, SchematicMinecart.class);
SchematicRegistry.registerSchematicEntity(EntityMinecartChest.class, SchematicMinecart.class);
SchematicRegistry.registerSchematicEntity(EntityMinecartHopper.class, SchematicMinecart.class);
SchematicRegistry.registerSchematicEntity(EntityItemFrame.class, SchematicHanging.class);
// BuildCraft blocks

View file

@ -16,7 +16,7 @@ public class CoordTransformation {
public double y = 0;
public double z = 0;
public Position transform (Position p) {
public Position translate (Position p) {
Position p2 = new Position (p);
p2.x = p.x + x;

View file

@ -12,6 +12,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import buildcraft.api.core.Position;
@ -25,7 +26,7 @@ public class SchematicEntity {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos = transform.transform(pos);
pos = transform.translate(pos);
cpt.setTag("Pos", this.newDoubleNBTList(new double[] {pos.x, pos.y, pos.z}));
Entity e = EntityList.createEntityFromNBT(cpt, context.world());
@ -38,12 +39,22 @@ public class SchematicEntity {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos = transform.transform(pos);
pos = transform.translate(pos);
cpt.setTag("Pos", this.newDoubleNBTList(new double[] {pos.x, pos.y, pos.z}));
}
public void rotateLeft(IBuilderContext context) {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos = context.rotatePositionLeft(pos);
cpt.setTag("Pos", this.newDoubleNBTList(new double[] {pos.x, pos.y, pos.z}));
nbttaglist = cpt.getTagList("Rotation", 5);
float yaw = nbttaglist.func_150308_e (0);
yaw += 90;
cpt.setTag("Rotation", this.newFloatNBTList(new float[] {yaw, nbttaglist.func_150308_e (1)}));
}
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
@ -55,19 +66,29 @@ public class SchematicEntity {
cpt = nbt.getCompoundTag("entity");
}
protected NBTTagList newDoubleNBTList(double ... par1ArrayOfDouble)
{
NBTTagList nbttaglist = new NBTTagList();
double[] adouble = par1ArrayOfDouble;
int i = par1ArrayOfDouble.length;
protected NBTTagList newDoubleNBTList(double... par1ArrayOfDouble) {
NBTTagList nbttaglist = new NBTTagList();
double[] adouble = par1ArrayOfDouble;
int i = par1ArrayOfDouble.length;
for (int j = 0; j < i; ++j)
{
double d1 = adouble[j];
nbttaglist.appendTag(new NBTTagDouble(d1));
}
for (int j = 0; j < i; ++j) {
double d1 = adouble[j];
nbttaglist.appendTag(new NBTTagDouble(d1));
}
return nbttaglist;
}
return nbttaglist;
}
protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) {
NBTTagList nbttaglist = new NBTTagList();
float[] afloat = par1ArrayOfFloat;
int i = par1ArrayOfFloat.length;
for (int j = 0; j < i; ++j) {
float f1 = afloat[j];
nbttaglist.appendTag(new NBTTagFloat(f1));
}
return nbttaglist;
}
}

View file

@ -20,7 +20,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
@ -39,6 +38,7 @@ import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;

View file

@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import buildcraft.BuildCraftCore;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.filler.FillerManager;
import buildcraft.api.filler.IFillerPattern;
@ -33,6 +32,7 @@ import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;

View file

@ -17,15 +17,24 @@ import buildcraft.api.core.Position;
public class SchematicHanging extends SchematicEntity {
@Override
public void writeToWorld(IBuilderContext context, CoordTransformation transform) {
/*par1NBTTagCompound.setByte("Direction", (byte)this.hangingDirection);
par1NBTTagCompound.setInteger("TileX", this.field_146063_b);
par1NBTTagCompound.setInteger("TileY", this.field_146064_c);
par1NBTTagCompound.setInteger("TileZ", this.field_146062_d);*/
public void rotateLeft(IBuilderContext context) {
super.rotateLeft(context);
Position pos = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
pos = transform.transform(pos);
pos = context.rotatePositionLeft(pos);
cpt.setInteger("TileX", (int) pos.x);
cpt.setInteger("TileY", (int) pos.y);
cpt.setInteger("TileZ", (int) pos.z);
int direction = cpt.getByte("Direction");
direction = direction < 3 ? direction + 1 : 0;
cpt.setInteger("Direction", direction);
}
@Override
public void writeToWorld(IBuilderContext context, CoordTransformation transform) {
Position pos = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
pos = transform.translate(pos);
cpt.setInteger("TileX", (int) pos.x);
cpt.setInteger("TileY", (int) pos.y);
cpt.setInteger("TileZ", (int) pos.z);
@ -38,7 +47,8 @@ public class SchematicHanging extends SchematicEntity {
super.readFromWorld(context, entity, transform);
Position pos = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
pos = transform.transform(pos);
pos = transform.translate(pos);
cpt.setInteger("TileX", (int) pos.x);
cpt.setInteger("TileY", (int) pos.y);
cpt.setInteger("TileZ", (int) pos.z);

View file

@ -0,0 +1,43 @@
/**
* 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.schematics;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagList;
import buildcraft.api.blueprints.CoordTransformation;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.core.Position;
public class SchematicMinecart extends SchematicEntity {
@Override
public void writeToWorld(IBuilderContext context, CoordTransformation transform) {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos.x += 0.5;
pos.z += 0.5;
cpt.setTag("Pos", this.newDoubleNBTList(new double[] {pos.x, pos.y, pos.z}));
super.writeToWorld(context, transform);
}
@Override
public void readFromWorld(IBuilderContext context, Entity entity, CoordTransformation transform) {
super.readFromWorld(context, entity, transform);
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos.x -= 0.5;
pos.z -= 0.5;
cpt.setTag("Pos", this.newDoubleNBTList(new double[] {pos.x, pos.y, pos.z}));
}
}

View file

@ -8,8 +8,8 @@
*/
package buildcraft.builders.urbanism;
import buildcraft.api.blueprints.BuildingSlotBlock;
import buildcraft.builders.urbanism.TileUrbanist.FrameTask;
import buildcraft.core.blueprints.BuildingSlotBlock;
import buildcraft.core.robots.AIMoveAround;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.robots.IRobotTask;

View file

@ -38,6 +38,15 @@ public class Blueprint extends BlueprintBase {
super(sizeX, sizeY, sizeZ);
}
@Override
public void rotateLeft(BptContext context) {
for (SchematicEntity e : entities) {
e.rotateLeft(context);
}
super.rotateLeft(context);
}
@Override
public void readFromWorld(IBuilderContext context, TileEntity anchorTile, int x, int y, int z) {
Block block = anchorTile.getWorldObj().getBlock(x, y, z);
@ -72,12 +81,10 @@ public class Blueprint extends BlueprintBase {
@Override
public void readEntitiesFromWorld(IBuilderContext context, TileEntity anchorTile) {
CoordTransformation transform = new CoordTransformation();
/*transform.x = -context.surroundingBox().pMin().x;
transform.x = -context.surroundingBox().pMin().x;
transform.y = -context.surroundingBox().pMin().y;
transform.z = -context.surroundingBox().pMin().z;*/
transform.x = -anchorTile.xCoord;
transform.y = -anchorTile.yCoord;
transform.z = -anchorTile.zCoord;
transform.z = -context.surroundingBox().pMin().z;
for (Object o : context.world().loadedEntityList) {
Entity e = (Entity) o;

View file

@ -10,7 +10,6 @@ package buildcraft.core.blueprints;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.core.IAreaProvider;
import buildcraft.core.Box;
import buildcraft.core.IBuilderInventory;

View file

@ -20,15 +20,12 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.blueprints.BuildingSlotBlock;
import buildcraft.api.blueprints.BuildingSlotBlock.Mode;
import buildcraft.api.blueprints.BuildingSlotEntity;
import buildcraft.api.blueprints.CoordTransformation;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.core.StackKey;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.BlockUtil;
@ -105,9 +102,10 @@ public class BptBuilderBlueprint extends BptBuilderBase {
}
CoordTransformation transform = new CoordTransformation();
transform.x = x;
transform.y = y;
transform.z = z;
transform.x = x - blueprint.anchorX;
transform.y = y - blueprint.anchorY;
transform.z = z - blueprint.anchorZ;
for (SchematicEntity e : bluePrint.entities) {
BuildingSlotEntity b = new BuildingSlotEntity();

View file

@ -11,12 +11,10 @@ package buildcraft.core.blueprints;
import java.util.LinkedList;
import net.minecraft.world.World;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.blueprints.BuildingSlotBlock;
import buildcraft.api.blueprints.BuildingSlotBlock.Mode;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
public class BptBuilderTemplate extends BptBuilderBase {

View file

@ -6,10 +6,11 @@
* 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.api.blueprints;
package buildcraft.core.blueprints;
import java.util.LinkedList;
import buildcraft.api.blueprints.IBuilderContext;
import net.minecraft.item.ItemStack;
public class BuildingSlot {

View file

@ -1,7 +1,18 @@
package buildcraft.api.blueprints;
/**
* 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.blueprints;
import java.util.LinkedList;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicMask;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

View file

@ -6,7 +6,11 @@
* 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.api.blueprints;
package buildcraft.core.blueprints;
import buildcraft.api.blueprints.CoordTransformation;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicEntity;
public class BuildingSlotEntity extends BuildingSlot {

View file

@ -27,7 +27,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.blueprints.BuildingSlot;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerReceptor;
@ -41,6 +40,7 @@ import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;