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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -23,7 +25,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
/**
|
||||
*
|
||||
* @author AidanBrady
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TileEntityEMContractor extends TileEntityBase implements IPacketReceiver, ITesla
|
||||
{
|
||||
|
@ -36,7 +38,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
private ForgeDirection facing = ForgeDirection.UP;
|
||||
|
||||
public int pushDelay;
|
||||
|
||||
|
||||
public float energyStored;
|
||||
|
||||
public AxisAlignedBB operationBounds;
|
||||
|
@ -47,11 +49,14 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
*/
|
||||
public boolean suck = true;
|
||||
|
||||
private Pathfinding pathfinder;
|
||||
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
pushDelay = Math.max(0, pushDelay - 1);
|
||||
|
||||
if (canFunction())
|
||||
|
@ -62,7 +67,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
if (!suck && pushDelay == 0)
|
||||
{
|
||||
ItemStack retrieved = InventoryUtil.takeTopItemFromInventory(inventory, facing.ordinal());
|
||||
|
||||
|
||||
if (retrieved != null)
|
||||
{
|
||||
EntityItem item = getItemWithPosition(retrieved);
|
||||
|
@ -71,7 +76,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
{
|
||||
worldObj.spawnEntityInWorld(item);
|
||||
}
|
||||
|
||||
|
||||
pushDelay = PUSH_DELAY;
|
||||
}
|
||||
}
|
||||
|
@ -82,12 +87,12 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
for (EntityItem item : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds))
|
||||
{
|
||||
ItemStack remains = InventoryUtil.putStackInInventory(inventory, item.getEntityItem(), facing.ordinal());
|
||||
|
||||
|
||||
if (remains == null)
|
||||
{
|
||||
item.setDead();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
item.setEntityItemStack(remains);
|
||||
}
|
||||
|
@ -259,7 +264,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
item = new EntityItem(worldObj, xCoord + 1.2, yCoord + 0.5, zCoord + 0.5, toSend);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
item.setVelocity(0, 0, 0);
|
||||
|
||||
return item;
|
||||
|
@ -348,7 +353,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
|
||||
public boolean canFunction()
|
||||
{
|
||||
return isLatched() && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
||||
|
@ -362,7 +367,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
facing = ForgeDirection.getOrientation(nbtTags.getInteger("facing"));
|
||||
suck = nbtTags.getBoolean("suck");
|
||||
energyStored = nbtTags.getFloat("energyStored");
|
||||
|
||||
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
|
@ -384,7 +389,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
facing = ForgeDirection.getOrientation(input.readInt());
|
||||
suck = input.readBoolean();
|
||||
energyStored = input.readFloat();
|
||||
|
||||
|
||||
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
|
||||
updateBounds();
|
||||
}
|
||||
|
@ -399,25 +404,25 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
|
|||
data.add(facing.ordinal());
|
||||
data.add(suck);
|
||||
data.add(energyStored);
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
energyStored += energyToUse;
|
||||
}
|
||||
|
||||
|
||||
return energyToUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive(TileEntity transferTile)
|
||||
public boolean canReceive(TileEntity transferTile)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
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.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.base.ItemBase;
|
||||
import resonantinduction.base.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -17,7 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class ItemQuantumEntangler extends ItemBase
|
||||
public class ItemQuantumEntangler extends ItemCoordLink
|
||||
{
|
||||
private static boolean didBindThisTick = false;
|
||||
|
||||
|
@ -34,10 +32,10 @@ public class ItemQuantumEntangler extends ItemBase
|
|||
{
|
||||
super.addInformation(itemstack, entityplayer, list, flag);
|
||||
|
||||
if (hasBind(itemstack))
|
||||
if (hasLink(itemstack))
|
||||
{
|
||||
Vector3 vec = getBindVec(itemstack);
|
||||
int dimID = getDimID(itemstack);
|
||||
Vector3 vec = getLink(itemstack);
|
||||
int dimID = getLinkDim(itemstack);
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
return true;
|
||||
|
@ -74,7 +72,7 @@ public class ItemQuantumEntangler extends ItemBase
|
|||
{
|
||||
if (!world.isRemote && !didBindThisTick)
|
||||
{
|
||||
if (!hasBind(itemstack))
|
||||
if (!hasLink(itemstack))
|
||||
{
|
||||
entityplayer.addChatMessage("Error: no block bound to Entangler!");
|
||||
return itemstack;
|
||||
|
@ -82,8 +80,8 @@ public class ItemQuantumEntangler extends ItemBase
|
|||
|
||||
// TELEPORT //
|
||||
|
||||
Vector3 vec = getBindVec(itemstack);
|
||||
int dimID = getDimID(itemstack);
|
||||
Vector3 vec = getLink(itemstack);
|
||||
int dimID = getLinkDim(itemstack);
|
||||
|
||||
// travel to dimension if different dimID
|
||||
if (world.provider.dimensionId != dimID)
|
||||
|
@ -102,46 +100,4 @@ public class ItemQuantumEntangler extends ItemBase
|
|||
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…
Add table
Reference in a new issue