Java源码示例:net.minecraftforge.event.ForgeEventFactory

示例1
public ActionResult<ItemStack> tryPickUpFluid(@Nonnull World world, @Nonnull EntityPlayer player,
		@Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) {
	RayTraceResult mop = this.rayTrace(world, player, true);
	ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop);
	if (ret != null)
		return ret;
	if (mop == null) {
		return ActionResult.newResult(EnumActionResult.PASS, itemstack);
	}
	BlockPos clickPos = mop.getBlockPos();
	if (world.isBlockModifiable(player, clickPos)) {
		FluidActionResult result = FluidUtil.tryPickUpFluid(itemstack, player, world, clickPos, mop.sideHit);
		if (result.isSuccess()) {
			ItemHandlerHelper.giveItemToPlayer(player, result.getResult());
			itemstack.shrink(1);
			return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
		}
	}
	return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
示例2
public static boolean placeTorch(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) continue;
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) continue;
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) return true;
    }
    return false;
}
 
示例3
public boolean place(IBlockState state, EnumFacing direction, EnumHand hand) {
	if (!world.isBlockLoaded(blockPos)) return false;

	if (spawnProtection) {
		if (!world.isBlockModifiable(player, blockPos)) return false;
	}

	final BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, blockPos);

	if (!world.setBlockState(blockPos, state, blockPlaceFlags)) return false;

	if (ForgeEventFactory.onPlayerBlockPlace(player, snapshot, direction, hand).isCanceled()) {
		world.restoringBlockSnapshots = true;
		snapshot.restore(true, false);
		world.restoringBlockSnapshots = false;
		return false;
	}

	return true;
}
 
示例4
protected void handleNormalDrops(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, @Nonnull ItemStack stack) {
	harvesters.set(player);
	final int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);

	boolean addNormalDrops = true;

	if (te instanceof ICustomHarvestDrops) {
		final ICustomHarvestDrops dropper = (ICustomHarvestDrops)te;
		final List<ItemStack> drops = Lists.newArrayList();
		dropper.addHarvestDrops(player, drops, state, fortune, false);

		ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, fortune, 1.0f, false, player);
		for (ItemStack drop : drops)
			spawnAsEntity(world, pos, drop);

		addNormalDrops = !dropper.suppressBlockHarvestDrops();
	}

	if (addNormalDrops)
		dropBlockAsItem(world, pos, state, fortune);

	harvesters.set(null);
}
 
示例5
protected void handleSilkTouchDrops(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) {
	List<ItemStack> items = Lists.newArrayList();

	boolean addNormalDrops = true;

	if (te instanceof ICustomHarvestDrops) {
		final ICustomHarvestDrops dropper = (ICustomHarvestDrops)te;

		dropper.addHarvestDrops(player, items, state, 0, true);
		addNormalDrops = !dropper.suppressBlockHarvestDrops();
	}

	if (addNormalDrops) {
		final ItemStack drop = new ItemStack(Item.getItemFromBlock(this), 1, damageDropped(state));
		items.add(drop);
	}

	ForgeEventFactory.fireBlockHarvesting(items, world, pos, state, 0, 1.0f, true, player);
	for (ItemStack stack : items)
		spawnAsEntity(world, pos, stack);
}
 
示例6
public void replaceBiomeBlocks(int x, int z, ChunkPrimer primer, Biome[] biomesIn) {
    if (!ForgeEventFactory.onReplaceBiomeBlocks(this, x, z, primer, this.world)) return;

    this.depthBuffer = this.surfaceNoise.getRegion(this.depthBuffer, (double) (x * 16), (double) (z * 16), 16, 16, 0.0625D, 0.0625D, 1.0D);

    for (int i = 0; i < 16; ++i) {
        for (int j = 0; j < 16; ++j) {
            Biome biome = biomesIn[j + i * 16];
            biome.genTerrainBlocks(this.world, this.rand, primer, x * 16 + i, z * 16 + j, this.depthBuffer[j + i * 16]);
        }
    }
}
 
示例7
@Override
public void populate(int x, int z) {
    BlockFalling.fallInstantly = true;
    BlockPos blockpos = new BlockPos(x * 16, 0, z * 16);

    Biome biome = this.world.getBiome(blockpos.add(16, 0, 16));

    rand.setSeed(world.getSeed());
    long xSeed = rand.nextLong() / 2L * 2L + 1L;
    long zSeed = rand.nextLong() / 2L * 2L + 1L;
    rand.setSeed(chunkX * xSeed + chunkZ * zSeed ^ world.getSeed());

    int i = x * 16;
    int j = z * 16;

    if (net.minecraftforge.event.terraingen.TerrainGen.generateOre(this.world, this.rand, diamondGen, blockpos, OreGenEvent.GenerateMinable.EventType.CUSTOM))
        for (int l1 = 0; l1 < 12; ++l1)
        {
            this.diamondGen.generate(this.world, this.rand, blockpos.add(this.rand.nextInt(16), this.rand.nextInt(30), this.rand.nextInt(16)));
        }


    ChunkPos chunkpos = new ChunkPos(x, z);

    if (mapFeaturesEnabled) {
        this.mineshaft.generateStructure(this.world, this.rand, chunkpos);
        this.villageGenerator.generateStructure(this.world, this.rand, chunkpos);
        this.tofuCastle.generateStructure(this.world, this.rand, chunkpos);
    }

    biome.decorate(world, rand, blockpos);


    if (net.minecraftforge.event.terraingen.TerrainGen.populate(this, this.world, this.rand, x, z, false, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.ANIMALS))
        WorldEntitySpawner.performWorldGenSpawning(this.world, biome, i + 8, j + 8, 16, 16, this.rand);

    net.minecraftforge.event.ForgeEventFactory.onChunkPopulate(false, this, this.world, this.rand, x, z, false);

    BlockFalling.fallInstantly = false;
}
 
示例8
public ActionResult<ItemStack> tryPlaceFluid(@Nonnull World world, @Nonnull EntityPlayer player,
		@Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) {
	RayTraceResult mop = this.rayTrace(world, player, false);
	ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop);
	if (ret != null)
		return ret;
	if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) {
		return ActionResult.newResult(EnumActionResult.PASS, itemstack);
	}
	BlockPos clickPos = mop.getBlockPos();
	if (world.isBlockModifiable(player, clickPos)) {
		BlockPos targetPos = clickPos.offset(mop.sideHit);
		if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack)) {
			FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, itemstack, fluidStack);
			if (result.isSuccess() && !player.capabilities.isCreativeMode) {
				player.addStat(StatList.getObjectUseStats(this));
				itemstack.shrink(1);
				ItemStack emptyStack = new ItemStack(GTItems.testTube);
				if (itemstack.isEmpty()) {
					return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack);
				} else {
					ItemHandlerHelper.giveItemToPlayer(player, emptyStack);
					return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
				}
			}
		}
	}
	return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
示例9
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
	if (!player.capabilities.isCreativeMode) {
		ArrayList<ItemStack> drops = getDrops(world, x, y, z, meta, 0);
		if (ForgeEventFactory.fireBlockHarvesting(drops, world, this, x, y, z, meta, 0, 1.0F, false, player) > 0.0F)
			for (ItemStack stack : drops)
				dropBlockAsItem(world, x, y, z, stack);
	}
}
 
示例10
private void brewPotions() {
	if (ForgeEventFactory.onPotionAttemptBreaw(new ItemStack[] { inventory[0], inventory[1], inventory[2], inventory[3] }))
		return;
	if (canBrew()) {
		for (int i = 0; i < 3; i++)
			if (inventory[i] != null && inventory[i].getItem() instanceof ItemPotion) {
				int j = inventory[i].getItemDamage();
				if (ItemPotion.isSplash(j) && inventory[3].getItem() == ModItems.dragon_breath)
					inventory[i] = new ItemStack(ModItems.lingering_potion, inventory[i].stackSize, inventory[i].getItemDamage());
				else {
					int k = applyIngredient(j, inventory[3]);
					List<?> list = Items.potionitem.getEffects(j);
					List<?> list1 = Items.potionitem.getEffects(k);

					if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null)) {
						if (j != k)
							inventory[i].setItemDamage(k);
					} else if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
						inventory[i].setItemDamage(k);
				}
			}

		boolean hasContainerItem = inventory[3].getItem().hasContainerItem(inventory[3]);
		if (--inventory[3].stackSize <= 0)
			inventory[3] = hasContainerItem ? inventory[3].getItem().getContainerItem(inventory[3]) : null;
		else if (hasContainerItem && !worldObj.isRemote) {
			float f = 0.7F;
			double x = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5D;
			double y = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5D;
			double z = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5D;
			EntityItem entityitem = new EntityItem(worldObj, xCoord + x, yCoord + y, zCoord + z, inventory[3].getItem().getContainerItem(inventory[3]));
			entityitem.delayBeforeCanPickup = 10;
			worldObj.spawnEntityInWorld(entityitem);
		}

		fuel--;
		ForgeEventFactory.onPotionBrewed(new ItemStack[] { inventory[0], inventory[1], inventory[2], inventory[3] });
		worldObj.playSound(xCoord, yCoord, zCoord, Reference.MOD_ID + ":block.brewing_stand.brew", 1.0F, 1.0F, true);
	}
}
 
示例11
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
            continue;
        }
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) {
            continue;
        }
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) {
            return true;
        }
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
示例12
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
            continue;
        }
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) {
            continue;
        }
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) {
            return true;
        }
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
示例13
/**
 * determines if a skeleton spawns on a spider, and if a sheep is a different color
 */
private static void creatureSpecificInit(EntityLiving par0EntityLiving, World par1World, float par2, float par3, float par4)
{
    if (ForgeEventFactory.doSpecialSpawn(par0EntityLiving, par1World, par2, par3, par4))
    {
        return;
    }

    par0EntityLiving.initCreature();
}
 
示例14
/**
 * see PlayerInteractionManager.tryHarvestBlock
 */
public boolean breakBlock(EntityPlayerMP player, BlockPos pos) {
	World world = player.world;
	IBlockState state = world.getBlockState(pos);
	TileEntity te = world.getTileEntity(pos);

	if (state.getBlockHardness(world, pos) < 0 || !state.getBlock().canHarvestBlock(world, pos, player))
	{
		return false;
	}
	else {
		ItemStack stack = player.getHeldItemMainhand();
		if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;

		world.playEvent(player, 2001, pos, Block.getStateId(state));
		ItemStack itemHand = player.getHeldItemMainhand();
		ItemStack itemHandCopy = itemHand.isEmpty() ? ItemStack.EMPTY : itemHand.copy();
		boolean canHarvest = state.getBlock().canHarvestBlock(world, pos, player);

		if (!itemHand.isEmpty()) {
			itemHand.onBlockDestroyed(world, state, pos, player);
			if (itemHand.isEmpty()) {
				ForgeEventFactory.onPlayerDestroyItem(player, itemHandCopy, EnumHand.MAIN_HAND);
			}
		}

		boolean didRemove = removeBlock(player, pos, canHarvest);
		if (didRemove && canHarvest) {
			state.getBlock().harvestBlock(world, player, pos, state, te, itemHandCopy);
		}
		return didRemove;
	}
}
 
示例15
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack){
    if(slot < 4) {
        inventory[slot] = itemStack;
        if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
            itemStack.stackSize = getInventoryStackLimit();
        }
    } else {
        EntityPlayer player = getPlayer();
        if(dispenserUpgradeInserted) {
            if(itemStack != null) {
                int startValue = itemStack.stackSize;
                while(itemStack.stackSize > 0) {
                    ItemStack remainingItem = itemStack.onFoodEaten(player.worldObj, player);
                    remainingItem = ForgeEventFactory.onItemUseFinish(player, itemStack, 0, remainingItem);
                    if(remainingItem != null && remainingItem.stackSize > 0 && (remainingItem != itemStack || remainingItem.stackSize != startValue)) {
                        if(!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.stackSize > 0) {
                            player.dropPlayerItemWithRandomChoice(remainingItem, false);
                        }
                    }
                    if(itemStack.stackSize == startValue) break;
                }
            }
        } else {
            InventoryPlayer inventoryPlayer = player != null ? player.inventory : null;
            if(inventoryPlayer != null) {
                inventoryPlayer.setInventorySlotContents(slot - 4, itemStack);
            } else if(worldObj != null && !worldObj.isRemote) {
                EntityItem item = new EntityItem(worldObj, xCoord, yCoord, zCoord, itemStack);
                worldObj.spawnEntityInWorld(item);
            }
        }
    }

}
 
示例16
private void removeBlock() {
    if(world == null || world.isRemote)
        return;

    PlayerEntity player = world.getPlayerByUuid(playerUUID);
    if (player == null)
        return;

    int silk = 0;
    int fortune = 0;

    ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get());

    // If silk is in the upgrades, apply it without a tier.
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) {
        tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
        silk = 1;
    }

    // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) {
        Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1);
        if (upgrade.isPresent()) {
            fortune = upgrade.get().getTier();
            tempTool.addEnchantment(Enchantments.FORTUNE, fortune);
        }
    }

    List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool);

    if ( blockAllowed ) {
        int exp = renderBlock.getExpDrop(world, pos, fortune, silk);
        boolean magnetMode = (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.MAGNET));
        for (ItemStack drop : drops) {
            if (drop != null) {
                if (magnetMode) {
                    int wasPickedUp = ForgeEventFactory.onItemPickup(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), drop), player);
                    // 1  = someone allowed the event meaning it's handled,
                    // -1 = someone blocked the event and thus we shouldn't drop it nor insert it
                    // 0  = no body captured the event and we should handle it by hand.
                    if( wasPickedUp == 0 ) {
                        if (!player.addItemStackToInventory(drop))
                            Block.spawnAsEntity(world, pos, drop);
                    }
                } else {
                    Block.spawnAsEntity(world, pos, drop);
                }
            }
        }
        if (magnetMode) {
            if (exp > 0)
                player.giveExperiencePoints(exp);
        } else {
            if (exp > 0)
                renderBlock.getBlock().dropXpOnBlockBreak(world, pos, exp);
        }

        renderBlock.spawnAdditionalDrops(world, pos, tempTool); // Fixes silver fish basically...
    }

    world.removeTileEntity(this.pos);
    world.setBlockState(this.pos, Blocks.AIR.getDefaultState());

    // Add to the break stats
    player.addStat(Stats.BLOCK_MINED.get(renderBlock.getBlock()));

    // Handle special cases
    if(SpecialBlockActions.getRegister().containsKey(renderBlock.getBlock()))
        SpecialBlockActions.getRegister().get(renderBlock.getBlock()).accept(world, pos, renderBlock);
}
 
示例17
@Override
public void populate(int x, int z)
{
	net.minecraft.block.BlockFalling.fallInstantly = true;

	BlockPos blockpos = new BlockPos(x * 16, 0, z * 16);
	Biome Biome = this.worldObj.getBiome(blockpos.add(16, 0, 16));
	this.rand.setSeed(this.worldObj.getSeed());
	long k = this.rand.nextLong() / 2L * 2L + 1L;
	long l = this.rand.nextLong() / 2L * 2L + 1L;
	this.rand.setSeed(x * k + z * l ^ this.worldObj.getSeed());
	boolean flag = false;
	ChunkPos ChunkPos = new ChunkPos(x, z);

	ForgeEventFactory.onChunkPopulate(true, this, this.worldObj, x, z, flag);

	TerrainGen.populate(this, this.worldObj, this.rand, x, z, flag, PopulateChunkEvent.Populate.EventType.LAKE);
	TerrainGen.populate(this, this.worldObj, this.rand, x, z, flag, PopulateChunkEvent.Populate.EventType.LAVA);

	Biome.decorate(this.worldObj, this.rand, new BlockPos(x * 16, 0, z * 16));

	if(TerrainGen.populate(this, this.worldObj, this.rand, x, z, flag, PopulateChunkEvent.Populate.EventType.ANIMALS))
	{
		BlockPos chunkWorldPos = new BlockPos(x * 16, 0, z * 16);
		worldX = x * 16;
		worldZ = z * 16;
		islandChunkX = worldX % MAP_SIZE;
		islandChunkZ = worldZ % MAP_SIZE;
		Point islandPos = new Point(islandChunkX, islandChunkZ).toIslandCoord();
		IslandMap map = Core.getMapForWorld(worldObj, chunkWorldPos);
		Center centerInChunk = null;

		Center temp = map.getClosestCenter(islandPos);
		if(Core.isCenterInRect(temp, (int)islandPos.x, (int)islandPos.y, 16, 16))
			centerInChunk = temp;
		else 
		{
			temp = map.getClosestCenter(islandPos.plus(15, 0));
			if(Core.isCenterInRect(temp, (int)islandPos.x, (int)islandPos.y, 16, 16))
				centerInChunk = temp;
			else
			{
				temp = map.getClosestCenter(islandPos.plus(0, 15));
				if(Core.isCenterInRect(temp, (int)islandPos.x, (int)islandPos.y, 16, 16))
					centerInChunk = temp;
				else
				{
					temp = map.getClosestCenter(islandPos.plus(15, 15));
					if(Core.isCenterInRect(temp, (int)islandPos.x, (int)islandPos.y, 16, 16))
						centerInChunk = temp;
				}
			}
		}
	}

	blockpos = blockpos.add(8, 0, 8);

	if (TerrainGen.populate(this, this.worldObj, this.rand, x, z, flag, PopulateChunkEvent.Populate.EventType.ICE))
	{
		for (int k2 = 0; k2 < 16; k2++)
		{
			for (int j3 = 0; j3 < 16; j3++)
			{
				BlockPos blockpos1 = this.worldObj.getPrecipitationHeight(blockpos.add(k2, 0, j3));
				BlockPos blockpos2 = blockpos1.down();

				if (this.worldObj.canBlockFreezeWater(blockpos2))
				{
					this.worldObj.setBlockState(blockpos2, Blocks.ICE.getDefaultState(), 2);
				}

				if (this.worldObj.canSnowAt(blockpos1, true))
				{
					this.worldObj.setBlockState(blockpos1, Blocks.SNOW_LAYER.getDefaultState(), 2);
				}
			}
		}
	}

	ForgeEventFactory.onChunkPopulate(false, this, this.worldObj, x, z, flag);

	net.minecraft.block.BlockFalling.fallInstantly = false;
}
 
示例18
/**
 * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't fuel
 * @param stack
 * @return
 */
private static int getItemBurnTime(ItemStack stack)
{
    if (stack.isEmpty())
    {
        return 0;
    }

    int burnTime = ForgeEventFactory.getItemBurnTime(stack) * COOKTIME_DEFAULT * 3 / 400;

    if (burnTime >= 0)
    {
        return burnTime;
    }

    Item item = stack.getItem();

    if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR)
    {
        Block block = Block.getBlockFromItem(item);
        if (block.getDefaultState().getMaterial() == Material.WOOD) { return COOKTIME_DEFAULT * 225 / 100; }
        if (block == Blocks.COAL_BLOCK) { return COOKTIME_DEFAULT * 120; }
        if (block == Blocks.WOODEN_SLAB) { return COOKTIME_DEFAULT * 45 / 40; }
        if (block == Blocks.SAPLING) return COOKTIME_DEFAULT * 3 / 4;
    }
    else
    {
        if (item == Items.COAL) return COOKTIME_DEFAULT * 12;
        if (item == Items.BLAZE_ROD) return COOKTIME_DEFAULT * 18;

        if (item == Items.LAVA_BUCKET) return COOKTIME_DEFAULT * 150;
        if (item == Items.STICK) return COOKTIME_DEFAULT * 3 / 4;
        if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemHoe && ((ItemHoe)item).getMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;

        // Ender Furnace custom fuels
        if (item == Items.BLAZE_POWDER) return COOKTIME_DEFAULT * 9;
        if (item == Items.ENDER_PEARL) { return COOKTIME_DEFAULT * 8; }
        if (item == Items.ENDER_EYE) { return COOKTIME_DEFAULT * 17; }
    }

    return 0;
}
 
示例19
@SuppressWarnings("unused")
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    if (!player.isSneaking()) {
        for (int i = 0; i < player.inventory.mainInventory.length; i++) {
            ItemStack torchStack = player.inventory.mainInventory[i];
            if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
                continue;
            }
            Item item = torchStack.getItem();
            if (!(item instanceof ItemBlock)) {
                continue;
            }
            int oldMeta = torchStack.getItemDamage();
            int oldSize = torchStack.stackSize;
            boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
            if (player.capabilities.isCreativeMode) {
                torchStack.setItemDamage(oldMeta);
                torchStack.stackSize = oldSize;
            } else if (torchStack.stackSize <= 0) {
                ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
                player.inventory.mainInventory[i] = null;
            }
            if (result) {
                return true;
            }
        }
    } else {
        ElectricItem.manager.use(stack, searchCost, player);
        if (!world.isRemote) {
            world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "thaumcraft:wandfail", 0.2F, 0.2F + world.rand.nextFloat() * 0.2F);
            return super.onItemUse(stack, player, world, x, y, z, side, xOffset, xOffset, zOffset);
        }
        Minecraft mc = Minecraft.getMinecraft();
        Thaumcraft.instance.renderEventHandler.startScan(player, x, y, z, System.currentTimeMillis() + 5000L);
        player.swingItem();
        return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
示例20
private boolean rightClick(ChunkPosition pos){
    int xCoord = pos.chunkPosX;
    int yCoord = pos.chunkPosY;
    int zCoord = pos.chunkPosZ;

    ForgeDirection faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget)widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World worldObj = drone.getWorld();
    int dx = faceDir.offsetX;
    int dy = faceDir.offsetY;
    int dz = faceDir.offsetZ;
    int x = xCoord /*+ dx*/;
    int y = yCoord /*+ dy*/;
    int z = zCoord /*+ dz*/;

    player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
    player.rotationPitch = faceDir.offsetY * -90;
    switch(faceDir){
        case NORTH:
            player.rotationYaw = 180;
            break;
        case SOUTH:
            player.rotationYaw = 0;
            break;
        case WEST:
            player.rotationYaw = 90;
            break;
        case EAST:
            player.rotationYaw = -90;
    }

    try {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
        if(event.isCanceled()) return false;

        Block block = worldObj.getBlock(x, y, z);

        ItemStack stack = player.getCurrentEquippedItem();
        if(stack != null && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz)) return false;

        if(!worldObj.isAirBlock(x, y, z) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz)) return false;

        if(stack != null) {
            boolean isGoingToShift = false;
            if(stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
                isGoingToShift = true;
            }
            int useX = isGoingToShift ? xCoord : x;
            int useY = isGoingToShift ? yCoord : y;
            int useZ = isGoingToShift ? zCoord : z;
            if(stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz)) return false;

            ItemStack copy = stack.copy();
            player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
            if(!copy.isItemEqual(stack)) return true;
        }
        return false;
    } catch(Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}