Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Snowglobe extends BlockContainer {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- public static final PropertyBool HAS_RECORD = PropertyBool.create("has_record");
- public static void registerFixesJukebox(DataFixer fixer)
- {
- fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackData(Snowglobe.TileEntityJukebox.class, new String[] {"RecordItem"}));
- }
- public Snowglobe(String name, Material material){
- super(material, MapColor.SNOW);
- setUnlocalizedName(name);
- setRegistryName(name);
- this.setHardness(0.3F);
- this.setCreativeTab(CreativeTabs.DECORATIONS);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(HAS_RECORD, Boolean.valueOf(false)));
- ModBlocks.BLOCKS.add(this);
- ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
- }
- @Override
- public BlockRenderLayer getBlockLayer() {
- return BlockRenderLayer.CUTOUT;
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
- {
- return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos) && worldIn.isSideSolid(pos.down(), EnumFacing.UP);
- }
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
- }
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
- }
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
- {
- if (((Boolean)state.getValue(HAS_RECORD)).booleanValue())
- {
- this.dropRecord(worldIn, pos, state);
- state = state.withProperty(HAS_RECORD, Boolean.valueOf(false)).withProperty(FACING, state.getValue(FACING));
- worldIn.setBlockState(pos, state, 2);
- return true;
- }
- else
- {
- return false;
- }
- }
- public void insertRecord(World worldIn, BlockPos pos, IBlockState state, ItemStack recordStack)
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof Snowglobe.TileEntityJukebox)
- {
- ((Snowglobe.TileEntityJukebox)tileentity).setRecord(recordStack.copy());
- worldIn.setBlockState(pos, state.withProperty(HAS_RECORD, Boolean.valueOf(true)).withProperty(FACING, state.getValue(FACING)), 2);
- }
- }
- private void dropRecord(World worldIn, BlockPos pos, IBlockState state)
- {
- if (!worldIn.isRemote)
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof Snowglobe.TileEntityJukebox)
- {
- Snowglobe.TileEntityJukebox snowglobe$tileentitysnowglobe = (Snowglobe.TileEntityJukebox)tileentity;
- ItemStack itemstack = snowglobe$tileentitysnowglobe.getRecord();
- if (!itemstack.isEmpty())
- {
- worldIn.playEvent(1010, pos, 0);
- worldIn.playRecord(pos, (SoundEvent)null);
- snowglobe$tileentitysnowglobe.setRecord(ItemStack.EMPTY);
- float f = 0.7F;
- double d0 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
- double d1 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
- double d2 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
- ItemStack itemstack1 = itemstack.copy();
- EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, itemstack1);
- entityitem.setDefaultPickupDelay();
- worldIn.spawnEntity(entityitem);
- }
- }
- }
- }
- public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
- {
- this.dropRecord(worldIn, pos, state);
- super.breakBlock(worldIn, pos, state);
- }
- public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
- {
- if (!worldIn.isRemote)
- {
- super.dropBlockAsItemWithChance(worldIn, pos, state, chance, 0);
- }
- }
- public TileEntity createNewTileEntity(World worldIn, int meta)
- {
- return new Snowglobe.TileEntityJukebox();
- }
- public boolean hasComparatorInputOverride(IBlockState state)
- {
- return true;
- }
- public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof Snowglobe.TileEntityJukebox)
- {
- ItemStack itemstack = ((Snowglobe.TileEntityJukebox)tileentity).getRecord();
- if (!itemstack.isEmpty())
- {
- return Item.getIdFromItem(itemstack.getItem()) + 1 - Item.getIdFromItem(Items.RECORD_13);
- }
- }
- return 0;
- }
- public EnumBlockRenderType getRenderType(IBlockState state)
- {
- return EnumBlockRenderType.MODEL;
- }
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(HAS_RECORD, Boolean.valueOf(meta > 0));
- }
- public int getMetaFromState(IBlockState state)
- {
- int index = ((EnumFacing)state.getValue(FACING)).getHorizontalIndex() >> 1;
- int bool = ((Boolean)state.getValue(HAS_RECORD)).booleanValue() ? 1 : 0 & 1;
- int i = index << 1|bool;
- return i;
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {FACING, HAS_RECORD});
- }
- public static class TileEntityJukebox extends TileEntity
- {
- private ItemStack record = ItemStack.EMPTY;
- public void readFromNBT(NBTTagCompound compound)
- {
- super.readFromNBT(compound);
- if (compound.hasKey("RecordItem", 10))
- {
- this.setRecord(new ItemStack(compound.getCompoundTag("RecordItem")));
- }
- else if (compound.getInteger("Record") > 0)
- {
- this.setRecord(new ItemStack(Item.getItemById(compound.getInteger("Record"))));
- }
- }
- public NBTTagCompound writeToNBT(NBTTagCompound compound)
- {
- super.writeToNBT(compound);
- if (!this.getRecord().isEmpty())
- {
- compound.setTag("RecordItem", this.getRecord().writeToNBT(new NBTTagCompound()));
- }
- return compound;
- }
- public ItemStack getRecord()
- {
- return this.record;
- }
- public void setRecord(ItemStack recordStack)
- {
- this.record = recordStack;
- this.markDirty();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement