Fixed link not saving

This commit is contained in:
Calclavia 2013-08-04 17:56:13 -04:00
parent fd3f60a3d5
commit fb4ed3aa3b
4 changed files with 50 additions and 7 deletions

View file

@ -57,12 +57,15 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
{ {
if (linkVec.getTileEntity(world) instanceof TileEntityEMContractor) if (linkVec.getTileEntity(world) instanceof TileEntityEMContractor)
{ {
contractor.setLink((TileEntityEMContractor) linkVec.getTileEntity(world)); contractor.setLink((TileEntityEMContractor) linkVec.getTileEntity(world), true);
if (!world.isRemote) if (!world.isRemote)
{ {
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]"); entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");
} }
link.clearLink(entityPlayer.getCurrentEquippedItem());
return true; return true;
} }
} }

View file

@ -57,6 +57,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
/** Color of beam */ /** Color of beam */
private int dyeID = 13; private int dyeID = 13;
private Vector3 tempLinkVector;
@Override @Override
public void updateEntity() public void updateEntity()
@ -65,6 +66,16 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
this.pushDelay = Math.max(0, this.pushDelay - 1); this.pushDelay = Math.max(0, this.pushDelay - 1);
if (this.tempLinkVector != null)
{
if (this.tempLinkVector.getTileEntity(this.worldObj) instanceof TileEntityEMContractor)
{
this.linked = (TileEntityEMContractor) this.tempLinkVector.getTileEntity(this.worldObj);
}
this.tempLinkVector = null;
}
if (canFunction()) if (canFunction())
{ {
TileEntity inventoryTile = getLatched(); TileEntity inventoryTile = getLatched();
@ -407,6 +418,11 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
this.suck = nbt.getBoolean("suck"); this.suck = nbt.getBoolean("suck");
this.energyStored = nbt.getFloat("energyStored"); this.energyStored = nbt.getFloat("energyStored");
this.dyeID = nbt.getInteger("dyeID"); this.dyeID = nbt.getInteger("dyeID");
int x = nbt.getInteger("link_x");
int y = nbt.getInteger("link_y");
int z = nbt.getInteger("link_z");
this.tempLinkVector = new Vector3(x, y, z);
updateBounds(); updateBounds();
} }
@ -420,6 +436,13 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
nbt.setBoolean("suck", suck); nbt.setBoolean("suck", suck);
nbt.setFloat("energyStored", energyStored); nbt.setFloat("energyStored", energyStored);
nbt.setInteger("dyeID", this.dyeID); nbt.setInteger("dyeID", this.dyeID);
if (this.linked != null)
{
nbt.setInteger("link_x", this.linked.xCoord);
nbt.setInteger("link_y", this.linked.yCoord);
nbt.setInteger("link_z", this.linked.zCoord);
}
} }
@Override @Override
@ -473,10 +496,20 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
/** /**
* Link between two TileEntities, do pathfinding operation. * Link between two TileEntities, do pathfinding operation.
*/ */
public void setLink(TileEntityEMContractor tileEntity) public void setLink(TileEntityEMContractor tileEntity, boolean setOpponent)
{ {
if (this.linked != null && setOpponent)
{
this.linked.setLink(null, false);
}
this.linked = tileEntity; this.linked = tileEntity;
this.linked.linked = this;
if (setOpponent)
{
this.linked.setLink(this, false);
}
this.updatePath(); this.updatePath();
} }

View file

@ -5,13 +5,13 @@ package resonantinduction.entangler;
import java.util.List; import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.base.ItemBase; import resonantinduction.base.ItemBase;
import resonantinduction.base.Vector3; import resonantinduction.base.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** /**
* @author Calclavia * @author Calclavia
@ -50,7 +50,7 @@ public abstract class ItemCoordLink extends ItemBase
public Vector3 getLink(ItemStack itemStack) public Vector3 getLink(ItemStack itemStack)
{ {
if (itemStack.stackTagCompound == null) if (itemStack.stackTagCompound == null || !(itemStack.getTagCompound().hasKey("bindX") && itemStack.getTagCompound().hasKey("bindY") && itemStack.getTagCompound().hasKey("bindZ")))
{ {
return null; return null;
} }
@ -85,4 +85,12 @@ public abstract class ItemCoordLink extends ItemBase
return itemStack.stackTagCompound.getInteger("dimID"); return itemStack.stackTagCompound.getInteger("dimID");
} }
public void clearLink(ItemStack itemStack)
{
itemStack.getTagCompound().removeTag("bindX");
itemStack.getTagCompound().removeTag("bindY");
itemStack.getTagCompound().removeTag("bindZ");
itemStack.getTagCompound().removeTag("dimID");
}
} }

View file

@ -24,7 +24,6 @@ public class ItemLinker extends ItemCoordLink
{ {
if (!world.isRemote) if (!world.isRemote)
{ {
System.out.println("TEST");
int dimID = world.provider.dimensionId; int dimID = world.provider.dimensionId;
player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'"); player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'");
this.setLink(stack, new Vector3(x, y, z), dimID); this.setLink(stack, new Vector3(x, y, z), dimID);