net.minecraft.world.World.mayPlace()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中net.minecraft.world.World.mayPlace()方法的一些代码示例,展示了World.mayPlace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.mayPlace()方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:mayPlace

World.mayPlace介绍

暂无

代码示例

代码示例来源:origin: Vazkii/Botania

  1. private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) {
  2. IBlockState iblockstate = world.getBlockState(pos);
  3. Block block = iblockstate.getBlock();
  4. if(!block.isReplaceable(world, pos)) {
  5. pos = pos.offset(side);
  6. }
  7. if(itemstack.isEmpty()) {
  8. return false;
  9. } else if(!player.canPlayerEdit(pos, side, itemstack)) {
  10. return false;
  11. } else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) {
  12. int meta = this.getMetadata(itemstack.getMetadata());
  13. IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player);
  14. if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) {
  15. world.playSound(null, pos, Blocks.MOB_SPAWNER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (Blocks.MOB_SPAWNER.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.MOB_SPAWNER.getSoundType().getPitch() * 0.8F);
  16. player.renderBrokenItemStack(itemstack);
  17. itemstack.shrink(1);
  18. for(int i = 0; i < 100; i++)
  19. Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6);
  20. }
  21. return true;
  22. } else {
  23. return false;
  24. }
  25. }

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

  1. private boolean mayPlace(World world, BlockPos pos, EntityPlayer placer) {
  2. return world.mayPlace(AWStructureBlocks.TOTEM_PART, pos, false, EnumFacing.UP, placer);
  3. }

代码示例来源:origin: SleepyTrousers/EnderIO

  1. @Override
  2. public boolean mayPlace(@Nonnull Block blockIn, @Nonnull BlockPos pos, boolean p_190527_3_, @Nonnull EnumFacing sidePlacedOn, @Nullable Entity placer) {
  3. return wrapped.mayPlace(blockIn, pos, p_190527_3_, sidePlacedOn, placer);
  4. }

代码示例来源:origin: Vazkii/Botania

  1. @Nonnull
  2. @Override
  3. public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  4. // Copy of ItemBlock.onItemUse
  5. IBlockState iblockstate = world.getBlockState(pos);
  6. Block block = iblockstate.getBlock();
  7. if (!block.isReplaceable(world, pos))
  8. {
  9. pos = pos.offset(facing);
  10. }
  11. ItemStack stack = player.getHeldItem(hand);
  12. if (!stack.isEmpty() && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModBlocks.buriedPetals, pos, false, facing, null))
  13. {
  14. int i = this.getMetadata(stack.getMetadata());
  15. IBlockState iblockstate1 = ModBlocks.buriedPetals.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player);
  16. if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
  17. {
  18. SoundType soundtype = ModBlocks.buriedPetals.getSoundType();
  19. world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  20. stack.shrink(1);
  21. }
  22. return EnumActionResult.SUCCESS;
  23. }
  24. else
  25. {
  26. return EnumActionResult.FAIL;
  27. }
  28. }

代码示例来源:origin: amadornes/MCMultiPart

  1. @Override
  2. public boolean mayPlace(Block p_190527_1_, BlockPos p_190527_2_, boolean p_190527_3_, EnumFacing p_190527_4_, Entity p_190527_5_) {
  3. return getActualWorld().mayPlace(p_190527_1_, p_190527_2_, p_190527_3_, p_190527_4_, p_190527_5_);
  4. }

代码示例来源:origin: SleepyTrousers/EnderIO

  1. protected boolean canMakeIce(@Nonnull World world, final @Nonnull BlockPos neighborPos, final @Nonnull IBlockState neighborState) {
  2. return neighborState.getBlock() == Blocks.WATER && neighborState.getValue(BlockLiquid.LEVEL) == 0
  3. && world.mayPlace(Blocks.ICE, neighborPos, false, EnumFacing.DOWN, null);
  4. }

代码示例来源:origin: SleepyTrousers/EnderIO

  1. private BlockPos canPlaceItem(@Nonnull ItemStack held, IBlockState blockToPlace, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos,
  2. @Nonnull EnumFacing side) {
  3. if (held.isEmpty() || blockToPlace == null) {
  4. return null;
  5. }
  6. IBlockState bs = world.getBlockState(pos);
  7. Block block = bs.getBlock();
  8. if (!block.isReplaceable(world, pos)) {
  9. pos = pos.offset(side);
  10. }
  11. if (!player.canPlayerEdit(pos, side, held)) {
  12. return null;
  13. } else if (pos.getY() == 255 && blockToPlace.getMaterial().isSolid()) {
  14. return null;
  15. }
  16. if (world.mayPlace(blockToPlace.getBlock(), pos, false, side, player)) {
  17. return pos;
  18. }
  19. return null;
  20. }

代码示例来源:origin: SleepyTrousers/EnderIO

  1. @Override
  2. public boolean prepareBlock(@Nonnull IFarmer farm, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
  3. final ItemStack seed = farm.getSeedTypeInSuppliesFor(pos);
  4. final EntityPlayerMP player = farm.getFakePlayer();
  5. final World world = farm.getWorld();
  6. if (canPlant(seed) && isValidPlantingSpot(world, pos) && player.canPlayerEdit(pos, EnumFacing.UP, seed)
  7. && world.mayPlace(Blocks.CHORUS_FLOWER, pos, false, EnumFacing.UP, (Entity) null)) {
  8. IBlockState iblockstate1 = Blocks.CHORUS_FLOWER.getDefaultState().withProperty(BlockChorusFlower.AGE, 0);
  9. IBlockState oldState = world.getBlockState(pos);
  10. if (placeBlockAt(seed, player, world, pos, iblockstate1)) {
  11. if (Prep.isValid(farm.takeSeedFromSupplies(pos))) {
  12. SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
  13. world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  14. return true;
  15. } else {
  16. world.setBlockState(pos, oldState, 3);
  17. }
  18. }
  19. }
  20. return false;
  21. }

代码示例来源:origin: PrinceOfAmber/Cyclic

  1. world.mayPlace(stuff, nextPos, true, EnumFacing.UP, null)) { // check if this spot is even valid
  2. IBlockState placeState = UtilItemStack.getStateFromMeta(stuff, stack.getMetadata());
  3. if (world.isRemote == false && UtilPlaceBlocks.placeStateSafe(world, null, nextPos, placeState)) {

代码示例来源:origin: Vazkii/Quark

  1. private boolean setBlock(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, Block block) {
  2. boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
  3. BlockPos blockpos = flag ? pos : pos.offset(facing);
  4. ItemStack itemstack = player.getHeldItem(hand);
  5. if(player.canPlayerEdit(blockpos, facing, itemstack) && worldIn.mayPlace(worldIn.getBlockState(blockpos).getBlock(), blockpos, false, facing, null) && block.canPlaceBlockAt(worldIn, blockpos)) {
  6. worldIn.setBlockState(blockpos, block.getDefaultState());
  7. if(player instanceof EntityPlayerMP)
  8. CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, blockpos, itemstack);
  9. if(!player.capabilities.isCreativeMode)
  10. itemstack.shrink(1);
  11. player.swingArm(hand);
  12. return true;
  13. }
  14. return false;
  15. }

代码示例来源:origin: Vazkii/Quark

  1. @Override
  2. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  3. IBlockState iblockstate = worldIn.getBlockState(pos);
  4. Block block = iblockstate.getBlock();
  5. if(!block.isReplaceable(worldIn, pos))
  6. pos = pos.offset(facing);
  7. ItemStack itemstack = player.getHeldItem(hand);
  8. if(!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, null)) {
  9. int i = this.getMetadata(itemstack.getMetadata());
  10. IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
  11. if(placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
  12. iblockstate1 = worldIn.getBlockState(pos);
  13. SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, player);
  14. // worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  15. itemstack.shrink(1);
  16. }
  17. return EnumActionResult.SUCCESS;
  18. }
  19. else return EnumActionResult.FAIL;
  20. }

代码示例来源:origin: ForestryMC/Binnie

  1. private EnumActionResult placeFlower(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  2. IBlockState blockState = world.getBlockState(pos);
  3. Block block = blockState.getBlock();
  4. if (!block.isReplaceable(world, pos)) {
  5. pos = pos.offset(facing);
  6. }
  7. if (stack.getCount() != 0 && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModuleFlowers.flower, pos, false, facing, null)) {
  8. int i = getMetadata(stack.getMetadata());
  9. IBlockState stateForPlacement = ModuleFlowers.flower.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player, hand);
  10. if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, stateForPlacement)) {
  11. SoundType soundType = block.getSoundType(stateForPlacement, world, pos, player);
  12. world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
  13. stack.shrink(1);
  14. }
  15. return EnumActionResult.SUCCESS;
  16. }
  17. return EnumActionResult.FAIL;
  18. }

代码示例来源:origin: NanamiArihara/FoodCraft-Reloaded

  1. @Nonnull
  2. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  3. IBlockState iblockstate = worldIn.getBlockState(pos);
  4. Block block = iblockstate.getBlock();
  5. Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloadedMod.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));
  6. if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
  7. facing = EnumFacing.UP;
  8. else if (!block.isReplaceable(worldIn, pos))
  9. pos = pos.offset(facing);
  10. ItemStack itemstack = player.getHeldItem(hand);
  11. if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
  12. IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
  13. if (!worldIn.setBlockState(pos, blockState, 11))
  14. return EnumActionResult.FAIL;
  15. else {
  16. blockState = worldIn.getBlockState(pos);
  17. if (blockState.getBlock() == cake) {
  18. ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
  19. blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
  20. }
  21. SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
  22. worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  23. itemstack.shrink(1);
  24. return EnumActionResult.SUCCESS;
  25. }
  26. }
  27. else
  28. return EnumActionResult.FAIL;
  29. }

