aboutsummaryrefslogtreecommitdiff
path: root/src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2017-01-17 19:41:46 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2017-01-17 19:41:46 +1000
commit5834a266fdf425ad56558db71691f9b3b0df5e31 (patch)
treeeb2123fde62da27795417fbe9b6afcd31b383adf /src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java
parent289e41515842ec89d01bfa593504163f75d0950c (diff)
downloadGT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.tar.gz
GT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.tar.bz2
GT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.zip
% Tried to improve the logic for the Tree Farmer, to support Forestry 4.
% Moved COFH API related files. + Added a child mod, for misc handling. $$ Borrowed some code from MFR, to attempt forestry support. (Credit left, will re-do if I even get it working).
Diffstat (limited to 'src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java')
-rw-r--r--src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java b/src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java
new file mode 100644
index 0000000000..c67e8a39a2
--- /dev/null
+++ b/src/Java/powercrystals/minefactoryreloaded/api/ReplacementBlock.java
@@ -0,0 +1,135 @@
+package powercrystals.minefactoryreloaded.api;
+
+import net.minecraft.block.Block;
+import net.minecraft.item.*;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+
+public class ReplacementBlock
+{
+ protected byte _hasMeta;
+ protected int _meta;
+ protected final Block _block;
+ protected final NBTTagCompound _tileTag;
+
+ /**
+ * Called to replace a block in the world.
+ * @param world The world object
+ * @param x The X coord
+ * @param y The Y coord
+ * @param z The Z coord
+ * @param stack The ItemStack being used to replace the block (may be null)
+ * @return True if the block was set successfully
+ */
+ public boolean replaceBlock(World world, int x, int y, int z, ItemStack stack)
+ {
+ int meta = getMeta(world, x, y, z, stack);
+ if (world.setBlock(x, y, z, _block, meta, 3))
+ {
+ if (hasTag(stack) && _block.hasTileEntity(meta))
+ {
+ TileEntity tile = world.getTileEntity(x, y, z);
+ if (tile != null)
+ tile.readFromNBT(getTag(world, x, y, z, stack));
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Called to get the metadata of the replacement block in the world.
+ * @param world The world object
+ * @param x The X coord
+ * @param y The Y coord
+ * @param z The Z coord
+ * @param stack The ItemStack being used to replace the block (may be null)
+ * @return The metadata of the block
+ */
+ protected int getMeta(World world, int x, int y, int z, ItemStack stack)
+ {
+ int m = 0;
+ if (_hasMeta > 0)
+ {
+ if (_hasMeta > 1)
+ return _meta;
+ m = stack.getItemDamage();
+ Item item = stack.getItem();
+ if (item instanceof ItemBlock)
+ m = ((ItemBlock)item).getMetadata(m);
+ }
+ return m;
+ }
+
+ /**
+ * Called to set the metdata of this ReplacementBlock to a fixed value
+ * @param meta The metadata of the block
+ * @return This instance
+ */
+ public ReplacementBlock setMeta(int meta)
+ {
+ if (meta >= 0)
+ {
+ _hasMeta = 2;
+ _meta = meta;
+ }
+ return this;
+ }
+
+ /**
+ * Called to set the metdata of this ReplacementBlock to a value read from an ItemStack
+ * @param meta The metadata of the block
+ * @return This instance
+ */
+ public ReplacementBlock setMeta(boolean hasMeta)
+ {
+ _hasMeta = (byte) (hasMeta ? 1 : 0);
+ return this;
+ }
+
+ /**
+ * Called to get the NBTTagCompound a TileEntity will read its state from
+ * @param world The world object
+ * @param x The X coord
+ * @param y The Y coord
+ * @param z The Z coord
+ * @param stack The ItemStack being used to replace the block (may be null)
+ * @return The NBTTagCompound a TileEntity will read its state from
+ */
+ protected NBTTagCompound getTag(World world, int x, int y, int z, ItemStack stack)
+ {
+ return _tileTag;
+ }
+
+ /**
+ * Called to see if a TileEntity should have its state set
+ * @param stack The ItemStack being used to replace the block (may be null)
+ * @return True if the TileEntity should have its state set
+ */
+ protected boolean hasTag(ItemStack stack)
+ {
+ return _tileTag != null;
+ }
+
+ public ReplacementBlock(Item block)
+ {
+ this(Block.getBlockFromItem(block));
+ }
+
+ public ReplacementBlock(Item block, NBTTagCompound tag)
+ {
+ this(Block.getBlockFromItem(block), tag);
+ }
+
+ public ReplacementBlock(Block block)
+ {
+ this(block, null);
+ }
+
+ public ReplacementBlock(Block block, NBTTagCompound tag)
+ {
+ _block = block;
+ _tileTag = tag;
+ }
+}