Made ItemCoordLink parent class
This commit is contained in:
parent
4ddb716101
commit
be5d59180c
3 changed files with 94 additions and 69 deletions
|
@ -1,7 +1,9 @@
|
||||||
package resonantinduction.contractor;
|
package resonantinduction.contractor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
@ -47,6 +49,9 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
||||||
*/
|
*/
|
||||||
public boolean suck = true;
|
public boolean suck = true;
|
||||||
|
|
||||||
|
private Pathfinding pathfinder;
|
||||||
|
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
|
@ -406,7 +411,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
||||||
@Override
|
@Override
|
||||||
public float transfer(float transferEnergy, boolean doTransfer)
|
public float transfer(float transferEnergy, boolean doTransfer)
|
||||||
{
|
{
|
||||||
float energyToUse = Math.min(transferEnergy, ENERGY_USAGE-energyStored);
|
float energyToUse = Math.min(transferEnergy, ENERGY_USAGE - energyStored);
|
||||||
|
|
||||||
if (doTransfer)
|
if (doTransfer)
|
||||||
{
|
{
|
||||||
|
|
64
src/resonantinduction/entangler/ItemCoordLink.java
Normal file
64
src/resonantinduction/entangler/ItemCoordLink.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package resonantinduction.entangler;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import resonantinduction.base.ItemBase;
|
||||||
|
import resonantinduction.base.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class ItemCoordLink extends ItemBase
|
||||||
|
{
|
||||||
|
public ItemCoordLink(String name, int id)
|
||||||
|
{
|
||||||
|
super(name, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasLink(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
return getLink(itemStack) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 getLink(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
if (itemStack.stackTagCompound == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = itemStack.stackTagCompound.getInteger("bindX");
|
||||||
|
int y = itemStack.stackTagCompound.getInteger("bindY");
|
||||||
|
int z = itemStack.stackTagCompound.getInteger("bindZ");
|
||||||
|
|
||||||
|
return new Vector3(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLink(ItemStack itemStack, Vector3 vec, int dimID)
|
||||||
|
{
|
||||||
|
if (itemStack.stackTagCompound == null)
|
||||||
|
{
|
||||||
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStack.stackTagCompound.setInteger("bindX", (int) vec.x);
|
||||||
|
itemStack.stackTagCompound.setInteger("bindY", (int) vec.y);
|
||||||
|
itemStack.stackTagCompound.setInteger("bindZ", (int) vec.z);
|
||||||
|
|
||||||
|
itemStack.stackTagCompound.setInteger("dimID", dimID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLinkDim(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
if (itemStack.stackTagCompound == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemStack.stackTagCompound.getInteger("dimID");
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,7 @@ import java.util.List;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import resonantinduction.base.ItemBase;
|
|
||||||
import resonantinduction.base.Vector3;
|
import resonantinduction.base.Vector3;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
@ -17,7 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
* @author AidanBrady
|
* @author AidanBrady
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ItemQuantumEntangler extends ItemBase
|
public class ItemQuantumEntangler extends ItemCoordLink
|
||||||
{
|
{
|
||||||
private static boolean didBindThisTick = false;
|
private static boolean didBindThisTick = false;
|
||||||
|
|
||||||
|
@ -34,10 +32,10 @@ public class ItemQuantumEntangler extends ItemBase
|
||||||
{
|
{
|
||||||
super.addInformation(itemstack, entityplayer, list, flag);
|
super.addInformation(itemstack, entityplayer, list, flag);
|
||||||
|
|
||||||
if (hasBind(itemstack))
|
if (hasLink(itemstack))
|
||||||
{
|
{
|
||||||
Vector3 vec = getBindVec(itemstack);
|
Vector3 vec = getLink(itemstack);
|
||||||
int dimID = getDimID(itemstack);
|
int dimID = getLinkDim(itemstack);
|
||||||
|
|
||||||
list.add("Bound to [" + (int) vec.x + ", " + (int) vec.y + ", " + (int) vec.z + "], dimension '" + dimID + "'");
|
list.add("Bound to [" + (int) vec.x + ", " + (int) vec.y + ", " + (int) vec.z + "], dimension '" + dimID + "'");
|
||||||
}
|
}
|
||||||
|
@ -57,7 +55,7 @@ public class ItemQuantumEntangler extends ItemBase
|
||||||
int dimID = world.provider.dimensionId;
|
int dimID = world.provider.dimensionId;
|
||||||
|
|
||||||
entityplayer.addChatMessage("Bound Entangler to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'");
|
entityplayer.addChatMessage("Bound Entangler to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'");
|
||||||
setBindVec(itemstack, new Vector3(x, y, z), dimID);
|
setLink(itemstack, new Vector3(x, y, z), dimID);
|
||||||
didBindThisTick = true;
|
didBindThisTick = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -74,7 +72,7 @@ public class ItemQuantumEntangler extends ItemBase
|
||||||
{
|
{
|
||||||
if (!world.isRemote && !didBindThisTick)
|
if (!world.isRemote && !didBindThisTick)
|
||||||
{
|
{
|
||||||
if (!hasBind(itemstack))
|
if (!hasLink(itemstack))
|
||||||
{
|
{
|
||||||
entityplayer.addChatMessage("Error: no block bound to Entangler!");
|
entityplayer.addChatMessage("Error: no block bound to Entangler!");
|
||||||
return itemstack;
|
return itemstack;
|
||||||
|
@ -82,8 +80,8 @@ public class ItemQuantumEntangler extends ItemBase
|
||||||
|
|
||||||
// TELEPORT //
|
// TELEPORT //
|
||||||
|
|
||||||
Vector3 vec = getBindVec(itemstack);
|
Vector3 vec = getLink(itemstack);
|
||||||
int dimID = getDimID(itemstack);
|
int dimID = getLinkDim(itemstack);
|
||||||
|
|
||||||
// travel to dimension if different dimID
|
// travel to dimension if different dimID
|
||||||
if (world.provider.dimensionId != dimID)
|
if (world.provider.dimensionId != dimID)
|
||||||
|
@ -102,46 +100,4 @@ public class ItemQuantumEntangler extends ItemBase
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBind(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
return getBindVec(itemStack) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 getBindVec(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
if (itemStack.stackTagCompound == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x = itemStack.stackTagCompound.getInteger("bindX");
|
|
||||||
int y = itemStack.stackTagCompound.getInteger("bindY");
|
|
||||||
int z = itemStack.stackTagCompound.getInteger("bindZ");
|
|
||||||
|
|
||||||
return new Vector3(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBindVec(ItemStack itemStack, Vector3 vec, int dimID)
|
|
||||||
{
|
|
||||||
if (itemStack.stackTagCompound == null)
|
|
||||||
{
|
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
itemStack.stackTagCompound.setInteger("bindX", (int) vec.x);
|
|
||||||
itemStack.stackTagCompound.setInteger("bindY", (int) vec.y);
|
|
||||||
itemStack.stackTagCompound.setInteger("bindZ", (int) vec.z);
|
|
||||||
|
|
||||||
itemStack.stackTagCompound.setInteger("dimID", dimID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDimID(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
if (itemStack.stackTagCompound == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemStack.stackTagCompound.getInteger("dimID");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue