Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos blockpos, EnumHand hand,
- EnumFacing facing, float hitX, float hitY, float hitZ) {
- ItemStack itemstack = player.getHeldItem(hand);
- IBlockState iblockstate = worldIn.getBlockState(blockpos);
- Block block = iblockstate.getBlock();
- if (!(block instanceof BlockLayer) && !block.isReplaceable(worldIn, blockpos)) {
- blockpos = blockpos.offset(facing);
- iblockstate = worldIn.getBlockState(blockpos);
- block = iblockstate.getBlock();
- }
- if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemBlockLayer
- && player.canPlayerEdit(blockpos, facing, itemstack)) {
- int amount = 1;
- // Build upon already placed block
- if (block instanceof BlockLayer) {
- int i = ((Integer) iblockstate.getValue(BlockSnow.LAYERS)).intValue();
- if (i < 8) {
- if (Minecraft.getMinecraft().gameSettings
- .isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) {
- amount = Math.min(4, 8 - i);
- if (player.isCreative() == false) {
- amount = Math.min(amount, itemstack.getCount());
- }
- amount += i;
- } else {
- amount = i + 1;
- }
- } else {
- blockpos = blockpos.up();
- iblockstate = worldIn.getBlockState(blockpos);
- block = iblockstate.getBlock();
- }
- } else {
- // New block
- if (Minecraft.getMinecraft().gameSettings
- .isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) {
- amount = 4;
- if (player.isCreative() == false) {
- amount = Math.min(4, itemstack.getCount());
- }
- }
- }
- IBlockState iblockstate1 = ((ItemBlock) itemstack.getItem()).getBlock().getDefaultState()
- .withProperty(BlockSnow.LAYERS, Integer.valueOf(amount));
- // Change/Place block
- AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);
- if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos))
- && worldIn.setBlockState(blockpos, iblockstate1, 10)) {
- Main.logger.warn("PLACED");
- SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, blockpos, player);
- worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS,
- (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
- if (player instanceof EntityPlayerMP) {
- CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, blockpos, itemstack);
- }
- itemstack.shrink(amount);
- return EnumActionResult.SUCCESS;
- }
- }
- return EnumActionResult.FAIL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement