Got more things working!

This commit is contained in:
Aidan C. Brady 2013-10-22 11:08:28 -04:00
parent c7dcea6a06
commit 89eda12200
6 changed files with 76 additions and 42 deletions

View file

@ -35,7 +35,7 @@ public class RenderLogisticalTransporter extends TileEntitySpecialRenderer
public void renderAModelAt(TileEntityLogisticalTransporter tileEntity, double x, double y, double z, float partialTick) public void renderAModelAt(TileEntityLogisticalTransporter tileEntity, double x, double y, double z, float partialTick)
{ {
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "LogisticalTransporter" + (tileEntity.isActive ? "Active" : "") + ".png")); bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "LogisticalTransporter.png"));
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F); GL11.glScalef(1.0F, -1F, -1F);

View file

@ -294,7 +294,7 @@ public final class TransporterPathfinder
return p.getPath(); return p.getPath();
} }
public static List<Object3D> getIdlePath(TileEntityLogisticalTransporter start, Object3D home, Object3D prevHome) public static List<Object3D> getIdlePath(TileEntityLogisticalTransporter start)
{ {
IdleDest d = new IdleDest(start.worldObj, start); IdleDest d = new IdleDest(start.worldObj, start);
Object3D farthest = d.find(); Object3D farthest = d.find();
@ -304,7 +304,7 @@ public final class TransporterPathfinder
return null; return null;
} }
Path p = new Path(start.worldObj, prevHome, Object3D.get(start), null); Path p = new Path(start.worldObj, farthest, Object3D.get(start), null);
return p.getPath(); return p.getPath();
} }
} }

View file

@ -28,6 +28,8 @@ public class TransporterStack
public boolean noTarget = false; public boolean noTarget = false;
public boolean clientFirstTick = true;
public void write(TileEntityLogisticalTransporter tileEntity, ArrayList data) public void write(TileEntityLogisticalTransporter tileEntity, ArrayList data)
{ {
data.add(progress); data.add(progress);
@ -72,7 +74,7 @@ public class TransporterStack
itemStack.writeToNBT(nbtTags); itemStack.writeToNBT(nbtTags);
} }
public void read(NBTTagCompound nbtTags) public void readFromNBT(NBTTagCompound nbtTags)
{ {
progress = nbtTags.getInteger("progress"); progress = nbtTags.getInteger("progress");
originalLocation = Object3D.read(nbtTags); originalLocation = Object3D.read(nbtTags);
@ -80,6 +82,14 @@ public class TransporterStack
itemStack = ItemStack.loadItemStackFromNBT(nbtTags); itemStack = ItemStack.loadItemStackFromNBT(nbtTags);
} }
public static TransporterStack read(NBTTagCompound nbtTags)
{
TransporterStack stack = new TransporterStack();
stack.readFromNBT(nbtTags);
return stack;
}
public boolean hasPath() public boolean hasPath()
{ {
return pathToTarget != null; return pathToTarget != null;
@ -104,7 +114,7 @@ public class TransporterStack
public void calculateIdle(TileEntityLogisticalTransporter tileEntity) public void calculateIdle(TileEntityLogisticalTransporter tileEntity)
{ {
pathToTarget = TransporterPathfinder.getIdlePath(tileEntity, originalLocation, pathToTarget.get(pathToTarget.size()-1)); pathToTarget = TransporterPathfinder.getIdlePath(tileEntity);
noTarget = true; noTarget = true;
originalLocation = Object3D.get(tileEntity); originalLocation = Object3D.get(tileEntity);
initiatedPath = true; initiatedPath = true;

View file

@ -59,13 +59,6 @@ public class ItemConfigurator extends ItemEnergized
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList()))); PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())));
return true; return true;
} }
else if(world.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalTransporter)
{
TileEntityLogisticalTransporter tileEntity = (TileEntityLogisticalTransporter)world.getBlockTileEntity(x, y, z);
tileEntity.isActive = !tileEntity.isActive;
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())));
return true;
}
else if(world.getBlockTileEntity(x, y, z) instanceof TileEntityElectricPump) else if(world.getBlockTileEntity(x, y, z) instanceof TileEntityElectricPump)
{ {
TileEntityElectricPump tileEntity = (TileEntityElectricPump)world.getBlockTileEntity(x, y, z); TileEntityElectricPump tileEntity = (TileEntityElectricPump)world.getBlockTileEntity(x, y, z);

View file

@ -18,6 +18,7 @@ import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -29,16 +30,27 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityLogisticalTransporter extends TileEntityTransmitter<InventoryNetwork> implements ITileNetwork public class TileEntityLogisticalTransporter extends TileEntityTransmitter<InventoryNetwork> implements ITileNetwork
{ {
/** This transporter's active state. */
public boolean isActive = false;
public Set<TransporterStack> transit = new HashSet<TransporterStack>(); public Set<TransporterStack> transit = new HashSet<TransporterStack>();
public boolean needsSync = false;
@Override @Override
public void updateEntity() public void updateEntity()
{ {
if(!worldObj.isRemote) if(worldObj.isRemote)
{ {
for(TransporterStack stack : transit)
{
if(stack.clientFirstTick)
{
stack.clientFirstTick = false;
}
else {
stack.progress++;
}
}
}
else {
Set<TransporterStack> remove = new HashSet<TransporterStack>(); Set<TransporterStack> remove = new HashSet<TransporterStack>();
for(TransporterStack stack : transit) for(TransporterStack stack : transit)
@ -66,6 +78,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
{ {
if(next != null && next.getTileEntity(worldObj) instanceof TileEntityLogisticalTransporter) if(next != null && next.getTileEntity(worldObj) instanceof TileEntityLogisticalTransporter)
{ {
needsSync = true;
TileEntityLogisticalTransporter nextTile = (TileEntityLogisticalTransporter)next.getTileEntity(worldObj); TileEntityLogisticalTransporter nextTile = (TileEntityLogisticalTransporter)next.getTileEntity(worldObj);
nextTile.entityEntering(stack); nextTile.entityEntering(stack);
remove.add(stack); remove.add(stack);
@ -78,6 +91,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
{ {
if(next != null && next.getTileEntity(worldObj) instanceof IInventory) if(next != null && next.getTileEntity(worldObj) instanceof IInventory)
{ {
needsSync = true;
IInventory inventory = (IInventory)next.getTileEntity(worldObj); IInventory inventory = (IInventory)next.getTileEntity(worldObj);
if(inventory != null) if(inventory != null)
@ -104,6 +118,9 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
remove.add(stack); remove.add(stack);
continue; continue;
} }
else {
stack.progress = 50;
}
} }
else if(stack.progress == 50) else if(stack.progress == 50)
{ {
@ -152,12 +169,18 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
System.out.println(Object3D.get(this) + " " + stack.progress); System.out.println(Object3D.get(this) + " " + stack.progress);
} }
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getItemPacket(new ArrayList())), Object3D.get(this), 50D); if(needsSync)
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 50D);
needsSync = false;
}
} }
} }
private boolean recalculate(TransporterStack stack) private boolean recalculate(TransporterStack stack)
{ {
needsSync = true;
if(!stack.recalculatePath(this)) if(!stack.recalculatePath(this))
{ {
stack.calculateIdle(this); stack.calculateIdle(this);
@ -174,6 +197,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
public boolean insert(Object3D original, ItemStack itemStack) public boolean insert(Object3D original, ItemStack itemStack)
{ {
needsSync = true;
TransporterStack stack = new TransporterStack(); TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack; stack.itemStack = itemStack;
stack.originalLocation = original; stack.originalLocation = original;
@ -192,6 +216,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
{ {
stack.progress = 0; stack.progress = 0;
transit.add(stack); transit.add(stack);
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 50D);
} }
@Override @Override
@ -294,36 +319,22 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
@Override @Override
public void handlePacketData(ByteArrayDataInput dataStream) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
if(dataStream.readInt() == 0) transit.clear();
int amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{ {
isActive = dataStream.readBoolean(); TransporterStack stack = new TransporterStack();
} stack.read(dataStream);
else {
transit.clear();
int amount = dataStream.readInt(); transit.add(stack);
for(int i = 0; i < amount; i++)
{
TransporterStack stack = new TransporterStack();
stack.read(dataStream);
transit.add(stack);
}
} }
} }
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getNetworkedData(ArrayList data)
{ {
data.add(0);
data.add(isActive);
return data;
}
public ArrayList getItemPacket(ArrayList data)
{
data.add(1);
data.add(transit.size()); data.add(transit.size());
for(TransporterStack stack : transit) for(TransporterStack stack : transit)
@ -338,8 +349,16 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
public void readFromNBT(NBTTagCompound nbtTags) public void readFromNBT(NBTTagCompound nbtTags)
{ {
super.readFromNBT(nbtTags); super.readFromNBT(nbtTags);
isActive = nbtTags.getBoolean("isActive"); if(nbtTags.hasKey("stacks"))
{
NBTTagList tagList = nbtTags.getTagList("stacks");
for(int i = 0; i < tagList.tagCount(); i++)
{
transit.add(TransporterStack.read((NBTTagCompound)tagList.tagAt(i)));
}
}
} }
@Override @Override
@ -347,7 +366,19 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
{ {
super.writeToNBT(nbtTags); super.writeToNBT(nbtTags);
nbtTags.setBoolean("isActive", isActive); NBTTagList stacks = new NBTTagList();
for(TransporterStack stack : transit)
{
NBTTagCompound tagCompound = new NBTTagCompound();
stack.write(tagCompound);
stacks.appendTag(tagCompound);
}
if(stacks.tagCount() != 0)
{
nbtTags.setTag("stacks", stacks);
}
} }
@Override @Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB