store direction in blocks

This commit is contained in:
Raoul Van den Berge
2015-12-26 15:40:58 +01:00
parent 900ad2d2f1
commit 4bd38b0e61
5 changed files with 48 additions and 26 deletions

View File

@@ -3,12 +3,16 @@ package storagecraft.block;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase; import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import storagecraft.StorageCraft; import storagecraft.StorageCraft;
import storagecraft.tile.TileBase; import storagecraft.tile.TileBase;
@@ -16,6 +20,8 @@ import storagecraft.util.InventoryUtils;
public abstract class BlockBase extends Block public abstract class BlockBase extends Block
{ {
public static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
private String name; private String name;
public BlockBase(String name) public BlockBase(String name)
@@ -33,6 +39,40 @@ public abstract class BlockBase extends Block
return "block." + StorageCraft.ID + ":" + name; return "block." + StorageCraft.ID + ":" + name;
} }
@Override
protected BlockState createBlockState()
{
return new BlockState(this, new IProperty[]
{
DIRECTION,
});
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState();
}
@Override
public int getMetaFromState(IBlockState state)
{
return 0;
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase)
{
return state.withProperty(DIRECTION, ((TileBase) tile).getDirection());
}
return state;
}
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {

View File

@@ -27,6 +27,7 @@ public class BlockCable extends BlockBase implements ITileEntityProvider
{ {
return new BlockState(this, new IProperty[] return new BlockState(this, new IProperty[]
{ {
DIRECTION,
SENSITIVE SENSITIVE
}); });
} }

View File

@@ -29,26 +29,16 @@ public class BlockController extends BlockBase implements ITileEntityProvider
{ {
return new BlockState(this, new IProperty[] return new BlockState(this, new IProperty[]
{ {
DIRECTION,
ENERGY ENERGY
}); });
} }
@Override
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState();
}
@Override
public int getMetaFromState(IBlockState state)
{
return 0;
}
@Override @Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{ {
return state.withProperty(ENERGY, ((TileController) world.getTileEntity(pos)).getEnergyScaled(15)); return super.getActualState(state, world, pos)
.withProperty(ENERGY, ((TileController) world.getTileEntity(pos)).getEnergyScaled(15));
} }
@Override @Override

View File

@@ -47,6 +47,7 @@ public class BlockGrid extends BlockMachine
{ {
return new BlockState(this, new IProperty[] return new BlockState(this, new IProperty[]
{ {
DIRECTION,
CONNECTED, CONNECTED,
TYPE TYPE
}); });

View File

@@ -23,25 +23,15 @@ public abstract class BlockMachine extends BlockBase implements ITileEntityProvi
{ {
return new BlockState(this, new IProperty[] return new BlockState(this, new IProperty[]
{ {
DIRECTION,
CONNECTED CONNECTED
}); });
} }
@Override
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState();
}
@Override
public int getMetaFromState(IBlockState state)
{
return 0;
}
@Override @Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{ {
return state.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected()); return super.getActualState(state, world, pos)
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
} }
} }