本文整理了Java中net.minecraft.world.World.mayPlace()
方法的一些代码示例,展示了World.mayPlace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.mayPlace()
方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:mayPlace
暂无
代码示例来源:origin: Vazkii/Botania
private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) {
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if(!block.isReplaceable(world, pos)) {
pos = pos.offset(side);
}
if(itemstack.isEmpty()) {
return false;
} else if(!player.canPlayerEdit(pos, side, itemstack)) {
return false;
} else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) {
int meta = this.getMetadata(itemstack.getMetadata());
IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player);
if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) {
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);
player.renderBrokenItemStack(itemstack);
itemstack.shrink(1);
for(int i = 0; i < 100; i++)
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);
}
return true;
} else {
return false;
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private boolean mayPlace(World world, BlockPos pos, EntityPlayer placer) {
return world.mayPlace(AWStructureBlocks.TOTEM_PART, pos, false, EnumFacing.UP, placer);
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public boolean mayPlace(@Nonnull Block blockIn, @Nonnull BlockPos pos, boolean p_190527_3_, @Nonnull EnumFacing sidePlacedOn, @Nullable Entity placer) {
return wrapped.mayPlace(blockIn, pos, p_190527_3_, sidePlacedOn, placer);
}
代码示例来源:origin: Vazkii/Botania
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
// Copy of ItemBlock.onItemUse
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if (!block.isReplaceable(world, pos))
{
pos = pos.offset(facing);
}
ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty() && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModBlocks.buriedPetals, pos, false, facing, null))
{
int i = this.getMetadata(stack.getMetadata());
IBlockState iblockstate1 = ModBlocks.buriedPetals.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player);
if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
{
SoundType soundtype = ModBlocks.buriedPetals.getSoundType();
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
stack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
else
{
return EnumActionResult.FAIL;
}
}
代码示例来源:origin: amadornes/MCMultiPart
@Override
public boolean mayPlace(Block p_190527_1_, BlockPos p_190527_2_, boolean p_190527_3_, EnumFacing p_190527_4_, Entity p_190527_5_) {
return getActualWorld().mayPlace(p_190527_1_, p_190527_2_, p_190527_3_, p_190527_4_, p_190527_5_);
}
代码示例来源:origin: SleepyTrousers/EnderIO
protected boolean canMakeIce(@Nonnull World world, final @Nonnull BlockPos neighborPos, final @Nonnull IBlockState neighborState) {
return neighborState.getBlock() == Blocks.WATER && neighborState.getValue(BlockLiquid.LEVEL) == 0
&& world.mayPlace(Blocks.ICE, neighborPos, false, EnumFacing.DOWN, null);
}
代码示例来源:origin: SleepyTrousers/EnderIO
private BlockPos canPlaceItem(@Nonnull ItemStack held, IBlockState blockToPlace, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos,
@Nonnull EnumFacing side) {
if (held.isEmpty() || blockToPlace == null) {
return null;
}
IBlockState bs = world.getBlockState(pos);
Block block = bs.getBlock();
if (!block.isReplaceable(world, pos)) {
pos = pos.offset(side);
}
if (!player.canPlayerEdit(pos, side, held)) {
return null;
} else if (pos.getY() == 255 && blockToPlace.getMaterial().isSolid()) {
return null;
}
if (world.mayPlace(blockToPlace.getBlock(), pos, false, side, player)) {
return pos;
}
return null;
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public boolean prepareBlock(@Nonnull IFarmer farm, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
final ItemStack seed = farm.getSeedTypeInSuppliesFor(pos);
final EntityPlayerMP player = farm.getFakePlayer();
final World world = farm.getWorld();
if (canPlant(seed) && isValidPlantingSpot(world, pos) && player.canPlayerEdit(pos, EnumFacing.UP, seed)
&& world.mayPlace(Blocks.CHORUS_FLOWER, pos, false, EnumFacing.UP, (Entity) null)) {
IBlockState iblockstate1 = Blocks.CHORUS_FLOWER.getDefaultState().withProperty(BlockChorusFlower.AGE, 0);
IBlockState oldState = world.getBlockState(pos);
if (placeBlockAt(seed, player, world, pos, iblockstate1)) {
if (Prep.isValid(farm.takeSeedFromSupplies(pos))) {
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
return true;
} else {
world.setBlockState(pos, oldState, 3);
}
}
}
return false;
}
代码示例来源:origin: PrinceOfAmber/Cyclic
world.mayPlace(stuff, nextPos, true, EnumFacing.UP, null)) { // check if this spot is even valid
IBlockState placeState = UtilItemStack.getStateFromMeta(stuff, stack.getMetadata());
if (world.isRemote == false && UtilPlaceBlocks.placeStateSafe(world, null, nextPos, placeState)) {
代码示例来源:origin: Vazkii/Quark
private boolean setBlock(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, Block block) {
boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
BlockPos blockpos = flag ? pos : pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if(player.canPlayerEdit(blockpos, facing, itemstack) && worldIn.mayPlace(worldIn.getBlockState(blockpos).getBlock(), blockpos, false, facing, null) && block.canPlaceBlockAt(worldIn, blockpos)) {
worldIn.setBlockState(blockpos, block.getDefaultState());
if(player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, blockpos, itemstack);
if(!player.capabilities.isCreativeMode)
itemstack.shrink(1);
player.swingArm(hand);
return true;
}
return false;
}
代码示例来源:origin: Vazkii/Quark
@Override
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();
if(!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if(!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, null)) {
int i = this.getMetadata(itemstack.getMetadata());
IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
if(placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
iblockstate1 = worldIn.getBlockState(pos);
SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, 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;
}
代码示例来源:origin: ForestryMC/Binnie
private EnumActionResult placeFlower(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
if (!block.isReplaceable(world, pos)) {
pos = pos.offset(facing);
}
if (stack.getCount() != 0 && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModuleFlowers.flower, pos, false, facing, null)) {
int i = getMetadata(stack.getMetadata());
IBlockState stateForPlacement = ModuleFlowers.flower.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player, hand);
if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, stateForPlacement)) {
SoundType soundType = block.getSoundType(stateForPlacement, world, pos, player);
world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
stack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
代码示例来源:origin: NanamiArihara/FoodCraft-Reloaded
@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(FoodCraftReloadedMod.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;
}
代码示例来源:origin: OpenMods/OpenModsLib
if (!world.mayPlace(this.block, pos, false, facing, (Entity)null)) return EnumActionResult.FAIL;
代码示例来源:origin: NanamiArihara/FoodCraft-Reloaded
@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(FoodCraftReloadedMod.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;
}
代码示例来源:origin: Vazkii/Quark
private EnumActionResult placeBlock(ItemStack itemstack, EntityPlayer player, BlockPos pos, EnumFacing facing, World worldIn, EnumHand hand, float hitX, float hitY, float hitZ) {
IBlockState stateAt = worldIn.getBlockState(pos);
if(!stateAt.getBlock().isReplaceable(worldIn, pos))
pos = pos.offset(facing);
if(itemstack.getItem() instanceof ItemBlock) {
ItemBlock item = (ItemBlock) itemstack.getItem();
Block block = item.getBlock();
if(player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
int i = item.getMetadata(itemstack.getMetadata());
IBlockState state = block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
if(item.placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, state)) {
state = worldIn.getBlockState(pos);
SoundType soundtype = state.getBlock().getSoundType(state, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
if(!player.capabilities.isCreativeMode)
shrinkInventory(itemstack, player);
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.FAIL;
}
代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod
@Override
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();
if(!block.isReplaceable(worldIn, pos))
{
pos = pos.offset(facing);
}
ItemStack itemstack = player.getHeldItem(hand);
if(!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(FurnitureBlocks.CUP, pos, false, facing, null))
{
int i = this.getMetadata(itemstack.getMetadata());
IBlockState iblockstate1 = FurnitureBlocks.CUP.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
if(placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
{
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), 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;
}
}
代码示例来源:origin: ValkyrienWarfare/Valkyrien-Warfare-Revamped
if (this.world.mayPlace(block, blockpos1, true, EnumFacing.UP, null) && !BlockFalling.canFallThrough(this.world.getBlockState(blockpos1.up())) && world.setBlockState(blockpos1, this.fallTile, 3)) {
if (block instanceof BlockFalling) {
((BlockFalling) block).onEndFalling(this.world, blockpos1,
代码示例来源:origin: blay09/CookingForBlockheads
if (world.mayPlace(ModBlocks.cuttingBoard, pos, false, event.getFace(), player)) {
IBlockState placedState = ModBlocks.cuttingBoard.getStateForPlacement(world, pos, event.getFace(), 0.5f, 1f, 0.5f, 0, player, event.getHand());
BlockEvent.PlaceEvent placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, new BlockSnapshot(world, pos, placedState), event.getFace(), event.getHand());
代码示例来源:origin: WayofTime/BloodMagic
blockPos = blockPos.offset(side);
if (!stack.isEmpty() && player.canPlayerEdit(blockPos, side, stack) && world.mayPlace(storedState.getBlock(), blockPos, false, side, player)) {
if (world.setBlockState(blockPos, storedState, 3)) {
storedState.getBlock().onBlockPlacedBy(world, blockPos, storedState, player, ItemStack.EMPTY);
内容来源于网络,如有侵权,请联系作者删除!