Skip to content

Instantly share code, notes, and snippets.

@Ivorforce
Created May 24, 2016 12:26
Show Gist options
  • Save Ivorforce/9ecf1af269bac367641bedef675cd906 to your computer and use it in GitHub Desktop.
Save Ivorforce/9ecf1af269bac367641bedef675cd906 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2014, Lukas Tenbrink.
* http://lukas.axxim.net
*/
package ivorius.pandorasbox.block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
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.entity.player.EntityPlayer;
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;
/**
* Created by lukas on 15.04.14.
*/
public class BlockPandorasBox extends BlockContainer
{
public static final PropertyDirection FACING_PROP = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public static final PropertyBool INVENTORY = PropertyBool.create("inventory");
public BlockPandorasBox()
{
super(Material.wood);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING_PROP, EnumFacing.NORTH).withProperty(INVENTORY, false));
setBlockBounds(0.2f, 0.0f, 0.2f, 0.8f, 0.6f, 0.8f);
}
@Override
public TileEntity createNewTileEntity(World var1, int var2)
{
return new TileEntityPandorasBox();
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityPandorasBox)
((TileEntityPandorasBox) tileEntity).spawnPandorasBox();
worldIn.setBlockToAir(pos);
return true;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isFullCube()
{
return false;
}
@Override
public int getRenderType()
{
return 3;
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityPandorasBox)
((TileEntityPandorasBox) tileEntity).setPartialRotationYaw(placer.rotationYaw % 90.0f);
}
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING_PROP, placer.getHorizontalFacing().getOpposite());
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING_PROP, EnumFacing.getFront(meta & 7));
}
@Override
public int getMetaFromState(IBlockState state)
{
byte b0 = 0;
int i = b0 | ((EnumFacing) state.getValue(FACING_PROP)).getIndex();
return i;
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, FACING_PROP, INVENTORY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment