本文整理匯總了Java中net.minecraft.block.Block.onBlockPlacedBy方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.onBlockPlacedBy方法的具體用法?Java Block.onBlockPlacedBy怎麽用?Java Block.onBlockPlacedBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.onBlockPlacedBy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBlockActivated
import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
boolean isBlock = stack.getItem() instanceof ItemBlock && stack.getItem() != ModItems.ANGSTROM;
if(!world.isRemote && isBlock) {
//Replace
ItemBlock item = (ItemBlock) stack.getItem();
Block block = Block.getBlockFromItem(item);
int meta = item.getMetadata(stack);
IBlockState inState = block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, player, hand);
world.setBlockState(pos, inState);
block.onBlockPlacedBy(world, pos, inState, player, stack);
SoundType sound = block.getSoundType(inState, world, pos, player);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), sound.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F);
//Exchange
ItemStack drop = new ItemStack(Item.getItemFromBlock(this));
ItemHandlerHelper.giveItemToPlayer(player, drop);
if(!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
}
return isBlock;
}
示例2: canPlantCrop
import net.minecraft.block.Block; //導入方法依賴的package包/類
public static boolean canPlantCrop(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, Block cropBlock) {
if (side != EnumFacing.UP)
return false;
if (!world.isRemote && cropBlock instanceof BlockCropsBase && !((BlockCropsBase)cropBlock).canPlantCrop()) {
UCPacketHandler.sendToNearbyPlayers(world, pos, new PacketUCEffect(EnumParticleTypes.BARRIER, pos.getX(), pos.getY() + 2, pos.getZ(), 0));
return false;
}
else if (player.canPlayerEdit(pos, side, stack) && player.canPlayerEdit(pos.offset(EnumFacing.UP), side, stack)) {
IBlockState state = world.getBlockState(pos);
if (state.getBlock().canSustainPlant(state, world, pos, EnumFacing.UP, (IPlantable)stack.getItem()) && world.isAirBlock(pos.offset(EnumFacing.UP))) {
if (cropBlock == UCBlocks.cropCollis) {
if (!world.provider.isSurfaceWorld() || pos.getY() <= 100)
return false;
}
if (cropBlock == UCBlocks.cropCinderbella) {
long time = world.getWorldTime() % 24000L;
if (time >= 18000)
return false;
BlockPos pos1 = pos.add(0, 1, 0);
int pumpkins = 0;
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
IBlockState pumpkin = world.getBlockState(pos1.offset(facing));
if (pumpkin.getBlock() != null && pumpkin.getBlock() == Blocks.PUMPKIN && !world.isRemote) {
pumpkins++;
}
}
if (pumpkins >= 4) {
cropBlock.onBlockPlacedBy(world, pos.offset(side), cropBlock.getDefaultState(), player, stack);
return true;
}
}
if (cropBlock == UCBlocks.cropFeroxia) {
cropBlock.onBlockPlacedBy(world, pos.offset(side), cropBlock.getDefaultState(), player, stack);
return true;
}
if (cropBlock == UCBlocks.cropEula) {
player.openGui(UniqueCrops.instance, 1, world, (int)player.posX, (int)player.posY, (int)player.posZ);
}
if (cropBlock == UCBlocks.cropAbstract) {
player.renderBrokenItemStack(stack);
if (!player.worldObj.isRemote)
setAbstractCropGrowth(player, true);
return true;
}
if (cropBlock == UCBlocks.cropPetramia && pos.offset(side).getY() >= 10) {
return false;
}
world.setBlockState(pos.offset(side), cropBlock.getDefaultState(), 3);
return true;
}
}
return false;
}