本文整理汇总了Java中net.minecraft.block.Block.getBlockFromItem方法的典型用法代码示例。如果您正苦于以下问题:Java Block.getBlockFromItem方法的具体用法?Java Block.getBlockFromItem怎么用?Java Block.getBlockFromItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.getBlockFromItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: renderItem
import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
RenderBlocks renderblocks = (RenderBlocks) data[0];
Block block = Block.getBlockFromItem(item.getItem());
if (item.hasTagCompound()) {
NBTTagCompound tag = item.stackTagCompound;
if (tag.hasKey("Fluid")) {
FluidStack liquid = FluidStack.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("Fluid"));
if (liquid != null) {
GL11.glEnable(GL11.GL_BLEND);
float height = ((float) liquid.amount / (float) 8000 * (float) 0.99);
renderblocks.setRenderBounds(0.01, 0.01, 0.01, 0.99, height, 0.99);
Utils.renderInventoryBlock(renderblocks, GrandFluidTank.renderblocks, liquid.getFluid());
GL11.glDisable(GL11.GL_BLEND);
}
}
GL11.glEnable(GL11.GL_ALPHA_TEST);
renderblocks.setRenderBounds(0, 0, 0, 1, 1, 1);
Utils.renderInventoryBlock(renderblocks, block, GrandFluidTank.glassfluidtank.getIcon(0, 0));
GL11.glDisable(GL11.GL_ALPHA_TEST);
}
}
示例3: doVoidFogParticles
import net.minecraft.block.Block; //导入方法依赖的package包/类
public void doVoidFogParticles(int posX, int posY, int posZ)
{
int i = 32;
Random random = new Random();
ItemStack itemstack = this.mc.player.getHeldItemMainhand();
if (itemstack == null || Block.getBlockFromItem(itemstack.getItem()) != Blocks.BARRIER)
{
itemstack = this.mc.player.getHeldItemOffhand();
}
boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.func_190926_b() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int j = 0; j < 667; ++j)
{
this.showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos);
this.showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos);
}
}
示例4: getItemBurnTime
import net.minecraft.block.Block; //导入方法依赖的package包/类
public static int getItemBurnTime (@Nonnull ItemStack stack) {
if (stack.isEmpty())
return 0;
Item item = stack.getItem();
if (item instanceof ItemBlock) {
Block block = Block.getBlockFromItem(item);
if (block == ModBlocks.stoneMaterial && BlockStoneMaterial.StoneType.byMetadata(stack.getItemDamage()) == BlockStoneMaterial.StoneType.CHARCOAL_BLOCK)
return ModBlocks.stoneMaterial.getBurnTime(stack);
}
if (item == Items.COAL && stack.getItemDamage() == 1)
return 1600;
return 0;
}
示例5: getItemBurnTimeElectrical
import net.minecraft.block.Block; //导入方法依赖的package包/类
public static int getItemBurnTimeElectrical(ItemStack itemStack) {
if(itemStack == null) {
return 0;
} else {
Item item = itemStack.getItem();
if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
@SuppressWarnings("unused")
Block block = Block.getBlockFromItem(item);
}
if(item == TechnicalItem.Battery1)
return 2560;
return 0;
}
}
示例6: onBlockActivated
import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itm = playerIn.getHeldItemMainhand();
if (!itm.isEmpty() && itm.getItem() instanceof ItemBlock && Block.getBlockFromItem(itm.getItem()) == this && state.getValue(LAYERS) < 8)
{
if (!playerIn.capabilities.isCreativeMode)
{
itm.shrink(1);
}
worldIn.setBlockState(pos, state.cycleProperty(LAYERS));
return true;
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
示例7: keyTyped
import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB)
{ this.textInput.setMaxStringLength(60);
ArrayList<String> stringList = new ArrayList<>();
if(dictonaryList.isEmpty())
{
stringList.addAll(CommandBase.getListOfStringsMatchingLastWord(HarshenUtils.listOf(this.textInput.getText()), Block.REGISTRY.getKeys()));
for(String s : HarshenUtils.getAllOreDictionaryList())
for(ItemStack stack : OreDictionary.getOres(s))
if(Block.getBlockFromItem(stack.getItem()) != Blocks.AIR)
stringList.add(s);
dictonaryList = CommandBase.getListOfStringsMatchingLastWord(HarshenUtils.listOf(this.textInput.getText()), stringList);
}
if(!dictonaryList.isEmpty())
this.textInput.setText(dictonaryList.get(timeOver++%dictonaryList.size()));
}
else
{
timeOver = 0;
dictonaryList.clear();
}
if(keyCode == Keyboard.KEY_RETURN)
closeGui();
this.textInput.textboxKeyTyped(typedChar, keyCode);
super.keyTyped(typedChar, keyCode);
}
示例8: getAustraliumCount
import net.minecraft.block.Block; //导入方法依赖的package包/类
public static int getAustraliumCount(EntityPlayer player){
int count=0;
for(int i=0;i<player.inventory.getSizeInventory();i++){
ItemStack stack=player.inventory.getStackInSlot(i);
if(!stack.isEmpty()){
if(stack.getItem()==TF2weapons.itemTF2 && stack.getItemDamage()==6)
count++;
else if(stack.getItem()==TF2weapons.itemTF2 && stack.getItemDamage()==2)
count+=9;
else if(Block.getBlockFromItem(stack.getItem())==TF2weapons.blockAustralium)
count+=81;
}
}
return count;
}
示例9: getBurnTime
import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public int getBurnTime (@Nonnull ItemStack fuel) {
if (!fuel.isEmpty() && Block.getBlockFromItem(fuel.getItem()) == this && StoneType.byMetadata(fuel.getItemDamage()) == StoneType.CHARCOAL_BLOCK)
return 16000;
return 0;
}
示例10: matches
import net.minecraft.block.Block; //导入方法依赖的package包/类
public boolean matches(InventoryCrafting inv, World worldIn)
{
int i = 0;
int j = 0;
for (int k = 0; k < inv.getSizeInventory(); ++k)
{
ItemStack itemstack = inv.getStackInSlot(k);
if (!itemstack.func_190926_b())
{
if (Block.getBlockFromItem(itemstack.getItem()) instanceof BlockShulkerBox)
{
++i;
}
else
{
if (itemstack.getItem() != Items.DYE)
{
return false;
}
++j;
}
if (j > 1 || i > 1)
{
return false;
}
}
}
return i == 1 && j == 1;
}
示例11: renderItem
import net.minecraft.block.Block; //导入方法依赖的package包/类
public void renderItem(EntityLivingBase entityIn, ItemStack heldStack, ItemCameraTransforms.TransformType transform)
{
if (heldStack != null)
{
Item item = heldStack.getItem();
Block block = Block.getBlockFromItem(item);
GlStateManager.pushMatrix();
if (this.itemRenderer.shouldRenderItemIn3D(heldStack))
{
GlStateManager.scale(2.0F, 2.0F, 2.0F);
if (this.isBlockTranslucent(block))
{
GlStateManager.depthMask(false);
}
}
this.itemRenderer.renderItemModelForEntity(heldStack, entityIn, transform);
if (this.isBlockTranslucent(block))
{
GlStateManager.depthMask(true);
}
GlStateManager.popMatrix();
}
}
示例12: getItemBurnTime
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Returns the number of ticks that the supplied fuel item will keep the
* furnace burning, or 0 if the item isn't fuel
*/
public static int getItemBurnTime(ItemStack stack) {
if (stack.isEmpty())
return 0;
else {
Item item = stack.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {
Block block = Block.getBlockFromItem(item);
if (block == Blocks.WOODEN_SLAB)
return 150;
if (block.getDefaultState().getMaterial() == Material.WOOD)
return 300;
if (block == Blocks.COAL_BLOCK)
return 16000;
}
if (item instanceof ItemTool && "WOOD".equals(((ItemTool) item).getToolMaterialName()))
return 200;
if (item instanceof ItemSword && "WOOD".equals(((ItemSword) item).getToolMaterialName()))
return 200;
if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe) item).getMaterialName()))
return 200;
if (item == Items.STICK)
return 100;
if (item == Items.COAL)
return 1600;
if (item == Items.LAVA_BUCKET)
return 20000;
if (item == Item.getItemFromBlock(Blocks.SAPLING))
return 100;
if (item == Items.BLAZE_ROD)
return 2400;
return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack);
}
}
示例13: placeMobSpawner
import net.minecraft.block.Block; //导入方法依赖的package包/类
@SubscribeEvent
public void placeMobSpawner(BlockEvent.PlaceEvent event) {
if (event.getState().getBlock() != Blocks.MOB_SPAWNER) return;
ItemStack spawner = event.getItemInHand();
if (spawner.hasTagCompound() && spawner.getTagCompound().hasKey("Spawner") && Block.getBlockFromItem(spawner.getItem()) == Blocks.MOB_SPAWNER) {
TileEntity tile = TileEntity.func_190200_a(event.getWorld(), spawner.getTagCompound().getCompoundTag("Spawner"));
event.getWorld().setTileEntity(event.getPos(), tile);
}
}
示例14: onPlayerItemCrafted
import net.minecraft.block.Block; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerItemCrafted(ItemCraftedEvent event) {
if(Block.getBlockFromItem(event.crafting.getItem()) instanceof BlockPhotoProcessor &&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftprocessor)){
event.player.addStat(AchievementLoader.craftprocessor);
}
if(Block.getBlockFromItem(event.crafting.getItem()) instanceof BlockPictureFrame &&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftpictureframe)){
event.player.addStat(AchievementLoader.craftpictureframe);
}
if(Block.getBlockFromItem(event.crafting.getItem()) instanceof BlockPictureFrameMultiple &&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftpictureframe_multiple)){
event.player.addStat(AchievementLoader.craftpictureframe_multiple);
}
if(event.crafting.getItem() instanceof ItemPhotoPaper&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftphoto_paper)){
event.player.addStat(AchievementLoader.craftphoto_paper);
}
if(event.crafting.getItem() instanceof ItemGlassesHelmet&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftglasses)){
event.player.addStat(AchievementLoader.craftglasses);
}
if(event.crafting.getItem() instanceof ItemFilm&&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftfilm)){
event.player.addStat(AchievementLoader.craftfilm);
}
if(event.crafting.getItem() instanceof ItemTripod&&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.crafttripod)){
event.player.addStat(AchievementLoader.crafttripod);
}
if(event.crafting.getItem() instanceof ItemPictureBook&&!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftpicture_book)){
event.player.addStat(AchievementLoader.craftpicture_book);
}
if (event.crafting.getItem() instanceof ItemCamera) {
if(!event.player.getEntityWorld().isRemote&&!event.player.hasAchievement(AchievementLoader.craftcamera)){
System.out.println("has no stat");
event.player.addStat(AchievementLoader.craftcamera);
}
for (int i = 0; i < 9; i++) {
if (event.craftMatrix.getStackInSlot(i) != null
&& event.craftMatrix.getStackInSlot(i).getItem() instanceof ItemTripod) {
if (!event.player.inventory.addItemStackToInventory(new ItemStack(ItemLoader.itemCamera))) {
if (!event.player.getEntityWorld().isRemote) {
Block.spawnAsEntity(event.player.getEntityWorld(), event.player.getPosition(),
new ItemStack(ItemLoader.itemCamera));
}
}
if (!event.player.inventory.addItemStackToInventory(new ItemStack(Blocks.IRON_BLOCK, 3))) {
if (!event.player.getEntityWorld().isRemote) {
Block.spawnAsEntity(event.player.getEntityWorld(), event.player.getPosition(),
new ItemStack(Blocks.IRON_BLOCK, 3));
}
}
if (!event.player.inventory.addItemStackToInventory(new ItemStack(Items.ENDER_EYE))) {
if (!event.player.getEntityWorld().isRemote) {
Block.spawnAsEntity(event.player.getEntityWorld(), event.player.getPosition(),
new ItemStack(Items.ENDER_EYE));
}
}
break;
}
}
}
}
示例15: getHeldBlockMainhand
import net.minecraft.block.Block; //导入方法依赖的package包/类
public Block getHeldBlockMainhand() {
Item heldItem = player.getHeldItemMainhand().getItem();
return Block.getBlockFromItem(heldItem);
}