本文整理汇总了Java中net.minecraft.world.World.mayPlace方法的典型用法代码示例。如果您正苦于以下问题:Java World.mayPlace方法的具体用法?Java World.mayPlace怎么用?Java World.mayPlace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.world.World
的用法示例。
在下文中一共展示了World.mayPlace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
final boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
final BlockPos blockpos = flag ? pos : pos.offset(facing);
ItemStack stack = playerIn.getHeldItem(hand);
if (playerIn.canPlayerEdit(blockpos, facing, stack) && worldIn.mayPlace(worldIn.getBlockState(blockpos).getBlock(), blockpos, false, facing, playerIn) && ModBlocks.salt_barrier.canPlaceBlockAt(worldIn, blockpos)) {
stack.shrink(1);
worldIn.setBlockState(blockpos, ModBlocks.salt_barrier.getDefaultState());
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
示例2: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));
if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
facing = EnumFacing.UP;
else if (!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (!worldIn.setBlockState(pos, blockState, 11))
return EnumActionResult.FAIL;
else {
blockState = worldIn.getBlockState(pos);
if (blockState.getBlock() == cake) {
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
}
SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
else
return EnumActionResult.FAIL;
}
示例3: onItemUse
import net.minecraft.world.World; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake")));
if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
facing = EnumFacing.UP;
else if (!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (!worldIn.setBlockState(pos, blockState, 11))
return EnumActionResult.FAIL;
else {
blockState = worldIn.getBlockState(pos);
if (blockState.getBlock() == cake) {
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
}
SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
else
return EnumActionResult.FAIL;
}