From 431b93bf31f213fc118997da464450f676fb6f5a Mon Sep 17 00:00:00 2001 From: Mohammad-Ali Minaie Date: Tue, 20 Jun 2017 22:41:18 -0400 Subject: [PATCH] fixed bugs initial slot manager handler for casting added --- .../forgecraft/blocks/Anvil/AnvilStone.java | 1 + .../primal/forgecraft/blocks/CastingForm.java | 6 +- .../primal/forgecraft/init/ModCrafting.java | 2 +- .../primal/forgecraft/tiles/TileBloomery.java | 35 +++--- .../primal/forgecraft/tiles/TileForge.java | 18 +-- .../primal/forgecraft/util/AnvilHandler.java | 2 +- .../forgecraft/util/CastingFormHandler.java | 111 ++++++++++++++++++ .../forgecraft/models/block/castingform.json | 13 +- .../textures/blocks/castingform_top.png | Bin 0 -> 699 bytes 9 files changed, 150 insertions(+), 38 deletions(-) create mode 100644 1.11/src/main/java/nmd/primal/forgecraft/util/CastingFormHandler.java create mode 100644 1.11/src/main/resources/assets/forgecraft/textures/blocks/castingform_top.png diff --git a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Anvil/AnvilStone.java b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Anvil/AnvilStone.java index 4592f5f9..6364203b 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Anvil/AnvilStone.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Anvil/AnvilStone.java @@ -49,6 +49,7 @@ public class AnvilStone extends AnvilBase { CommonUtils.spawnItemEntityFromWorld(world, pos, new ItemStack(PrimalItems.ROCK_STONE, 3)); CommonUtils.spawnItemEntityFromWorld(world, pos, new ItemStack(ModBlocks.ironball, 1)); this.breakBlock(world, pos, state); + return true; } } } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/blocks/CastingForm.java b/1.11/src/main/java/nmd/primal/forgecraft/blocks/CastingForm.java index 48369155..38a2a116 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/blocks/CastingForm.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/blocks/CastingForm.java @@ -19,13 +19,14 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import nmd.primal.forgecraft.ModInfo; import nmd.primal.forgecraft.tiles.TileCastingForm; +import nmd.primal.forgecraft.util.CastingFormHandler; import javax.annotation.Nullable; /** * Created by mminaie on 6/19/17. */ -public class CastingForm extends CustomContainerFacing { +public class CastingForm extends CustomContainerFacing implements CastingFormHandler{ protected static AxisAlignedBB bound = new AxisAlignedBB(0/16D, 0.0D, 0/16D, 16/16D, 5/16D, 16/16D); @@ -40,7 +41,8 @@ public class CastingForm extends CustomContainerFacing { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitx, float hity, float hitz) { if (!world.isRemote) { - + TileCastingForm tile = (TileCastingForm) world.getTileEntity(pos); + doInventoryManager(player.getActiveItemStack(), world, tile, pos, hitx, hity, hitz, state, player); } return false; } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/init/ModCrafting.java b/1.11/src/main/java/nmd/primal/forgecraft/init/ModCrafting.java index 035b327a..6a33890e 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/init/ModCrafting.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/init/ModCrafting.java @@ -86,7 +86,7 @@ public class ModCrafting { GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.rawsteelcrucible), "XC","Y ", ('X'), new ItemStack(ModBlocks.ironcleanball, 1), - ('C'), new ItemStack(Items.COAL, 1, 1), + ('C'), new ItemStack(PrimalItems.CHARCOAL_HIGH), ('Y'), ModBlocks.emptycrucible)); diff --git a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBloomery.java b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBloomery.java index 5dd2755f..613b2360 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBloomery.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBloomery.java @@ -35,28 +35,25 @@ public class TileBloomery extends TileBaseSlot implements ITickable { World world = this.getWorld(); if(!world.isRemote){ IBlockState state = world.getBlockState(this.pos); - if(state.getValue(PrimalStates.ACTIVE) == true){ - if(this.getHeat() < 100){ + if(state.getValue(PrimalStates.ACTIVE) == true) { + if (this.getHeat() < 100) { this.setHeat(100); } - } - this.iteration ++; - if(this.iteration == 300 ) { - this.iteration = 0; - - //IBlockState state = world.getBlockState(this.pos); - BlockPos abovePos = new BlockPos(this.getPos().getX(), this.getPos().getY()+1, this.getPos().getZ()); - if (world.getBlockState(this.getPos()).getValue(PrimalStates.ACTIVE)) { - if (this.getSlotStack(0) == ItemStack.EMPTY) { - world.setBlockState(this.getPos(), state.withProperty(PrimalStates.ACTIVE, false), 2); - this.markDirty(); - world.notifyBlockUpdate(pos, state, state, 2); - } - slotZeroManager(world); + this.iteration++; + if (this.iteration == 300) { + this.iteration = 0; + //IBlockState state = world.getBlockState(this.pos); + BlockPos abovePos = new BlockPos(this.getPos().getX(), this.getPos().getY() + 1, this.getPos().getZ()); + if (this.getSlotStack(0) == ItemStack.EMPTY) { + world.setBlockState(this.getPos(), state.withProperty(PrimalStates.ACTIVE, false), 2); + this.markDirty(); + world.notifyBlockUpdate(pos, state, state, 2); + } + this.heatManager(this.getHeat(), state, this.getSlotStack(0), world, pos); } - this.heatManager(this.getHeat(), state, this.getSlotStack(0), world, pos); + slotZeroManager(world); + slotOneManager(); } - slotOneManager(); } } @@ -104,7 +101,7 @@ public class TileBloomery extends TileBaseSlot implements ITickable { private void slotZeroManager(World world){ if(this.getSlotStack(0) != ItemStack.EMPTY) { - Integer decrInt = (int) Math.floor(getVanillaItemBurnTime(this.getSlotStack(0)) / 10); + Integer decrInt = (int) Math.floor(getVanillaItemBurnTime(this.getSlotStack(0)) / 20); if(decrInt == 0) { decrInt = 1; } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileForge.java b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileForge.java index 12265a4f..f01e0abf 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileForge.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileForge.java @@ -33,19 +33,18 @@ public class TileForge extends TileBaseSlot implements ITickable { @Override public void update () { - if(!world.isRemote){ + if(!world.isRemote) { World world = this.getWorld(); - this.iteration ++; + this.iteration++; IBlockState state = world.getBlockState(this.pos); - BlockPos abovePos = new BlockPos(this.getPos().getX(), this.getPos().getY()+1, this.getPos().getZ()); + BlockPos abovePos = new BlockPos(this.getPos().getX(), this.getPos().getY() + 1, this.getPos().getZ()); IBlockState aboveState = world.getBlockState(abovePos); Block block = world.getBlockState(abovePos).getBlock(); - - if(this.iteration == 300 ) { - this.iteration = 0; + if (world.getBlockState(this.getPos()).getValue(PrimalStates.ACTIVE)) { + if (this.iteration == 300) { + this.iteration = 0; - if (world.getBlockState(this.getPos()).getValue(PrimalStates.ACTIVE)) { if (this.getSlotStack(0) == ItemStack.EMPTY) { world.setBlockState(this.getPos(), state.withProperty(PrimalStates.ACTIVE, false), 2); this.markDirty(); @@ -54,14 +53,15 @@ public class TileForge extends TileBaseSlot implements ITickable { slotZeroManager(world); } this.heatManager(this.getHeat(), state, this.getSlotStack(0), world, pos); + + craftingManager(); } - craftingManager(); } } private void slotZeroManager(World world){ if(this.getSlotStack(0) != ItemStack.EMPTY) { - Integer decrInt = (int) Math.floor(getVanillaItemBurnTime(this.getSlotStack(0)) / 10); + Integer decrInt = (int) Math.floor(getVanillaItemBurnTime(this.getSlotStack(0)) / 20); if(decrInt == 0) { decrInt = 1; } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java b/1.11/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java index b18bdbe9..edea9f0a 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java @@ -638,7 +638,7 @@ public interface AnvilHandler { tile.setSlotStack(counter, ItemStack.EMPTY); return true; } - +//TODO REFACTOR THIS CODE if (tile.getSlotStack(counter).getItem().equals(ModItems.pickaxehead)) { if (tile.getSlotStack(counter).getSubCompound("tags").getBoolean("hot") == false) { CommonUtils.spawnItemEntityFromWorld(world, pos, tile.getSlotStack(counter)); diff --git a/1.11/src/main/java/nmd/primal/forgecraft/util/CastingFormHandler.java b/1.11/src/main/java/nmd/primal/forgecraft/util/CastingFormHandler.java new file mode 100644 index 00000000..6fcb3918 --- /dev/null +++ b/1.11/src/main/java/nmd/primal/forgecraft/util/CastingFormHandler.java @@ -0,0 +1,111 @@ +package nmd.primal.forgecraft.util; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import nmd.primal.forgecraft.tiles.TileCastingForm; + +import static nmd.primal.forgecraft.blocks.CustomContainerFacing.FACING; + +/** + * Created by mminaie on 6/20/17. + */ +public interface CastingFormHandler { + + double[] normalMin = {0.1875, 0.3125, 0.4375, 0.5625, 0.6875}; + + default double getNormalMin(Integer x) { + return normalMin[x]; + } + + double[] normalMax = {0.3125, 0.4375, 0.5625, 0.6875, 0.8125}; + + default double getNormalMax(Integer x) { + return normalMax[x]; + } + + double[] reverseMin = {0.6875, 0.5625, 0.4375, 0.3125, 0.1875}; + + default double getReverseMin(Integer x) { + return reverseMin[x]; + } + + double[] reverseMax = {0.8125, 0.6875, 0.5625, 0.4375, 0.3125}; + + default double getReverseMax(Integer x) { + return reverseMax[x]; + } + + + + /***************************************************************************** + Adding and Removing Inventory With Tongs + *****************************************************************************/ + + default boolean doInventoryManager(ItemStack pItem, World world, TileCastingForm tile, BlockPos pos, float hitx, float hity, float hitz, IBlockState state, EntityPlayer player) { + + if (state.getValue(FACING) == EnumFacing.NORTH) { + int counter = 0; + for (int z = 0; z < 5; z++) { + for (int x = 0; x < 5; x++) { + if (hitx >= this.getNormalMin(x) && hitx <= this.getNormalMax(x)) { + if (hitz >= this.getNormalMin(z) && hitz <= this.getNormalMax(z)) { + System.out.println("North Facing: " + tile.getSlotStack(counter)); + return true; + } + } + counter++; + } + } + } + if (state.getValue(FACING) == EnumFacing.SOUTH) { + int counter = 0; + for (int z = 0; z < 5; z++) { + for (int x = 0; x < 5; x++) { + if (hitx >= this.getReverseMin(x) && hitx <= this.getReverseMax(x)) { + if (hitz >= this.getReverseMin(z) && hitz <= this.getReverseMax(z)) { + + return true; + } + } + counter++; + } + } + } + if (state.getValue(FACING) == EnumFacing.WEST) { + int counter = 0; + for (int x = 0; x < 5; x++) { + for (int z = 0; z < 5; z++) { + if (hitx >= this.getNormalMin(x) && hitx <= this.getNormalMax(x)) { + if (hitz >= this.getReverseMin(z) && hitz <= this.getReverseMax(z)) { + + return true; + } + } + counter++; + } + } + } + if (state.getValue(FACING) == EnumFacing.EAST) { + int counter = 0; + for (int x = 0; x < 5; x++) { + for (int z = 0; z < 5; z++) { + if (hitx >= this.getReverseMin(x) && hitx <= this.getReverseMax(x)) { + if (hitz >= this.getNormalMin(z) && hitz <= this.getNormalMax(z)) { + + return true; + } + } + counter++; + } + } + } + + return false; + } + + +} diff --git a/1.11/src/main/resources/assets/forgecraft/models/block/castingform.json b/1.11/src/main/resources/assets/forgecraft/models/block/castingform.json index 35d8e152..bcb41602 100644 --- a/1.11/src/main/resources/assets/forgecraft/models/block/castingform.json +++ b/1.11/src/main/resources/assets/forgecraft/models/block/castingform.json @@ -2,7 +2,8 @@ "__comment": "Designed by Kitsushadow with Cubik Studio - https://cubik.studio", "textures": { "particle": "blocks/log_oak", - "texture": "blocks/log_oak" + "texture": "blocks/log_oak", + "texture1": "forgecraft:blocks/castingform_top" }, "elements": [ { @@ -10,7 +11,7 @@ "from": [ 0, 2, 0 ], "to": [ 3, 5, 16 ], "faces": { - "up": { "uv": [ 0, 0, 3, 16 ], "texture": "#texture" }, + "up": { "uv": [ 0, 0, 3, 16 ], "texture": "#texture1" }, "north": { "uv": [ 13, 11, 16, 14 ], "texture": "#texture" }, "south": { "uv": [ 0, 11, 3, 14 ], "texture": "#texture" }, "west": { "uv": [ 0, 11, 16, 14 ], "texture": "#texture" }, @@ -22,7 +23,7 @@ "from": [ 13, 2, 0 ], "to": [ 16, 5, 16 ], "faces": { - "up": { "uv": [ 13, 0, 16, 16 ], "texture": "#texture" }, + "up": { "uv": [ 13, 0, 16, 16 ], "texture": "#texture1" }, "north": { "uv": [ 0, 11, 3, 14 ], "texture": "#texture" }, "south": { "uv": [ 13, 11, 16, 14 ], "texture": "#texture" }, "west": { "uv": [ 0, 11, 16, 14 ], "texture": "#texture" }, @@ -34,7 +35,7 @@ "from": [ 3, 2, 0 ], "to": [ 13, 5, 3 ], "faces": { - "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, + "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture1" }, "north": { "uv": [ 3, 11, 13, 14 ], "texture": "#texture" }, "south": { "uv": [ 3, 11, 13, 14 ], "texture": "#texture" } } @@ -44,7 +45,7 @@ "from": [ 3, 2, 13 ], "to": [ 13, 5, 16 ], "faces": { - "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, + "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture1" }, "north": { "uv": [ 3, 11, 13, 14 ], "texture": "#texture" }, "south": { "uv": [ 3, 11, 13, 14 ], "texture": "#texture" } } @@ -55,7 +56,7 @@ "to": [ 16, 2, 16 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture1" }, "north": { "uv": [ 0, 14, 16, 16 ], "texture": "#texture" }, "south": { "uv": [ 0, 14, 16, 16 ], "texture": "#texture" }, "west": { "uv": [ 0, 14, 16, 16 ], "texture": "#texture" }, diff --git a/1.11/src/main/resources/assets/forgecraft/textures/blocks/castingform_top.png b/1.11/src/main/resources/assets/forgecraft/textures/blocks/castingform_top.png new file mode 100644 index 0000000000000000000000000000000000000000..440077c0ca892566667cc753def1284d58052d59 GIT binary patch literal 699 zcmV;s0!00ZP)(lzg)0}D$ijso zac5Ae1`q`*K}xE8m13*YJNJ%@Vk0|vlG#jV-g9!!jJPv3W=Ai?a2$uLnFLQ}KXNTM zKrR*M+1x7GR2(TK)>?WyV;t5s@iv#eYK@8908(p>F$TwRc=-GsQcA82cegH2UN5KaS8^qdd<;dthrdqR}XqhPn_!;QKy82&}cOwOKymf0R;)2lpoJ z%EmtFM1<+-832l<{o?~60NTO|fXcxx0I5#H(^pH}$`2xa-^Un3G#cf!1VKQf(P)ZD zDM|Hp05CUS1mN!NNdP_-J^--3=>afva|D1div^TY>{O1B#u(ClaW=LqoP{6=a9tPW zI1cG#j5iA#+&@;XS9h98?|CO2t*jPX1B4I&$RG%?*0wfI!@;lL0CYsdC;-QCa9x+# z*KYyHXZiscP4}K~l*=|V=nP6M7n_Z!wXG^W9p_r9o`!HZjFgi8o(M{74S=<_rTDM! z%t-1)JNZo0dc+vC*3Ch_?~_i(&g5Wzc?+df^R>?0xM;^S2@a3`(9!NSSs;q?CN#te}));cFRV3{pz= hsx@-M-Sl?G_zS^4`}EJcN(%r0002ovPDHLkV1nxkG1344 literal 0 HcmV?d00001