Tile Entities retain powered state

This commit is contained in:
Kino 2017-12-27 23:53:29 -05:00
parent 8e384bd634
commit 5974ee817e
11 changed files with 84 additions and 88 deletions

View file

@ -2,6 +2,9 @@ package com.legacy.aether.blocks.container;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
@ -14,9 +17,13 @@ import com.legacy.aether.tile_entities.util.AetherTileEntity;
public abstract class BlockAetherContainer extends BlockContainer
{
public static final PropertyBool powered = PropertyBool.create("powered");
public BlockAetherContainer(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.getDefaultState().withProperty(powered, false));
}
@Override
@ -33,4 +40,36 @@ public abstract class BlockAetherContainer extends BlockContainer
}
}
public static void setState(World worldIn, BlockPos pos, boolean isActive)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
worldIn.setBlockState(pos, iblockstate.withProperty(powered, isActive), 3);
if (tileentity != null)
{
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(powered, meta == 1);
}
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(powered) ? 1 : 0;
}
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {powered});
}
}

View file

@ -51,9 +51,7 @@ public class BlockEnchanter extends BlockAetherContainer
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random)
{
TileEntityEnchanter tileentity = (TileEntityEnchanter)world.getTileEntity(pos);
if(tileentity.isBurning())
if(state.getValue(powered).booleanValue())
{
float f = (float)pos.getX() + 0.5F;
float f1 = (float)pos.getY() + 1.0F + (random.nextFloat() * 6F) / 16F;

View file

@ -51,9 +51,7 @@ public class BlockFreezer extends BlockAetherContainer
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random)
{
TileEntityFreezer tileentity = (TileEntityFreezer)world.getTileEntity(pos);
if(tileentity.isBurning())
if(state.getValue(powered).booleanValue())
{
float f = (float)pos.getX() + 0.5F;
float f1 = (float)pos.getY() + 1.0F + (random.nextFloat() * 6F) / 16F;
@ -65,8 +63,11 @@ public class BlockFreezer extends BlockAetherContainer
{
world.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, f, f1, f2, 0.0D, 0.0D, 0.0D);
}
if (random.nextDouble() < 0.1D)
{
world.playSound((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 3.0F, false);
}
}
}

View file

@ -54,14 +54,12 @@ public class BlockIncubator extends BlockAetherContainer
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random)
{
TileEntityIncubator tileentity = (TileEntityIncubator)world.getTileEntity(pos);
if(tileentity.isBurning())
if(state.getValue(powered).booleanValue())
{
float f = (float)pos.getX() + 0.5F;
float f1 = (float)pos.getY() + 1.0F + (random.nextFloat() * 60F) / 16F;

View file

@ -46,7 +46,7 @@ public class GuiEnchanter extends GuiContainer
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;
if (this.enchanter.isBurning())
if (this.enchanter.isEnchanting())
{
i1 = this.enchanter.getEnchantmentTimeRemaining(12);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);

View file

@ -46,7 +46,7 @@ public class GuiFreezer extends GuiContainer
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;
if (this.freezer.isBurning())
if (this.freezer.isFreezing())
{
i1 = this.freezer.getEnchantmentTimeRemaining(12);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);

View file

@ -44,7 +44,7 @@ public class GuiIncubator extends GuiContainer
this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize);
if (this.incubatorInventory.isBurning())
if (this.incubatorInventory.isIncubating())
{
int l = this.incubatorInventory.getPowerTimeRemainingScaled(12);

View file

@ -15,6 +15,7 @@ import net.minecraft.util.ResourceLocation;
import com.legacy.aether.Aether;
import com.legacy.aether.blocks.BlocksAether;
import com.legacy.aether.blocks.container.BlockAetherContainer;
import com.legacy.aether.blocks.decorative.BlockAetherFenceGate;
import com.legacy.aether.blocks.natural.BlockAetherDirt;
import com.legacy.aether.blocks.natural.BlockAetherGrass;
@ -46,6 +47,9 @@ public class BlockRendering
registerBlockWithStateMapper(BlocksAether.crystal_leaves, (new StateMap.Builder()).ignore(BlockCrystalLeaves.CHECK_DECAY).ignore(BlockCrystalLeaves.DECAYABLE).build());
registerBlockWithStateMapper(BlocksAether.holiday_leaves, (new StateMap.Builder()).ignore(BlockHolidayLeaves.CHECK_DECAY).ignore(BlockHolidayLeaves.DECAYABLE).build());
registerBlockWithStateMapper(BlocksAether.skyroot_fence_gate, (new StateMap.Builder()).ignore(BlockAetherFenceGate.POWERED).build());
registerBlockWithStateMapper(BlocksAether.enchanter, (new StateMap.Builder()).ignore(BlockAetherContainer.powered).build());
registerBlockWithStateMapper(BlocksAether.incubator, (new StateMap.Builder()).ignore(BlockAetherContainer.powered).build());
registerBlockWithStateMapper(BlocksAether.freezer, (new StateMap.Builder()).ignore(BlockAetherContainer.powered).build());
register(BlocksAether.enchanted_aether_grass, "enchanted_aether_grass");
register(BlocksAether.holystone_brick, "holystone_brick");

View file

@ -14,6 +14,7 @@ import com.legacy.aether.api.AetherAPI;
import com.legacy.aether.api.enchantments.AetherEnchantment;
import com.legacy.aether.api.events.AetherHooks;
import com.legacy.aether.blocks.BlocksAether;
import com.legacy.aether.blocks.container.BlockAetherContainer;
import com.legacy.aether.tile_entities.util.AetherTileEntity;
public class TileEntityEnchanter extends AetherTileEntity
@ -45,6 +46,8 @@ public class TileEntityEnchanter extends AetherTileEntity
@Override
public void update()
{
boolean flag = this.isEnchanting();
if (this.powerRemaining > 0)
{
this.powerRemaining--;
@ -142,6 +145,12 @@ public class TileEntityEnchanter extends AetherTileEntity
}
}
}
if (flag != this.isEnchanting())
{
this.markDirty();
BlockAetherContainer.setState(this.worldObj, this.pos, this.isEnchanting());
}
}
public void addEnchantmentWeight(ItemStack stack)
@ -157,12 +166,6 @@ public class TileEntityEnchanter extends AetherTileEntity
}
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@SideOnly(Side.CLIENT)
public int getEnchantmentProgressScaled(int i)
{
@ -179,76 +182,11 @@ public class TileEntityEnchanter extends AetherTileEntity
return (this.powerRemaining * i) / 500;
}
public boolean isBurning()
public boolean isEnchanting()
{
return this.powerRemaining > 0;
}
@Override
public int getSizeInventory()
{
return this.enchantedItemStacks.length;
}
@Override
public ItemStack getStackInSlot(int i)
{
return this.enchantedItemStacks[i];
}
@Override
public ItemStack decrStackSize(int i, int j)
{
if (this.enchantedItemStacks[i] != null)
{
if (this.enchantedItemStacks[i].stackSize <= j)
{
ItemStack itemstack = this.enchantedItemStacks[i];
this.enchantedItemStacks[i] = null;
return itemstack;
}
else
{
ItemStack itemstack1 = this.enchantedItemStacks[i].splitStack(j);
if (this.enchantedItemStacks[i].stackSize == 0)
{
this.enchantedItemStacks[i] = null;
}
return itemstack1;
}
}
else
{
return null;
}
}
@Override
public ItemStack removeStackFromSlot(int par1)
{
if (this.enchantedItemStacks[par1] != null)
{
ItemStack var2 = this.enchantedItemStacks[par1];
this.enchantedItemStacks[par1] = null;
return var2;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
this.enchantedItemStacks[i] = itemstack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
{
itemstack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{

View file

@ -14,6 +14,7 @@ import com.legacy.aether.api.AetherAPI;
import com.legacy.aether.api.events.AetherHooks;
import com.legacy.aether.api.freezables.AetherFreezable;
import com.legacy.aether.blocks.BlocksAether;
import com.legacy.aether.blocks.container.BlockAetherContainer;
import com.legacy.aether.tile_entities.util.AetherTileEntity;
public class TileEntityFreezer extends AetherTileEntity
@ -45,6 +46,8 @@ public class TileEntityFreezer extends AetherTileEntity
@Override
public void update()
{
boolean flag = this.isFreezing();
if (this.powerRemaining > 0)
{
this.powerRemaining--;
@ -130,6 +133,12 @@ public class TileEntityFreezer extends AetherTileEntity
}
}
}
if (flag != this.isFreezing())
{
this.markDirty();
BlockAetherContainer.setState(this.worldObj, this.pos, this.isFreezing());
}
}
public void addEnchantmentWeight(ItemStack stack)
@ -161,7 +170,7 @@ public class TileEntityFreezer extends AetherTileEntity
return (this.powerRemaining * i) / 500;
}
public boolean isBurning()
public boolean isFreezing()
{
return this.powerRemaining > 0;
}

View file

@ -8,6 +8,7 @@ import net.minecraft.util.EnumFacing;
import com.legacy.aether.api.events.AetherHooks;
import com.legacy.aether.blocks.BlocksAether;
import com.legacy.aether.blocks.container.BlockAetherContainer;
import com.legacy.aether.entities.passive.mountable.EntityMoa;
import com.legacy.aether.items.ItemMoaEgg;
import com.legacy.aether.items.ItemsAether;
@ -73,7 +74,7 @@ public class TileEntityIncubator extends AetherTileEntity
return (this.powerRemaining * i) / 500;
}
public boolean isBurning()
public boolean isIncubating()
{
return this.getField(1) > 0;
}
@ -81,6 +82,8 @@ public class TileEntityIncubator extends AetherTileEntity
@Override
public void update()
{
boolean flag = this.isIncubating();
if (this.powerRemaining > 0)
{
this.powerRemaining--;
@ -146,6 +149,12 @@ public class TileEntityIncubator extends AetherTileEntity
this.progress = 0;
}
}
if (flag != this.isIncubating())
{
this.markDirty();
BlockAetherContainer.setState(this.worldObj, this.pos, this.isIncubating());
}
}
@Override