store direction in blocks
This commit is contained in:
@@ -3,12 +3,16 @@ package storagecraft.block;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockPistonBase;
|
||||
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.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.tile.TileBase;
|
||||
@@ -16,6 +20,8 @@ import storagecraft.util.InventoryUtils;
|
||||
|
||||
public abstract class BlockBase extends Block
|
||||
{
|
||||
public static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
|
||||
|
||||
private String name;
|
||||
|
||||
public BlockBase(String name)
|
||||
@@ -33,6 +39,40 @@ public abstract class BlockBase extends Block
|
||||
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
|
||||
public int damageDropped(IBlockState state)
|
||||
{
|
||||
|
@@ -27,6 +27,7 @@ public class BlockCable extends BlockBase implements ITileEntityProvider
|
||||
{
|
||||
return new BlockState(this, new IProperty[]
|
||||
{
|
||||
DIRECTION,
|
||||
SENSITIVE
|
||||
});
|
||||
}
|
||||
|
@@ -29,26 +29,16 @@ public class BlockController extends BlockBase implements ITileEntityProvider
|
||||
{
|
||||
return new BlockState(this, new IProperty[]
|
||||
{
|
||||
DIRECTION,
|
||||
ENERGY
|
||||
});
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
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
|
||||
|
@@ -47,6 +47,7 @@ public class BlockGrid extends BlockMachine
|
||||
{
|
||||
return new BlockState(this, new IProperty[]
|
||||
{
|
||||
DIRECTION,
|
||||
CONNECTED,
|
||||
TYPE
|
||||
});
|
||||
|
@@ -23,25 +23,15 @@ public abstract class BlockMachine extends BlockBase implements ITileEntityProvi
|
||||
{
|
||||
return new BlockState(this, new IProperty[]
|
||||
{
|
||||
DIRECTION,
|
||||
CONNECTED
|
||||
});
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
return state.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
||||
return super.getActualState(state, world, pos)
|
||||
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user