Horrible nasty stuffs.

This commit is contained in:
CrazyPants committed 2014-10-24 16:12:21 +08:00
1 parent c999c81865
commit 31d7a26aa9
1 file changed
+95 -19
@@ -7,32 +7,49 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import crazypants.enderio.Log;
import crazypants.enderio.TileEntityEio;
import crazypants.util.BlockCoord;
import crazypants.util.EntityUtil;
import crazypants.util.ForgeDirectionOffsets;
import crazypants.util.MetadataUtil;
import crazypants.vecmath.Vector3d;
import mods.railcraft.api.carts.CartTools;
import mods.railcraft.api.carts.ILinkageManager;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEnderRail extends TileEntity {
public class TileEnderRail extends TileEntityEio {
//keep track of which carts we have received have left the track as they can't be teleported again until they have
private final Set<EntityMinecart> newlySpawnedCarts = new HashSet<EntityMinecart>();
private final LinkedList<List<Entity>> entitiesToSpawn = new LinkedList<List<Entity>>();
private final LinkedList<List<Entity>> cartsToSpawn = new LinkedList<List<Entity>>();
private int ticksFailedToSpawn = 0;
// private NBTTagList cartList;
public TileEnderRail() {
}
@Override
public void updateEntity() {
// if(cartList != null) {
// loadCartsToSpawn();
// cartList = null;
// }
spawnRecievedCart();
List<EntityMinecart> carts = getMinecartsAt(getWorldObj(), xCoord, yCoord, zCoord);
@@ -48,7 +65,8 @@ public class TileEnderRail extends TileEntity {
}
private void spawnRecievedCart() {
if(entitiesToSpawn.isEmpty()) {
// System.out.println("TileEnderRail.spawnRecievedCart: " + cartsToSpawn.size() + ":" + new BlockCoord(this));
if(cartsToSpawn.isEmpty()) {
ticksFailedToSpawn = 0;
return;
}
@@ -58,8 +76,9 @@ public class TileEnderRail extends TileEntity {
return;
}
}
System.out.println("TileEnderRail.spawnRecievedCart: " + cartsToSpawn);
List<Entity> spawnThisTick = entitiesToSpawn.removeFirst();
List<Entity> spawnThisTick = cartsToSpawn.removeFirst();
for(Entity ent : spawnThisTick) {
TeleportUtil.spawn(getWorldObj(), ent);
if(ent instanceof EntityMinecart) {
@@ -72,16 +91,18 @@ public class TileEnderRail extends TileEntity {
}
public boolean isReverse() {
return BlockEnderRail.isReverse(getBlockMetadata());
}
// public boolean isReverse() {
// return BlockEnderRail.isReverse(getBlockMetadata());
// }
//
// public ForgeDirection getDirection() {
// return BlockEnderRail.getDirection(getBlockMetadata());
// }
public ForgeDirection getDirection() {
return BlockEnderRail.getDirection(getBlockMetadata());
}
public void onTrainRecieved(List<List<Entity>> toTeleport) {
entitiesToSpawn.addAll(toTeleport);
public void onTrainRecieved(List<List<Entity>> toTeleport) {
// System.out.println("TileEnderRail.onTrainRecieved: " + toTeleport.size() + ":" + System.identityHashCode(this) + ":" + new BlockCoord(this));
cartsToSpawn.addAll(toTeleport);
// System.out.println("TileEnderRail.onTrainRecieved: Carts to spawn now " + cartsToSpawn.size() + ":" + new BlockCoord(this));
}
public boolean isRecievedCart(EntityMinecart mc) {
@@ -99,10 +120,6 @@ public class TileEnderRail extends TileEntity {
return res == null || res.isEmpty();
}
@Override
public void onChunkUnload() {
}
public List<EntityMinecart> getCartsOnTrack() {
return getMinecartsAt(getWorldObj(), xCoord, yCoord + 1, zCoord);
}
@@ -121,12 +138,71 @@ public class TileEnderRail extends TileEntity {
// @Override
// public void readFromNBT(NBTTagCompound root) {
// super.readFromNBT(root);
//
// super.readFromNBT(root);
// cartsToSpawn.clear();
// if(!root.hasKey("cartList")) {
// System.out.println("TileEnderRail.readFromNBT: No cart list found");
// return;
// }
// cartList = (NBTTagList)root.getTag("cartList");
// System.out.println("TileEnderRail.readFromNBT: read cart list with " + cartList.tagCount() + " entries");
// }
//
// private void loadCartsToSpawn() {
// System.out.println("TileEnderRail.loadCartsToSpawn: Loading carts to spawn: " + cartList.tagCount());
// while(cartList.tagCount() > 0) {
// NBTTagList entityList = (NBTTagList)cartList.removeTag(0);
// System.out.println("TileEnderRail.loadCartsToSpawn: Entity list size: " + entityList.tagCount());
// List<Entity> ents = new ArrayList<Entity>(entityList.tagCount());
// for(int i=0;i < entityList.tagCount();i++) {
// NBTTagCompound entityRoot = entityList.getCompoundTagAt(i);
// Entity entity = EntityList.createEntityFromNBT(entityRoot, worldObj);
// if(entity != null) {
// ents.add(entity);
// System.out.println("TileEnderRail.loadCartsToSpawn: Added entity to list: " + entity);
// } else {
// System.out.println("TileEnderRail.loadCartsToSpawn: Null emtity");
// }
// }
// cartsToSpawn.add(ents);
// }
// }
// @Override
// public void writeToNBT(NBTTagCompound root) {
// super.writeToNBT(root);
// if(cartsToSpawn.isEmpty()) {
// return;
// }
// NBTTagList cartList = new NBTTagList();
//
// for(List<Entity> entsInCart : cartsToSpawn) {
// if(entsInCart != null && !entsInCart.isEmpty()) {
// NBTTagList entityList = new NBTTagList();
// cartList.appendTag(entityList);
// for(Entity entity : entsInCart) {
// NBTTagCompound entRoot = new NBTTagCompound();
// entRoot.setString("id", EntityList.getEntityString(entity));
// entity.writeToNBT(entRoot);
// entityList.appendTag(entRoot);
// }
// }
// }
// root.setTag("cartList", cartList);
// System.out.println("TileEnderRail.writeToNBT: Wrote out a cart list with " + cartList.tagCount() + " carts");
// }
@Override
protected void writeCustomNBT(NBTTagCompound root) {
// TODO Auto-generated method stub
}
@Override
protected void readCustomNBT(NBTTagCompound root) {
// TODO Auto-generated method stub
}
}