本文整理匯總了Java中net.minecraft.item.ItemBlock.setTileEntityNBT方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemBlock.setTileEntityNBT方法的具體用法?Java ItemBlock.setTileEntityNBT怎麽用?Java ItemBlock.setTileEntityNBT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.item.ItemBlock
的用法示例。
在下文中一共展示了ItemBlock.setTileEntityNBT方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onItemUse
import net.minecraft.item.ItemBlock; //導入方法依賴的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;
}
示例2: onItemUse
import net.minecraft.item.ItemBlock; //導入方法依賴的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;
}