From 6557b3df6f000834fa5d116afe847e3192a14d1d Mon Sep 17 00:00:00 2001 From: Mohammad-Ali Minaie Date: Thu, 26 Jan 2017 17:21:15 -0500 Subject: [PATCH] logic for bloomery in tile doesnt work --- .../primal/forgecraft/blocks/Bloomery.java | 4 +- .../forgecraft/blocks/PistonBellows.java | 54 ++++++++++++++----- .../forgecraft/crafting/BloomeryCrafting.java | 4 +- .../primal/forgecraft/init/ModCrafting.java | 9 ++-- .../primal/forgecraft/tiles/TileBloomery.java | 45 +++++++++++++++- 5 files changed, 96 insertions(+), 20 deletions(-) diff --git a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Bloomery.java b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Bloomery.java index 81008b9e..8fda83f8 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Bloomery.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Bloomery.java @@ -33,6 +33,7 @@ import nmd.primal.forgecraft.tiles.TileBloomery; import nmd.primal.forgecraft.tiles.TileFirebox; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * Created by mminaie on 1/21/17. @@ -433,7 +434,8 @@ public class Bloomery extends CustomContainerFacing implements ITileEntityProvid double d1 = (double)pos.getY() + 0.2D; double d2 = (double)pos.getZ() + 0.5D; double d3 = 0.52D; - double d4 = rand.nextDouble() * 0.6D - 0.3D; + //double d4 = rand.nextDouble() * 0.6D - 0.3D; + double d4 = ThreadLocalRandom.current().nextDouble(0.15, 0.35); if (rand.nextDouble() < 0.1D) { diff --git a/1.11/src/main/java/nmd/primal/forgecraft/blocks/PistonBellows.java b/1.11/src/main/java/nmd/primal/forgecraft/blocks/PistonBellows.java index 68b830d0..c7c7168d 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/blocks/PistonBellows.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/blocks/PistonBellows.java @@ -1,5 +1,6 @@ package nmd.primal.forgecraft.blocks; +import javafx.scene.effect.Bloom; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; @@ -26,6 +27,7 @@ import nmd.primal.forgecraft.tiles.TileFirebox; import nmd.primal.forgecraft.tiles.TilePistonBellows; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * Created by mminaie on 1/1/17. @@ -389,8 +391,15 @@ public class PistonBellows extends CustomContainerFacing { makeEmbers(world, tempPos, world.rand); } } - + if (world.getBlockState(tempPos).getBlock() instanceof Bloomery) { + TileBloomery tile = (TileBloomery) world.getTileEntity(tempPos); + if ((world.getBlockState(tempPos).getValue(Bloomery.ACTIVE) == true) && (world.getBlockState(tempPos).getValue(Bloomery.FACING) == EnumFacing.EAST)) { + makeEmbers(world, tempPos, world.rand); + } + } } + + if (state.getValue(PistonBellows.FACING) == EnumFacing.SOUTH) { BlockPos tempPos = new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()); if (world.getBlockState(tempPos).getBlock() == ModBlocks.firebox) { @@ -399,8 +408,15 @@ public class PistonBellows extends CustomContainerFacing { makeEmbers(world, tempPos, world.rand); } } - + if (world.getBlockState(tempPos).getBlock() instanceof Bloomery) { + TileBloomery tile = (TileBloomery) world.getTileEntity(tempPos); + if ((world.getBlockState(tempPos).getValue(Bloomery.ACTIVE) == true) && (world.getBlockState(tempPos).getValue(Bloomery.FACING) == EnumFacing.WEST)) { + makeEmbers(world, tempPos, world.rand); + } + } } + + if (state.getValue(PistonBellows.FACING) == EnumFacing.EAST) { BlockPos tempPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1); if (world.getBlockState(tempPos).getBlock() == ModBlocks.firebox) { @@ -409,8 +425,15 @@ public class PistonBellows extends CustomContainerFacing { makeEmbers(world, tempPos, world.rand); } } - + if (world.getBlockState(tempPos).getBlock() instanceof Bloomery) { + TileBloomery tile = (TileBloomery) world.getTileEntity(tempPos); + if ((world.getBlockState(tempPos).getValue(Bloomery.ACTIVE) == true) && (world.getBlockState(tempPos).getValue(Bloomery.FACING) == EnumFacing.SOUTH)) { + makeEmbers(world, tempPos, world.rand); + } + } } + + if (state.getValue(PistonBellows.FACING) == EnumFacing.WEST) { BlockPos tempPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1); if (world.getBlockState(tempPos).getBlock() == ModBlocks.firebox) { @@ -419,6 +442,12 @@ public class PistonBellows extends CustomContainerFacing { makeEmbers(world, tempPos, world.rand); } } + if (world.getBlockState(tempPos).getBlock() instanceof Bloomery) { + TileBloomery tile = (TileBloomery) world.getTileEntity(tempPos); + if ((world.getBlockState(tempPos).getValue(Bloomery.ACTIVE) == true) && (world.getBlockState(tempPos).getValue(Bloomery.FACING) == EnumFacing.NORTH)) { + makeEmbers(world, tempPos, world.rand); + } + } } } } @@ -427,23 +456,24 @@ public class PistonBellows extends CustomContainerFacing { double d1 = (double)pos.getY() + 0.96D; double d2 = (double)pos.getZ() + 0.5D; double d3 = 0.52D; - double d4 = rand.nextDouble() * 0.6D - 0.3D; + double d4 = ThreadLocalRandom.current().nextDouble(0.175, 0.35); + double ySpeed = 0.1D; if(rand.nextInt(3) == 0){ - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); } if(rand.nextInt(3) == 1){ - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2-d4, 0.0D, 0.1D, 0.0D, new int[0]); - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2-d4, 0.0D, ySpeed, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); } if(rand.nextInt(3) == 2){ - world.spawnParticle(EnumParticleTypes.FLAME, d0-d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0-d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); } if(rand.nextInt(3) == 3){ - world.spawnParticle(EnumParticleTypes.FLAME, d0-d4, d1, d2-d4, 0.0D, 0.1D, 0.0D, new int[0]); - world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, 0.1D, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0-d4, d1, d2-d4, 0.0D, ySpeed, 0.0D, new int[0]); + world.spawnParticle(EnumParticleTypes.FLAME, d0+d4, d1, d2+d4, 0.0D, ySpeed, 0.0D, new int[0]); } } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/crafting/BloomeryCrafting.java b/1.11/src/main/java/nmd/primal/forgecraft/crafting/BloomeryCrafting.java index ca4e9412..8c9a0499 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/crafting/BloomeryCrafting.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/crafting/BloomeryCrafting.java @@ -95,9 +95,9 @@ public class BloomeryCrafting { return this.ideal_time; } - public float getHeat_variance(){return this.heat_variance; } + public float getHeatVariance(){return this.heat_variance; } - public float getTime_variance(){return this.time_variance; } + public float getTimeVariance(){return this.time_variance; } /// // end 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 214e2886..18658238 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 @@ -2,6 +2,7 @@ package nmd.primal.forgecraft.init; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.registry.GameRegistry; import nmd.primal.forgecraft.blocks.Bloomery; @@ -37,12 +38,12 @@ public class ModCrafting { //DryingRecipe.addRecipe(new ItemStack(Items.FISH, 1, 0), new ItemStack(PrimalItems.FISH_COD_DRIED), new ItemStack(PrimalItems.FISH_COD_ROTTEN), 25, 0.006F); BloomeryCrafting.addRecipe( new ItemStack(ModItems.softcrucible, 1), - new ItemStack(ModBlocks.emptycrucible, 1), + new ItemStack(Item.getItemFromBlock(ModBlocks.emptycrucible), 1), //new ItemStack(ModItems.crackedcrucible, 1), new ItemStack(Items.STICK, 1), - 2100, - 2400, - 0.25f, + 500, + 500, + 1.25f, 1.0f); } } 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 71d19770..0cdec0e4 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 @@ -13,6 +13,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import nmd.primal.forgecraft.blocks.Bloomery; import nmd.primal.forgecraft.blocks.Firebox; +import nmd.primal.forgecraft.crafting.BloomeryCrafting; import nmd.primal.forgecraft.init.ModItems; import static nmd.primal.forgecraft.CommonUtils.getVanillaItemBurnTime; @@ -25,6 +26,7 @@ public class TileBloomery extends TileBaseSlot implements ITickable { private NonNullList slotList = NonNullList.withSize(3, ItemStack.EMPTY); private int iteration = 0; private int heat; + private int cookCounter; @Override public void update () { @@ -46,10 +48,49 @@ public class TileBloomery extends TileBaseSlot implements ITickable { } this.heatManager(this.getHeat(), state, this.getSlotStack(0)); } + slotOneManager(); } } - //Insert Slot 1 manager for crafting + private void slotOneManager(){ + BloomeryCrafting recipe = BloomeryCrafting.getRecipe(this.getSlotStack(1)); + if(recipe != null){ + System.out.println(recipe.getInput() + " : " + recipe.getOutput() + " : " + recipe.getIdealTime() + " : " + recipe.getHeatThreshold()); + System.out.println(this.getSlotStack(1) + " : " + this.cookCounter + " : " + this.getHeat()); + if(this.getHeat() >= recipe.getHeatThreshold()){ + cookCounter++; + //System.out.println(cookCounter); + } + if(cookCounter >= recipe.getIdealTime()){ + if(this.getSlotStack(1) == recipe.getInput()) { + this.setSlotStack(1, recipe.getOutput()); + System.out.print(" :Success: " + this.getSlotStack(1)); + this.updateBlock(); + this.markDirty(); + } + } + if( cookCounter > recipe.getIdealTime() + (recipe.getIdealTime() * recipe.getTimeVariance())){ + if(this.getSlotStack(1) == recipe.getInput()) { + this.setSlotStack(1, recipe.getOutputFailed()); + this.cookCounter = 0; + System.out.print(" :Failure Time: " + this.getSlotStack(1)); + this.updateBlock(); + this.markDirty(); + } + + } + if(this.getHeat() > recipe.getHeatThreshold() + (recipe.getHeatThreshold() * recipe.getHeatVariance())){ + this.setSlotStack(1, recipe.getOutputFailed()); + this.cookCounter = 0; + System.out.print(" :Failure Heat: " + this.getSlotStack(1)); + this.updateBlock(); + this.markDirty(); + } + if (this.getSlotStack(1).isEmpty()){ + this.cookCounter=0; + } + } + } private void slotZeroManager(World world){ if(this.getSlotStack(0) != ItemStack.EMPTY) { @@ -143,6 +184,7 @@ public class TileBloomery extends TileBaseSlot implements ITickable { { super.readNBT(nbt); this.heat = nbt.getInteger("heat"); + this.cookCounter = nbt.getInteger("cook"); return nbt; } @@ -150,6 +192,7 @@ public class TileBloomery extends TileBaseSlot implements ITickable { public NBTTagCompound writeNBT(NBTTagCompound nbt) { nbt.setInteger("heat", this.heat); + nbt.setInteger("cook", this.cookCounter); super.writeNBT(nbt); return nbt; }