Created
February 3, 2015 00:25
-
-
Save Ivorforce/9b4ddaa7bfbfaba6ca20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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.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.tileentity.TileEntity; | |
import net.minecraft.util.AxisAlignedBB; | |
import net.minecraft.util.BlockPos; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
/** | |
* Created by lukas on 15.04.14. | |
*/ | |
public class BlockPandorasBox extends BlockContainer | |
{ | |
public static final PropertyDirection propertyFacing = PropertyDirection.create("facing"); | |
public BlockPandorasBox() | |
{ | |
super(Material.wood); | |
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 void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) | |
{ | |
switch (SwitchEnumFacing.facings[((EnumFacing) access.getBlockState(pos).getValue(propertyFacing)).ordinal()]) | |
{ | |
case 1: | |
default: | |
this.setBlockBounds(0.25F, 0.0F, 0.25F, 0.75F, 0.5F, 0.75F); | |
break; | |
case 2: | |
this.setBlockBounds(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F); | |
break; | |
case 3: | |
this.setBlockBounds(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F); | |
break; | |
case 4: | |
this.setBlockBounds(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F); | |
break; | |
case 5: | |
this.setBlockBounds(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F); | |
} | |
} | |
@Override | |
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) | |
{ | |
this.setBlockBoundsBasedOnState(worldIn, pos); | |
return super.getCollisionBoundingBox(worldIn, pos, state); | |
} | |
@Override | |
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) | |
{ | |
return this.getDefaultState().withProperty(propertyFacing, placer.func_174811_aO()); | |
} | |
@Override | |
public IBlockState getStateFromMeta(int meta) | |
{ | |
return this.getDefaultState().withProperty(propertyFacing, EnumFacing.getFront(meta & 7)); | |
} | |
@Override | |
public int getMetaFromState(IBlockState state) | |
{ | |
byte b0 = 0; | |
int i = b0 | ((EnumFacing) state.getValue(propertyFacing)).getIndex(); | |
return i; | |
} | |
protected BlockState createBlockState() | |
{ | |
return new BlockState(this, propertyFacing); | |
} | |
static final class SwitchEnumFacing | |
{ | |
static final int[] facings = new int[EnumFacing.values().length]; | |
static | |
{ | |
try | |
{ | |
facings[EnumFacing.UP.ordinal()] = 1; | |
} | |
catch (NoSuchFieldError var5) | |
{ | |
; | |
} | |
try | |
{ | |
facings[EnumFacing.NORTH.ordinal()] = 2; | |
} | |
catch (NoSuchFieldError var4) | |
{ | |
; | |
} | |
try | |
{ | |
facings[EnumFacing.SOUTH.ordinal()] = 3; | |
} | |
catch (NoSuchFieldError var3) | |
{ | |
; | |
} | |
try | |
{ | |
facings[EnumFacing.WEST.ordinal()] = 4; | |
} | |
catch (NoSuchFieldError var2) | |
{ | |
; | |
} | |
try | |
{ | |
facings[EnumFacing.EAST.ordinal()] = 5; | |
} | |
catch (NoSuchFieldError var1) | |
{ | |
; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment