Made furnace and crusher have different textures when smelting again

This commit is contained in:
Ellpeck 2017-02-22 12:37:29 +01:00
parent 498358ddcb
commit cd59523e06
7 changed files with 79 additions and 28 deletions

View file

@ -21,6 +21,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
@ -41,6 +42,8 @@ import java.util.Random;
public class BlockFurnaceDouble extends BlockContainerBase{ public class BlockFurnaceDouble extends BlockContainerBase{
public static final PropertyBool IS_ON = PropertyBool.create("on");
public BlockFurnaceDouble(String name){ public BlockFurnaceDouble(String name){
super(Material.ROCK, name); super(Material.ROCK, name);
this.setHarvestLevel("pickaxe", 0); this.setHarvestLevel("pickaxe", 0);
@ -59,16 +62,12 @@ public class BlockFurnaceDouble extends BlockContainerBase{
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){ public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){
TileEntity tile = world.getTileEntity(pos); if(state.getValue(IS_ON)){
if(tile instanceof TileEntityFurnaceDouble){
TileEntityFurnaceDouble furnace = (TileEntityFurnaceDouble)tile;
if(furnace.firstSmeltTime > 0 || furnace.secondSmeltTime > 0){
for(int i = 0; i < 5; i++){ 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); 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 @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
@ -84,7 +83,7 @@ public class BlockFurnaceDouble extends BlockContainerBase{
@Override @Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos){ public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos){
return this.getMetaFromState(state) > 3 ? 12 : 0; return state.getValue(IS_ON) ? 12 : 0;
} }
@Override @Override
@ -101,17 +100,20 @@ public class BlockFurnaceDouble extends BlockContainerBase{
@Override @Override
public IBlockState getStateFromMeta(int meta){ 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 @Override
public int getMetaFromState(IBlockState state){ 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 @Override
protected BlockStateContainer createBlockState(){ protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, BlockHorizontal.FACING); return new BlockStateContainer(this, BlockHorizontal.FACING, IS_ON);
} }
@Override @Override

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinder;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinderDouble; import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinderDouble;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
@ -55,10 +56,7 @@ public class BlockGrinder extends BlockContainerBase{
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){ public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand){
TileEntity tile = world.getTileEntity(pos); if(state.getValue(BlockFurnaceDouble.IS_ON)){
if(tile instanceof TileEntityGrinder){
TileEntityGrinder crusher = (TileEntityGrinder)tile;
if(crusher.firstCrushTime > 0 || crusher.secondCrushTime > 0){
for(int i = 0; i < 5; i++){ for(int i = 0; i < 5; i++){
double xRand = rand.nextDouble()/0.75D-0.5D; double xRand = rand.nextDouble()/0.75D-0.5D;
double zRand = rand.nextDouble()/0.75D-0.5D; double zRand = rand.nextDouble()/0.75D-0.5D;
@ -68,8 +66,6 @@ public class BlockGrinder extends BlockContainerBase{
} }
} }
}
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
if(!world.isRemote){ if(!world.isRemote){
@ -96,4 +92,21 @@ public class BlockGrinder extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; 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);
}
} }

View file

@ -10,10 +10,12 @@
package de.ellpeck.actuallyadditions.mod.tile; 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.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
@ -39,6 +41,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
private int lastFirstSmelt; private int lastFirstSmelt;
private int lastSecondSmelt; private int lastSecondSmelt;
private boolean lastAutoSplit; private boolean lastAutoSplit;
private boolean lastSmelted;
public TileEntityFurnaceDouble(){ public TileEntityFurnaceDouble(){
super(4, "furnaceDouble"); super(4, "furnaceDouble");
@ -104,7 +107,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
autoSplit(this.slots, SLOT_INPUT_1, SLOT_INPUT_2); 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 canSmeltOnFirst = this.canSmeltOn(SLOT_INPUT_1, SLOT_OUTPUT_1);
boolean canSmeltOnSecond = this.canSmeltOn(SLOT_INPUT_2, SLOT_OUTPUT_2); 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); this.storage.extractEnergyInternal(ENERGY_USE, false);
} }
smelted = true;
} }
else{ else{
this.firstSmeltTime = 0; this.firstSmeltTime = 0;
@ -132,11 +136,21 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
} }
this.storage.extractEnergyInternal(ENERGY_USE, false); this.storage.extractEnergyInternal(ENERGY_USE, false);
} }
smelted = true;
} }
else{ else{
this.secondSmeltTime = 0; 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()){ 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.lastEnergy = this.storage.getEnergyStored();
this.lastFirstSmelt = this.firstSmeltTime; this.lastFirstSmelt = this.firstSmeltTime;

View file

@ -11,11 +11,13 @@
package de.ellpeck.actuallyadditions.mod.tile; 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.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry; import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -43,6 +45,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
private int lastFirstCrush; private int lastFirstCrush;
private int lastSecondCrush; private int lastSecondCrush;
private boolean lastAutoSplit; private boolean lastAutoSplit;
private boolean lastCrushed;
public TileEntityGrinder(int slots, String name){ public TileEntityGrinder(int slots, String name){
super(slots, 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); 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 canCrushOnFirst = this.canCrushOn(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2);
boolean canCrushOnSecond = false; boolean canCrushOnSecond = false;
@ -105,6 +108,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
} }
this.storage.extractEnergyInternal(ENERGY_USE, false); this.storage.extractEnergyInternal(ENERGY_USE, false);
} }
crushed = true;
} }
else{ else{
this.firstCrushTime = 0; this.firstCrushTime = 0;
@ -123,12 +127,22 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
} }
this.storage.extractEnergyInternal(ENERGY_USE, false); this.storage.extractEnergyInternal(ENERGY_USE, false);
} }
crushed = true;
} }
else{ else{
this.secondCrushTime = 0; 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()){ 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.lastEnergy = this.storage.getEnergyStored();
this.lastFirstCrush = this.firstCrushTime; this.lastFirstCrush = this.firstCrushTime;

View file

@ -21,6 +21,10 @@
"south": { "y" : 180 }, "south": { "y" : 180 },
"west": { "y" : 270 }, "west": { "y" : 270 },
"east": { "y" : 90 } "east": { "y" : 90 }
},
"on": {
"true": { "textures": {"north": "actuallyadditions:blocks/block_furnace_double_on"} },
"false": {}
} }
} }
} }

View file

@ -11,6 +11,10 @@
}, },
"variants": { "variants": {
"normal": [{}], "normal": [{}],
"inventory": [{}] "inventory": [{}],
"on": {
"true": { "textures": {"top": "actuallyadditions:blocks/block_grinder_on"} },
"false": {}
}
} }
} }

View file

@ -12,9 +12,9 @@
"variants": { "variants": {
"normal": [{}], "normal": [{}],
"inventory": [{}], "inventory": [{}],
"meta": { "on": {
"0": {}, "true": { "textures": {"top": "actuallyadditions:blocks/block_grinder_on"} },
"1": { "textures": { "top": "actuallyadditions:blocks/block_grinder_on" } } "false": {}
} }
} }
} }