代码示例来源:origin: OpenMods/OpenModsLib

  1. if (!world.mayPlace(this.block, pos, false, facing, (Entity)null)) return EnumActionResult.FAIL;

代码示例来源:origin: NanamiArihara/FoodCraft-Reloaded

  1. @Nonnull
  2. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  3. IBlockState iblockstate = worldIn.getBlockState(pos);
  4. Block block = iblockstate.getBlock();
  5. Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloadedMod.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake")));
  6. if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
  7. facing = EnumFacing.UP;
  8. else if (!block.isReplaceable(worldIn, pos))
  9. pos = pos.offset(facing);
  10. ItemStack itemstack = player.getHeldItem(hand);
  11. if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
  12. IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
  13. if (!worldIn.setBlockState(pos, blockState, 11))
  14. return EnumActionResult.FAIL;
  15. else {
  16. blockState = worldIn.getBlockState(pos);
  17. if (blockState.getBlock() == cake) {
  18. ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
  19. blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
  20. }
  21. SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
  22. worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  23. itemstack.shrink(1);
  24. return EnumActionResult.SUCCESS;
  25. }
  26. }
  27. else
  28. return EnumActionResult.FAIL;
  29. }

代码示例来源:origin: Vazkii/Quark

  1. private EnumActionResult placeBlock(ItemStack itemstack, EntityPlayer player, BlockPos pos, EnumFacing facing, World worldIn, EnumHand hand, float hitX, float hitY, float hitZ) {
  2. IBlockState stateAt = worldIn.getBlockState(pos);
  3. if(!stateAt.getBlock().isReplaceable(worldIn, pos))
  4. pos = pos.offset(facing);
  5. if(itemstack.getItem() instanceof ItemBlock) {
  6. ItemBlock item = (ItemBlock) itemstack.getItem();
  7. Block block = item.getBlock();
  8. if(player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
  9. int i = item.getMetadata(itemstack.getMetadata());
  10. IBlockState state = block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
  11. if(item.placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, state)) {
  12. state = worldIn.getBlockState(pos);
  13. SoundType soundtype = state.getBlock().getSoundType(state, worldIn, pos, player);
  14. worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  15. if(!player.capabilities.isCreativeMode)
  16. shrinkInventory(itemstack, player);
  17. }
  18. return EnumActionResult.SUCCESS;
  19. }
  20. }
  21. return EnumActionResult.FAIL;
  22. }

代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod

  1. @Override
  2. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  3. {
  4. IBlockState iblockstate = worldIn.getBlockState(pos);
  5. Block block = iblockstate.getBlock();
  6. if(!block.isReplaceable(worldIn, pos))
  7. {
  8. pos = pos.offset(facing);
  9. }
  10. ItemStack itemstack = player.getHeldItem(hand);
  11. if(!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(FurnitureBlocks.CUP, pos, false, facing, null))
  12. {
  13. int i = this.getMetadata(itemstack.getMetadata());
  14. IBlockState iblockstate1 = FurnitureBlocks.CUP.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
  15. if(placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
  16. {
  17. SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
  18. worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  19. itemstack.shrink(1);
  20. }
  21. return EnumActionResult.SUCCESS;
  22. }
  23. else
  24. {
  25. return EnumActionResult.FAIL;
  26. }
  27. }

代码示例来源:origin: ValkyrienWarfare/Valkyrien-Warfare-Revamped

  1. if (this.world.mayPlace(block, blockpos1, true, EnumFacing.UP, null) && !BlockFalling.canFallThrough(this.world.getBlockState(blockpos1.up())) && world.setBlockState(blockpos1, this.fallTile, 3)) {
  2. if (block instanceof BlockFalling) {
  3. ((BlockFalling) block).onEndFalling(this.world, blockpos1,

代码示例来源:origin: blay09/CookingForBlockheads

  1. if (world.mayPlace(ModBlocks.cuttingBoard, pos, false, event.getFace(), player)) {
  2. IBlockState placedState = ModBlocks.cuttingBoard.getStateForPlacement(world, pos, event.getFace(), 0.5f, 1f, 0.5f, 0, player, event.getHand());
  3. BlockEvent.PlaceEvent placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, new BlockSnapshot(world, pos, placedState), event.getFace(), event.getHand());

代码示例来源:origin: WayofTime/BloodMagic

  1. blockPos = blockPos.offset(side);
  2. if (!stack.isEmpty() && player.canPlayerEdit(blockPos, side, stack) && world.mayPlace(storedState.getBlock(), blockPos, false, side, player)) {
  3. if (world.setBlockState(blockPos, storedState, 3)) {
  4. storedState.getBlock().onBlockPlacedBy(world, blockPos, storedState, player, ItemStack.EMPTY);

相关文章

World类方法