From 8f7ac50fbf97af06efc7abec04ae1963cc08db77 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 18 Feb 2014 17:25:03 +0800 Subject: [PATCH] Refactored belts --- .../mechanical/Mechanical.java | 12 +- .../logistic/{ => belt}/BlockDetector.java | 2 +- .../logistic/{ => belt}/BlockManipulator.java | 2 +- .../logistic/{ => belt}/BlockRejector.java | 2 +- .../logistic/{ => belt}/ModelManipulator.java | 2 +- .../{ => belt}/ModelRejectorPiston.java | 2 +- .../{ => belt}/RenderManipulator.java | 2 +- .../logistic/{ => belt}/RenderRejector.java | 2 +- .../logistic/{ => belt}/TileDetector.java | 2 +- .../logistic/{ => belt}/TileManipulator.java | 2 +- .../logistic/{ => belt}/TileRejector.java | 2 +- .../mechanical/logistic/rail/BlockSorter.java | 117 ++++++++ .../logistic/rail/RenderSorter.java | 61 +++++ .../mechanical/logistic/rail/TileSorter.java | 252 ++++++++++++++++++ 14 files changed, 446 insertions(+), 16 deletions(-) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/BlockDetector.java (98%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/BlockManipulator.java (98%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/BlockRejector.java (96%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/ModelManipulator.java (99%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/ModelRejectorPiston.java (99%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/RenderManipulator.java (96%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/RenderRejector.java (96%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/TileDetector.java (98%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/TileManipulator.java (99%) rename mechanical/src/main/java/resonantinduction/mechanical/logistic/{ => belt}/TileRejector.java (98%) create mode 100644 mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/BlockSorter.java create mode 100644 mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/RenderSorter.java create mode 100644 mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/TileSorter.java diff --git a/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java b/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java index 60bb2ba53..5420efb64 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java @@ -22,12 +22,12 @@ import resonantinduction.mechanical.fluid.transport.TileGrate; import resonantinduction.mechanical.gear.ItemGear; import resonantinduction.mechanical.gear.ItemGearShaft; import resonantinduction.mechanical.item.ItemPipeGauge; -import resonantinduction.mechanical.logistic.BlockDetector; -import resonantinduction.mechanical.logistic.BlockManipulator; -import resonantinduction.mechanical.logistic.BlockRejector; -import resonantinduction.mechanical.logistic.TileDetector; -import resonantinduction.mechanical.logistic.TileManipulator; -import resonantinduction.mechanical.logistic.TileRejector; +import resonantinduction.mechanical.logistic.belt.BlockDetector; +import resonantinduction.mechanical.logistic.belt.BlockManipulator; +import resonantinduction.mechanical.logistic.belt.BlockRejector; +import resonantinduction.mechanical.logistic.belt.TileDetector; +import resonantinduction.mechanical.logistic.belt.TileManipulator; +import resonantinduction.mechanical.logistic.belt.TileRejector; import resonantinduction.mechanical.network.PacketNetwork; import resonantinduction.mechanical.process.BlockFilter; import resonantinduction.mechanical.process.BlockGrindingWheel; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockDetector.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockDetector.java similarity index 98% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockDetector.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockDetector.java index b7541e7a4..1f7e93cfb 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockDetector.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockDetector.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLivingBase; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockManipulator.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockManipulator.java similarity index 98% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockManipulator.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockManipulator.java index 6628c653b..665165c9d 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockManipulator.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockManipulator.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockRejector.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockRejector.java similarity index 96% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockRejector.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockRejector.java index 57ac0cb3c..8c50defa4 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/BlockRejector.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/BlockRejector.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelManipulator.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelManipulator.java similarity index 99% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelManipulator.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelManipulator.java index 11637fb83..2747d9e31 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelManipulator.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelManipulator.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelRejectorPiston.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelRejectorPiston.java similarity index 99% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelRejectorPiston.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelRejectorPiston.java index 7884fd722..314bb9d16 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/ModelRejectorPiston.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/ModelRejectorPiston.java @@ -4,7 +4,7 @@ // Keep in mind that you still need to fill in some blanks // - ZeuX -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderManipulator.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderManipulator.java similarity index 96% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderManipulator.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderManipulator.java index d821f6d4b..09ecf00b5 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderManipulator.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderManipulator.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderRejector.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderRejector.java similarity index 96% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderRejector.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderRejector.java index 804755749..c323dacd3 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/RenderRejector.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/RenderRejector.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileDetector.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileDetector.java similarity index 98% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/TileDetector.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileDetector.java index 34fa2190a..c982080a7 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileDetector.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileDetector.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import java.util.ArrayList; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileManipulator.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileManipulator.java similarity index 99% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/TileManipulator.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileManipulator.java index 3938aa075..bf14dd519 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileManipulator.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileManipulator.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import java.util.List; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileRejector.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileRejector.java similarity index 98% rename from mechanical/src/main/java/resonantinduction/mechanical/logistic/TileRejector.java rename to mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileRejector.java index f1c937011..a0e3e1366 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/TileRejector.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileRejector.java @@ -1,4 +1,4 @@ -package resonantinduction.mechanical.logistic; +package resonantinduction.mechanical.logistic.belt; import java.util.List; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/BlockSorter.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/BlockSorter.java new file mode 100644 index 000000000..fe7b6e901 --- /dev/null +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/BlockSorter.java @@ -0,0 +1,117 @@ +package resonantinduction.mechanical.logistic.rail; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatMessageComponent; +import net.minecraft.world.World; +import resonantinduction.core.prefab.imprint.BlockImprintable; +import resonantinduction.core.render.RIBlockRenderingHandler; +import universalelectricity.api.UniversalElectricity; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * A block that manipulates item movement between inventories. + * + * @author Calclavia, DarkGuardsman + */ +public class BlockSorter extends BlockImprintable +{ + public BlockSorter(int id) + { + super(id, UniversalElectricity.machine); + this.setBlockBounds(0.01f, 0.01f, 0.01f, 0.09f, 0.09f, 0.09f); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) + { + return AxisAlignedBB.getAABBPool().getAABB(par2, par3, par4, (double) par2 + 1, (double) par3 + 1, (double) par4 + 1); + } + + @Override + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileSorter) + { + if (!world.isRemote) + { + ((TileSorter) tileEntity).setSelfPulse(!((TileSorter) tileEntity).isSelfPulse()); + entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Manipulator set to " + (((TileSorter) tileEntity).isSelfPulse() ? "auto pulse" : "not pulse"))); + } + } + return true; + } + + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileSorter) + { + TileSorter manip = (TileSorter) tileEntity; + boolean manipMode = manip.isOutput(); + boolean inverted = manip.isInverted(); + if (manipMode && !inverted) + { + manip.toggleInversion(); + } + else if (manipMode && inverted) + { + manip.toggleOutput(); + manip.toggleInversion(); + } + else if (!manipMode && !inverted) + { + manip.toggleInversion(); + } + else + { + manip.toggleOutput(); + manip.toggleInversion(); + } + if (!world.isRemote) + { + entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Manipulator outputing = " + manip.isOutput())); + } + } + + return true; + } + + @Override + public TileEntity createNewTileEntity(World var1) + { + return new TileSorter(); + } + + @SideOnly(Side.CLIENT) + @Override + public int getRenderType() + { + return RIBlockRenderingHandler.ID; + } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean renderAsNormalBlock() + { + return false; + } + + @Override + public int damageDropped(int par1) + { + return 0; + } +} diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/RenderSorter.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/RenderSorter.java new file mode 100644 index 000000000..2bdd81dd5 --- /dev/null +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/RenderSorter.java @@ -0,0 +1,61 @@ +package resonantinduction.mechanical.logistic.rail; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import resonantinduction.core.Reference; +import resonantinduction.core.render.RenderImprintable; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderSorter extends RenderImprintable +{ + public static final ModelManipulator MODEL = new ModelManipulator(); + public static final ResourceLocation TEXTURE_INPUT = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "manipulator1.png"); + public static final ResourceLocation TEXTURE_OUTPUT = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "manipulator2.png"); + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) + { + TileSorter tile = (TileSorter) tileEntity; + int face = tile.getDirection().ordinal(); + + GL11.glPushMatrix(); + GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); + GL11.glRotatef(180f, 0f, 0f, 1f); + + if (tile.isOutput()) + { + bindTexture(TEXTURE_INPUT); + } + else + { + bindTexture(TEXTURE_OUTPUT); + } + + if (face == 2) + { + GL11.glRotatef(0f, 0f, 1f, 0f); + } + else if (face == 3) + { + GL11.glRotatef(180f, 0f, 1f, 0f); + } + else if (face == 4) + { + GL11.glRotatef(270f, 0f, 1f, 0f); + } + else if (face == 5) + { + GL11.glRotatef(90f, 0f, 1f, 0f); + } + + MODEL.render(0.0625F, true, 0); + + GL11.glPopMatrix(); + } + +} \ No newline at end of file diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/TileSorter.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/TileSorter.java new file mode 100644 index 000000000..2f505ae66 --- /dev/null +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/rail/TileSorter.java @@ -0,0 +1,252 @@ +package resonantinduction.mechanical.logistic.rail; + +import java.util.List; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.packet.Packet; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.ForgeDirection; +import resonantinduction.api.mechanical.IManipulator; +import resonantinduction.core.ResonantInduction; +import resonantinduction.core.prefab.imprint.ItemImprint; +import resonantinduction.core.prefab.imprint.TileFilterable; +import universalelectricity.api.vector.Vector3; +import calclavia.lib.network.IPacketReceiver; +import calclavia.lib.prefab.tile.IRotatable; +import calclavia.lib.utility.inventory.InternalInventoryHandler; + +import com.google.common.io.ByteArrayDataInput; + +public class TileSorter extends TileFilterable implements IRotatable, IManipulator, IPacketReceiver +{ + /** True to auto output items with a redstone pulse */ + private boolean selfPulse = false; + /** True if outputting items */ + private boolean isOutput = false; + /** True if is currently powered by redstone */ + private boolean isRedstonePowered = false; + /** The class that interacts with inventories for this machine */ + private InternalInventoryHandler invExtractionHelper; + + @Override + public void updateEntity() + { + super.updateEntity(); + if (!this.worldObj.isRemote) + { + if (this.isFunctioning()) + { + if (!this.isOutput) + { + this.enject(); + } + else + { + this.isRedstonePowered = this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + if (this.isSelfPulse() && this.ticks % 10 == 0) + { + this.isRedstonePowered = true; + } + + /** Finds the connected inventory and outputs the items upon a redstone pulse. */ + if (this.isRedstonePowered) + { + this.inject(); + } + } + } + } + } + + /** + * Find items going into the manipulator and input them into an inventory behind this + * manipulator. + */ + @Override + public void enject() + { + Vector3 inputPosition = new Vector3(this); + /** output location up */ + Vector3 outputUp = new Vector3(this); + outputUp.modifyPositionFromSide(ForgeDirection.UP); + /** output location down */ + Vector3 outputDown = new Vector3(this); + outputDown.modifyPositionFromSide(ForgeDirection.DOWN); + /** output location facing */ + Vector3 outputPosition = new Vector3(this); + outputPosition.modifyPositionFromSide(this.getDirection().getOpposite()); + + /** Prevents manipulators from spamming and duping items. */ + if (outputPosition.getTileEntity(this.worldObj) instanceof TileSorter) + { + if (((TileSorter) outputPosition.getTileEntity(this.worldObj)).getDirection() == this.getDirection().getOpposite()) + { + return; + } + } + + AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(inputPosition.x, inputPosition.y, inputPosition.z, inputPosition.x + 1, inputPosition.y + 1, inputPosition.z + 1); + List itemsInBound = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); + + for (EntityItem entity : itemsInBound) + { + if (entity.isDead) + continue; + + /** + * Try top first, then bottom, then the sides to see if it is possible to insert the + * item into a inventory. + */ + ItemStack remainingStack = entity.getEntityItem().copy(); + + if (this.getFilter() == null || this.isFiltering(remainingStack)) + { + remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputUp, ForgeDirection.UP); + + if (remainingStack != null) + { + remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputDown, ForgeDirection.DOWN); + } + + if (remainingStack != null) + { + remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputPosition, this.getDirection().getOpposite()); + } + + if (remainingStack != null && remainingStack.stackSize > 0) + { + invHelper().throwItem(outputPosition, remainingStack); + } + + entity.setDead(); + } + } + } + + /** Inject items */ + @Override + public void inject() + { + this.isRedstonePowered = false; + /** input location up */ + Vector3 inputUp = new Vector3(this).modifyPositionFromSide(ForgeDirection.UP); + /** input location down */ + Vector3 inputDown = new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN); + /** input location facing */ + Vector3 inputPosition = new Vector3(this).modifyPositionFromSide(this.getDirection().getOpposite()); + /** output location facing */ + Vector3 outputPosition = new Vector3(this).modifyPositionFromSide(this.getDirection()); + + ItemStack itemStack = invHelper().tryGrabFromPosition(inputUp, ForgeDirection.UP, 1); + + if (itemStack == null) + { + itemStack = invHelper().tryGrabFromPosition(inputDown, ForgeDirection.DOWN, 1); + } + + if (itemStack == null) + { + itemStack = invHelper().tryGrabFromPosition(inputPosition, this.getDirection().getOpposite(), 1); + } + + if (itemStack != null) + { + if (itemStack.stackSize > 0) + { + invHelper().throwItem(outputPosition, itemStack); + } + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + this.isOutput = nbt.getBoolean("isOutput"); + this.setSelfPulse(nbt.getBoolean("selfpulse")); + } + + /** Writes a tile entity to NBT. */ + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setBoolean("isOutput", this.isOutput); + nbt.setBoolean("selfpulse", this.isSelfPulse()); + } + + @Override + public Packet getDescriptionPacket() + { + return ResonantInduction.PACKET_TILE.getPacket(this, this.isInverted(), this.isSelfPulse(), this.isOutput()); + } + + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) + { + try + { + this.setInverted(data.readBoolean()); + this.setSelfPulse(data.readBoolean()); + this.setOutput(data.readBoolean()); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public boolean isSelfPulse() + { + return selfPulse; + } + + public void setSelfPulse(boolean selfPulse) + { + this.selfPulse = selfPulse; + } + + /** Gets the class that managed extracting and placing items into inventories */ + public InternalInventoryHandler invHelper() + { + if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj) + { + this.invExtractionHelper = new InternalInventoryHandler(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprint.getFilters(getFilter()) : null, this.isInverted()); + } + return invExtractionHelper; + } + + @Override + public void setFilter(ItemStack filter) + { + super.setFilter(filter); + /* Reset inv Helper's filters */ + this.invHelper().setFilter(this.getFilter() != null ? ItemImprint.getFilters(this.getFilter()) : null, this.isInverted()); + } + + /** Is this manipulator set to output items */ + public boolean isOutput() + { + return this.isOutput; + } + + /** True to output items */ + public void setOutput(boolean isOutput) + { + this.isOutput = isOutput; + + if (!this.worldObj.isRemote) + { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + /** Inverts the current output state */ + public void toggleOutput() + { + this.setOutput(!this.isOutput()); + } +}