diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFurnaceDouble.java index 8555c557d..5f0ab59f2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFurnaceDouble.java @@ -21,6 +21,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -41,6 +42,8 @@ import java.util.Random; public class BlockFurnaceDouble extends BlockContainerBase{ + public static final PropertyBool IS_ON = PropertyBool.create("on"); + public BlockFurnaceDouble(String name){ super(Material.ROCK, name); this.setHarvestLevel("pickaxe", 0); @@ -59,13 +62,9 @@ public class BlockFurnaceDouble extends BlockContainerBase{ @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){ - TileEntity tile = world.getTileEntity(pos); - if(tile instanceof TileEntityFurnaceDouble){ - TileEntityFurnaceDouble furnace = (TileEntityFurnaceDouble)tile; - if(furnace.firstSmeltTime > 0 || furnace.secondSmeltTime > 0){ - for(int i = 0; i < 5; i++){ - world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)pos.getX()+0.5F, (double)pos.getY()+1.0F, (double)pos.getZ()+0.5F, 0.0D, 0.0D, 0.0D); - } + if(state.getValue(IS_ON)){ + for(int i = 0; i < 5; i++){ + world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)pos.getX()+0.5F, (double)pos.getY()+1.0F, (double)pos.getZ()+0.5F, 0.0D, 0.0D, 0.0D); } } } @@ -84,7 +83,7 @@ public class BlockFurnaceDouble extends BlockContainerBase{ @Override public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos){ - return this.getMetaFromState(state) > 3 ? 12 : 0; + return state.getValue(IS_ON) ? 12 : 0; } @Override @@ -101,17 +100,20 @@ public class BlockFurnaceDouble extends BlockContainerBase{ @Override public IBlockState getStateFromMeta(int meta){ - return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta)); + boolean isOn = meta >= 4; + EnumFacing facing = EnumFacing.getHorizontal(isOn ? meta-4 : meta); + return this.getDefaultState().withProperty(BlockHorizontal.FACING, facing).withProperty(IS_ON, isOn); } @Override public int getMetaFromState(IBlockState state){ - return state.getValue(BlockHorizontal.FACING).getHorizontalIndex(); + int meta = state.getValue(BlockHorizontal.FACING).getHorizontalIndex(); + return state.getValue(IS_ON) ? meta+4 : meta; } @Override protected BlockStateContainer createBlockState(){ - return new BlockStateContainer(this, BlockHorizontal.FACING); + return new BlockStateContainer(this, BlockHorizontal.FACING, IS_ON); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGrinder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGrinder.java index f438de2d6..5a6908c30 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGrinder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGrinder.java @@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinder; import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinderDouble; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; @@ -55,19 +56,14 @@ public class BlockGrinder extends BlockContainerBase{ @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){ - TileEntity tile = world.getTileEntity(pos); - if(tile instanceof TileEntityGrinder){ - TileEntityGrinder crusher = (TileEntityGrinder)tile; - if(crusher.firstCrushTime > 0 || crusher.secondCrushTime > 0){ - for(int i = 0; i < 5; i++){ - double xRand = rand.nextDouble()/0.75D-0.5D; - double zRand = rand.nextDouble()/0.75D-0.5D; - world.spawnParticle(EnumParticleTypes.CRIT, (double)pos.getX()+0.4F, (double)pos.getY()+0.8F, (double)pos.getZ()+0.4F, xRand, 0.5D, zRand); - } - world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)pos.getX()+0.5F, (double)pos.getY()+1.0F, (double)pos.getZ()+0.5F, 0.0D, 0.0D, 0.0D); + if(state.getValue(BlockFurnaceDouble.IS_ON)){ + for(int i = 0; i < 5; i++){ + double xRand = rand.nextDouble()/0.75D-0.5D; + double zRand = rand.nextDouble()/0.75D-0.5D; + world.spawnParticle(EnumParticleTypes.CRIT, (double)pos.getX()+0.4F, (double)pos.getY()+0.8F, (double)pos.getZ()+0.4F, xRand, 0.5D, zRand); } + world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)pos.getX()+0.5F, (double)pos.getY()+1.0F, (double)pos.getZ()+0.5F, 0.0D, 0.0D, 0.0D); } - } @Override @@ -96,4 +92,21 @@ public class BlockGrinder extends BlockContainerBase{ public EnumRarity getRarity(ItemStack stack){ return EnumRarity.EPIC; } + + + @Override + public IBlockState getStateFromMeta(int meta){ + boolean isOn = meta == 1; + return this.getDefaultState().withProperty(BlockFurnaceDouble.IS_ON, isOn); + } + + @Override + public int getMetaFromState(IBlockState state){ + return state.getValue(BlockFurnaceDouble.IS_ON) ? 1 : 0; + } + + @Override + protected BlockStateContainer createBlockState(){ + return new BlockStateContainer(this, BlockFurnaceDouble.IS_ON); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java index 10c3fa9d3..af6c0585e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java @@ -10,10 +10,12 @@ package de.ellpeck.actuallyadditions.mod.tile; +import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; @@ -39,6 +41,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements private int lastFirstSmelt; private int lastSecondSmelt; private boolean lastAutoSplit; + private boolean lastSmelted; public TileEntityFurnaceDouble(){ super(4, "furnaceDouble"); @@ -104,7 +107,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements autoSplit(this.slots, SLOT_INPUT_1, SLOT_INPUT_2); } - boolean flag = this.firstSmeltTime > 0 || this.secondSmeltTime > 0; + boolean smelted = false; boolean canSmeltOnFirst = this.canSmeltOn(SLOT_INPUT_1, SLOT_OUTPUT_1); boolean canSmeltOnSecond = this.canSmeltOn(SLOT_INPUT_2, SLOT_OUTPUT_2); @@ -118,6 +121,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements } this.storage.extractEnergyInternal(ENERGY_USE, false); } + smelted = true; } else{ this.firstSmeltTime = 0; @@ -132,11 +136,21 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements } this.storage.extractEnergyInternal(ENERGY_USE, false); } + smelted = true; } else{ this.secondSmeltTime = 0; } + if(smelted != this.lastSmelted){ + IBlockState currState = this.world.getBlockState(this.pos); + if(currState.getValue(BlockFurnaceDouble.IS_ON) != smelted){ + this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, smelted)); + } + + this.lastSmelted = smelted; + } + if((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstSmelt != this.firstSmeltTime || this.lastSecondSmelt != this.secondSmeltTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()){ this.lastEnergy = this.storage.getEnergyStored(); this.lastFirstSmelt = this.firstSmeltTime; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java index dca31359e..268a14ad1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java @@ -11,11 +11,13 @@ package de.ellpeck.actuallyadditions.mod.tile; +import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceDouble; import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.Util; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -43,6 +45,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto private int lastFirstCrush; private int lastSecondCrush; private boolean lastAutoSplit; + private boolean lastCrushed; public TileEntityGrinder(int slots, String name){ super(slots, name); @@ -83,7 +86,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto TileEntityFurnaceDouble.autoSplit(this.slots, SLOT_INPUT_1, SLOT_INPUT_2); } - boolean flag = this.firstCrushTime > 0 || this.secondCrushTime > 0; + boolean crushed = false; boolean canCrushOnFirst = this.canCrushOn(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2); boolean canCrushOnSecond = false; @@ -105,6 +108,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto } this.storage.extractEnergyInternal(ENERGY_USE, false); } + crushed = true; } else{ this.firstCrushTime = 0; @@ -123,12 +127,22 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto } this.storage.extractEnergyInternal(ENERGY_USE, false); } + crushed = true; } else{ this.secondCrushTime = 0; } } + if(crushed != this.lastCrushed){ + IBlockState currState = this.world.getBlockState(this.pos); + if(currState.getValue(BlockFurnaceDouble.IS_ON) != crushed){ + this.world.setBlockState(this.pos, currState.withProperty(BlockFurnaceDouble.IS_ON, crushed)); + } + + this.lastCrushed = crushed; + } + if((this.lastEnergy != this.storage.getEnergyStored() || this.lastFirstCrush != this.firstCrushTime || this.lastSecondCrush != this.secondCrushTime || this.isAutoSplit != this.lastAutoSplit) && this.sendUpdateWithInterval()){ this.lastEnergy = this.storage.getEnergyStored(); this.lastFirstCrush = this.firstCrushTime; diff --git a/src/main/resources/assets/actuallyadditions/blockstates/block_furnace_double.json b/src/main/resources/assets/actuallyadditions/blockstates/block_furnace_double.json index 5e002479b..e17918842 100644 --- a/src/main/resources/assets/actuallyadditions/blockstates/block_furnace_double.json +++ b/src/main/resources/assets/actuallyadditions/blockstates/block_furnace_double.json @@ -21,6 +21,10 @@ "south": { "y" : 180 }, "west": { "y" : 270 }, "east": { "y" : 90 } + }, + "on": { + "true": { "textures": {"north": "actuallyadditions:blocks/block_furnace_double_on"} }, + "false": {} } } } \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/blockstates/block_grinder.json b/src/main/resources/assets/actuallyadditions/blockstates/block_grinder.json index a6fedf33b..584c6f689 100644 --- a/src/main/resources/assets/actuallyadditions/blockstates/block_grinder.json +++ b/src/main/resources/assets/actuallyadditions/blockstates/block_grinder.json @@ -11,6 +11,10 @@ }, "variants": { "normal": [{}], - "inventory": [{}] + "inventory": [{}], + "on": { + "true": { "textures": {"top": "actuallyadditions:blocks/block_grinder_on"} }, + "false": {} + } } } \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/blockstates/block_grinder_double.json b/src/main/resources/assets/actuallyadditions/blockstates/block_grinder_double.json index 26582224d..851fbd0f6 100644 --- a/src/main/resources/assets/actuallyadditions/blockstates/block_grinder_double.json +++ b/src/main/resources/assets/actuallyadditions/blockstates/block_grinder_double.json @@ -12,9 +12,9 @@ "variants": { "normal": [{}], "inventory": [{}], - "meta": { - "0": {}, - "1": { "textures": { "top": "actuallyadditions:blocks/block_grinder_on" } } + "on": { + "true": { "textures": {"top": "actuallyadditions:blocks/block_grinder_on"} }, + "false": {} } } } \ No newline at end of file