Fixed #455 - EM Levitator item dupe
This commit is contained in:
parent
339b9e71e5
commit
853c7bfdb0
1 changed files with 48 additions and 40 deletions
|
@ -1,13 +1,15 @@
|
||||||
package resonantinduction.electrical.levitator;
|
package resonantinduction.electrical.levitator;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import calclavia.lib.render.EnumColor;
|
||||||
import java.util.List;
|
import calclavia.lib.utility.LinkUtility;
|
||||||
|
import calclavia.lib.utility.WrenchUtility;
|
||||||
import net.minecraft.block.Block;
|
import calclavia.lib.utility.inventory.InventoryUtility;
|
||||||
import net.minecraft.block.BlockFluid;
|
import codechicken.lib.data.MCDataInput;
|
||||||
import net.minecraft.block.BlockLadder;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
import net.minecraft.block.BlockSnow;
|
import codechicken.multipart.TMultiPart;
|
||||||
import net.minecraft.block.BlockVine;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -28,28 +30,23 @@ import resonantinduction.electrical.Electrical;
|
||||||
import resonantinduction.electrical.tesla.TileTesla;
|
import resonantinduction.electrical.tesla.TileTesla;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import universalelectricity.api.vector.VectorWorld;
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
import calclavia.lib.render.EnumColor;
|
|
||||||
import calclavia.lib.utility.LinkUtility;
|
import java.lang.ref.WeakReference;
|
||||||
import calclavia.lib.utility.WrenchUtility;
|
import java.util.List;
|
||||||
import calclavia.lib.utility.inventory.InventoryUtility;
|
|
||||||
import codechicken.lib.data.MCDataInput;
|
|
||||||
import codechicken.lib.data.MCDataOutput;
|
|
||||||
import codechicken.multipart.TMultiPart;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
public class PartLevitator extends PartFace
|
public class PartLevitator extends PartFace
|
||||||
{
|
{
|
||||||
private int pushDelay;
|
|
||||||
|
|
||||||
private AxisAlignedBB operationBounds;
|
|
||||||
private AxisAlignedBB suckBounds;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true = suck, false = push
|
* true = suck, false = push
|
||||||
*/
|
*/
|
||||||
public boolean input = true;
|
public boolean input = true;
|
||||||
|
/**
|
||||||
|
* Client Side Only
|
||||||
|
*/
|
||||||
|
public float renderRotation = 0;
|
||||||
|
private int pushDelay;
|
||||||
|
private AxisAlignedBB operationBounds;
|
||||||
|
private AxisAlignedBB suckBounds;
|
||||||
/**
|
/**
|
||||||
* Pathfinding
|
* Pathfinding
|
||||||
*/
|
*/
|
||||||
|
@ -57,20 +54,21 @@ public class PartLevitator extends PartFace
|
||||||
private PathfinderLevitator pathfinder;
|
private PathfinderLevitator pathfinder;
|
||||||
private WeakReference<PartLevitator> linked;
|
private WeakReference<PartLevitator> linked;
|
||||||
private int lastCalcTime = 0;
|
private int lastCalcTime = 0;
|
||||||
|
/**
|
||||||
/** Color of beam */
|
* Color of beam
|
||||||
|
*/
|
||||||
private int dyeID = TileTesla.DEFAULT_COLOR;
|
private int dyeID = TileTesla.DEFAULT_COLOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linking
|
* Linking
|
||||||
*/
|
*/
|
||||||
private byte saveLinkSide;
|
private byte saveLinkSide;
|
||||||
private VectorWorld saveLinkVector;
|
private VectorWorld saveLinkVector;
|
||||||
|
|
||||||
/**
|
public static boolean canBePath(World world, Vector3 position)
|
||||||
* Client Side Only
|
{
|
||||||
*/
|
Block block = Block.blocksList[position.getBlockID(world)];
|
||||||
public float renderRotation = 0;
|
return block == null || (block instanceof BlockSnow || block instanceof BlockVine || block instanceof BlockLadder || ((block instanceof BlockFluid || block instanceof IFluidBlock) && block.blockID != Block.lavaMoving.blockID && block.blockID != Block.lavaStill.blockID));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack itemStack)
|
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack itemStack)
|
||||||
|
@ -80,13 +78,17 @@ public class PartLevitator extends PartFace
|
||||||
if (tryLink(LinkUtility.getLink(itemStack), LinkUtility.getSide(itemStack)))
|
if (tryLink(LinkUtility.getLink(itemStack), LinkUtility.getSide(itemStack)))
|
||||||
{
|
{
|
||||||
if (world().isRemote)
|
if (world().isRemote)
|
||||||
|
{
|
||||||
player.addChatMessage("Successfully linked devices.");
|
player.addChatMessage("Successfully linked devices.");
|
||||||
|
}
|
||||||
LinkUtility.clearLink(itemStack);
|
LinkUtility.clearLink(itemStack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (world().isRemote)
|
if (world().isRemote)
|
||||||
|
{
|
||||||
player.addChatMessage("Marked link for device.");
|
player.addChatMessage("Marked link for device.");
|
||||||
|
}
|
||||||
|
|
||||||
LinkUtility.setLink(itemStack, new VectorWorld(world(), x(), y(), z()));
|
LinkUtility.setLink(itemStack, new VectorWorld(world(), x(), y(), z()));
|
||||||
LinkUtility.setSide(itemStack, (byte) placementSide.ordinal());
|
LinkUtility.setSide(itemStack, (byte) placementSide.ordinal());
|
||||||
|
@ -111,7 +113,9 @@ public class PartLevitator extends PartFace
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isSneaking())
|
if (player.isSneaking())
|
||||||
|
{
|
||||||
input = !input;
|
input = !input;
|
||||||
|
}
|
||||||
|
|
||||||
updateBounds();
|
updateBounds();
|
||||||
updatePath();
|
updatePath();
|
||||||
|
@ -152,18 +156,18 @@ public class PartLevitator extends PartFace
|
||||||
*/
|
*/
|
||||||
if (!world().isRemote && input && canFunction() && entity instanceof EntityItem)
|
if (!world().isRemote && input && canFunction() && entity instanceof EntityItem)
|
||||||
{
|
{
|
||||||
EntityItem item = (EntityItem) entity;
|
EntityItem entityItem = (EntityItem) entity;
|
||||||
IInventory inventory = (IInventory) getLatched();
|
IInventory inventory = (IInventory) getLatched();
|
||||||
|
|
||||||
ItemStack remains = InventoryUtility.putStackInInventory(inventory, item.getEntityItem(), placementSide.getOpposite().getOpposite().ordinal(), false);
|
ItemStack remains = InventoryUtility.putStackInInventory(inventory, entityItem.getEntityItem(), placementSide.getOpposite().getOpposite().ordinal(), false);
|
||||||
|
|
||||||
if (remains == null)
|
if (remains == null)
|
||||||
{
|
{
|
||||||
item.setDead();
|
entityItem.setDead();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.setEntityItemStack(remains);
|
entityItem.getEntityItem().stackSize = remains.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add redstone pulse and reaction?
|
// TODO: Add redstone pulse and reaction?
|
||||||
|
@ -174,7 +178,9 @@ public class PartLevitator extends PartFace
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
if (ticks % 60 == 0)
|
if (ticks % 60 == 0)
|
||||||
|
{
|
||||||
updateBounds();
|
updateBounds();
|
||||||
|
}
|
||||||
|
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
|
@ -277,7 +283,9 @@ public class PartLevitator extends PartFace
|
||||||
final ForgeDirection direction = difference.toForgeDirection();
|
final ForgeDirection direction = difference.toForgeDirection();
|
||||||
|
|
||||||
if (renderBeam)
|
if (renderBeam)
|
||||||
|
{
|
||||||
Electrical.proxy.renderElectricShock(world(), prevResult.clone().translate(0.5), result.clone().translate(0.5), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9);
|
Electrical.proxy.renderElectricShock(world(), prevResult.clone().translate(0.5), result.clone().translate(0.5), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1);
|
AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1);
|
||||||
List<EntityItem> entities = world().getEntitiesWithinAABB(EntityItem.class, bounds);
|
List<EntityItem> entities = world().getEntitiesWithinAABB(EntityItem.class, bounds);
|
||||||
|
@ -313,7 +321,9 @@ public class PartLevitator extends PartFace
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks % renderPeriod == 0)
|
if (ticks % renderPeriod == 0)
|
||||||
|
{
|
||||||
Electrical.proxy.renderElectricShock(world(), getBeamSpawnPosition(), new Vector3(operationBounds.maxX - 0.5 - placementSide.offsetX / 3f, operationBounds.maxY - 0.5 - placementSide.offsetY / 3f, operationBounds.maxZ - 0.5 - placementSide.offsetZ / 3f), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9);
|
Electrical.proxy.renderElectricShock(world(), getBeamSpawnPosition(), new Vector3(operationBounds.maxX - 0.5 - placementSide.offsetX / 3f, operationBounds.maxY - 0.5 - placementSide.offsetY / 3f, operationBounds.maxZ - 0.5 - placementSide.offsetZ / 3f), EnumColor.DYES[dyeID].toColor(), world().rand.nextFloat() > 0.9);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,21 +335,19 @@ public class PartLevitator extends PartFace
|
||||||
{
|
{
|
||||||
TMultiPart partSelf = MultipartUtility.getMultipart(new VectorWorld(world, position), placementSide.ordinal());
|
TMultiPart partSelf = MultipartUtility.getMultipart(new VectorWorld(world, position), placementSide.ordinal());
|
||||||
if (partSelf == this)
|
if (partSelf == this)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TMultiPart partLink = MultipartUtility.getMultipart(new VectorWorld(world, position), getLink().placementSide.ordinal());
|
TMultiPart partLink = MultipartUtility.getMultipart(new VectorWorld(world, position), getLink().placementSide.ordinal());
|
||||||
if (partLink == getLink())
|
if (partLink == getLink())
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return canBePath(world, position);
|
return canBePath(world, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canBePath(World world, Vector3 position)
|
|
||||||
{
|
|
||||||
Block block = Block.blocksList[position.getBlockID(world)];
|
|
||||||
return block == null || (block instanceof BlockSnow || block instanceof BlockVine || block instanceof BlockLadder || ((block instanceof BlockFluid || block instanceof IFluidBlock) && block.blockID != Block.lavaMoving.blockID && block.blockID != Block.lavaStill.blockID));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasLink()
|
private boolean hasLink()
|
||||||
{
|
{
|
||||||
return getLink() != null && getLink().getLink() == this;
|
return getLink() != null && getLink().getLink() == this;
|
||||||
|
|
Loading…
Reference in a new issue