initial 1.8 port
This commit is contained in:
@@ -1,92 +1,87 @@
|
||||
package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockPistonBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.tile.TileBase;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public abstract class BlockBase extends Block
|
||||
{
|
||||
private String name;
|
||||
|
||||
public BlockBase(String name)
|
||||
{
|
||||
super(Material.rock);
|
||||
|
||||
this.name = name;
|
||||
|
||||
setCreativeTab(StorageCraft.TAB);
|
||||
setBlockTextureName("storagecraft:" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return "block." + StorageCraft.ID + ":" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileBase)
|
||||
{
|
||||
ForgeDirection dir = ((TileBase) tile).getDirection();
|
||||
|
||||
int newDir = dir.ordinal() + 1;
|
||||
|
||||
if (newDir > ForgeDirection.VALID_DIRECTIONS.length - 1)
|
||||
{
|
||||
newDir = 0;
|
||||
}
|
||||
|
||||
((TileBase) tile).setDirection(ForgeDirection.getOrientation(newDir));
|
||||
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int meta)
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
||||
{
|
||||
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileBase)
|
||||
{
|
||||
((TileBase) tile).setDirection(ForgeDirection.getOrientation(BlockPistonBase.determineOrientation(world, x, y, z, entityLiving)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPreDestroy(World world, int x, int y, int z, int meta)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileBase && ((TileBase) tile).getDroppedInventory() != null)
|
||||
{
|
||||
InventoryUtils.dropInventory(world, ((TileBase) tile).getDroppedInventory(), x, y, z);
|
||||
}
|
||||
|
||||
super.onBlockPreDestroy(world, x, y, z, meta);
|
||||
}
|
||||
}
|
||||
package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockPistonBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
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.World;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.tile.TileBase;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public abstract class BlockBase extends Block
|
||||
{
|
||||
private String name;
|
||||
|
||||
public BlockBase(String name)
|
||||
{
|
||||
super(Material.rock);
|
||||
|
||||
this.name = name;
|
||||
|
||||
setCreativeTab(StorageCraft.TAB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return "block." + StorageCraft.ID + ":" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileBase)
|
||||
{
|
||||
EnumFacing dir = ((TileBase) tile).getDirection();
|
||||
|
||||
int newDir = dir.ordinal() + 1;
|
||||
|
||||
if (newDir > EnumFacing.VALUES.length - 1)
|
||||
{
|
||||
newDir = 0;
|
||||
}
|
||||
|
||||
((TileBase) tile).setDirection(EnumFacing.getFront(newDir));
|
||||
|
||||
world.markBlockForUpdate(pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack)
|
||||
{
|
||||
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileBase)
|
||||
{
|
||||
((TileBase) tile).setDirection(BlockPistonBase.func_180695_a(world, pos, player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state) // @TODO: Make this work all
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileBase && ((TileBase) tile).getDroppedInventory() != null)
|
||||
{
|
||||
InventoryUtils.dropInventory(world, ((TileBase) tile).getDroppedInventory(), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
super.onBlockDestroyedByPlayer(world, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user