net.minecraft.item.ItemFood Java Examples
The following examples show how to use
net.minecraft.item.ItemFood.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastEat.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onTicks() { if (this.isActive() && Mouse.getEventButton() == 1 && Mouse.isButtonDown(1)) { if (this.mode == 1) { int[] ignoredBlockIds = new int[]{23, 25, 26, 54, 58, 61, 62, 64, 69, 71, 77, 84, 92, 96, 107, 116, 117, 118, 120, 130, 137, 143, 145, 146, 149, 150, 154, 158}; for (int id : ignoredBlockIds) { if (Block.getIdFromBlock(Wrapper.INSTANCE.world().getBlock(Wrapper.INSTANCE.mc().objectMouseOver.blockX, Wrapper.INSTANCE.mc().objectMouseOver.blockY, Wrapper.INSTANCE.mc().objectMouseOver.blockZ)) != id) { continue; } return; } } if (Wrapper.INSTANCE.player().inventory.getCurrentItem() == null) { return; } Item item = Wrapper.INSTANCE.player().inventory.getCurrentItem().getItem(); if (Wrapper.INSTANCE.player().onGround && (item instanceof ItemFood || item instanceof ItemPotion) && (Wrapper.INSTANCE.player().getFoodStats().needFood() || item instanceof ItemPotion || item instanceof ItemAppleGold)) { Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C09PacketHeldItemChange(Wrapper.INSTANCE.player().inventory.currentItem)); for (int i = 0; i < 1000; ++i) { Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C03PacketPlayer(false)); } Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C07PacketPlayerDigging(5, 0, 0, 0, 255)); } } }
Example #2
Source File: CompostRegistry.java From GardenCollection with MIT License | 6 votes |
private void init () { registerCompostMaterial(new ItemStack(Blocks.melon_block), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.pumpkin), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.hay_block), defaultMaterial); registerCompostMaterial(new ItemStack(Items.string), new StandardCompostMaterial(100, 0.0625f)); registerCompostMaterial(new ItemStack(Items.wheat), new StandardCompostMaterial(100, 0.125f)); registerCompostMaterial(new ItemStack(Items.reeds), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.feather), new StandardCompostMaterial(50, 0.0625f)); registerCompostMaterial(new ItemStack(Items.rotten_flesh), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.leather), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial("treeWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("logWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("treeLeaves", defaultMaterial); registerCompostMaterial("treeSapling", defaultMaterial); registerCompostMaterial("stickWood", defaultMaterial); registerCompostMaterial(IPlantable.class, defaultMaterial); registerCompostMaterial(IGrowable.class, defaultMaterial); registerCompostMaterial(BlockLeavesBase.class, defaultMaterial); registerCompostMaterial(BlockVine.class, defaultMaterial); registerCompostMaterial(ItemFood.class, defaultMaterial); }
Example #3
Source File: ExtraInventory.java From ForgeHax with MIT License | 6 votes |
private static int getItemValue(ItemStack stack, boolean loopGuard) { Item item = stack.getItem(); if (stack.isEmpty()) { return 0; } else if (item instanceof ItemArmor || item instanceof ItemPickaxe || item instanceof ItemAxe || item instanceof ItemSword || item instanceof ItemFood || item instanceof ItemArrow || Items.TOTEM_OF_UNDYING.equals(item)) { return 100 * stack.getCount(); // very important } else if (item instanceof ItemShulkerBox) { return 5 + (loopGuard ? 0 : Utils.getShulkerContents(stack) .stream() .mapToInt(ExtraInventory::getItemValueSafe) .sum()); } else { return 5; } }
Example #4
Source File: Food.java From TFC2 with GNU General Public License v3.0 | 6 votes |
public static void addNutrition(FoodStats fs, ItemStack is) { IFoodStatsTFC stats = (IFoodStatsTFC)fs; TFCFood food = FoodRegistry.getInstance().getFood(is.getItem(), is.getItemDamage()); if(food != null && is.getItem() instanceof ItemFood) { ItemFood item = (ItemFood)is.getItem(); Iterator iter = food.foodGroup.iterator(); while(iter.hasNext()) { FoodGroupPair pair = (FoodGroupPair) iter.next(); float amount = pair.amount; if(pair.foodGroup != EnumFoodGroup.None) { amount = Math.min(stats.getNutritionMap().get(pair.foodGroup) + (item.getHealAmount(is) * (pair.amount / 100f)*0.25f), 20); stats.getNutritionMap().put(pair.foodGroup, amount); } } } }
Example #5
Source File: EtFuturum.java From Et-Futurum with The Unlicense | 6 votes |
@EventHandler public void postInit(FMLPostInitializationEvent event) { Items.blaze_rod.setFull3D(); Blocks.trapped_chest.setCreativeTab(CreativeTabs.tabRedstone); if (enableUpdatedFoodValues) { setFinalField(ItemFood.class, Items.carrot, 3, "healAmount", "field_77853_b"); setFinalField(ItemFood.class, Items.baked_potato, 5, "healAmount", "field_77853_b"); } if (enableUpdatedHarvestLevels) { Blocks.packed_ice.setHarvestLevel("pickaxe", 0); Blocks.ladder.setHarvestLevel("axe", 0); Blocks.melon_block.setHarvestLevel("axe", 0); } }
Example #6
Source File: RecipeBuilder.java From EmergingTechnology with MIT License | 5 votes |
public static ItemStack getCookerOutputForItemStack(ItemStack itemStack) { ItemStack resultStack = FurnaceRecipes.instance().getSmeltingResult(itemStack); if (resultStack == null) { return null; } if (resultStack.getItem() instanceof ItemFood) { return resultStack; } return null; }
Example #7
Source File: MachineRecipeLoader.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void registerOrganicRecyclingRecipes() { RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(800).EUt(3).input("treeSapling", 1).fluidInputs(Materials.Water.getFluid(100)).fluidOutputs(Materials.Biomass.getFluid(100)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.POTATO)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.CARROT)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.CACTUS)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.REEDS)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.BROWN_MUSHROOM)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.RED_MUSHROOM)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.BEETROOT)).fluidInputs(Materials.Water.getFluid(20)).fluidOutputs(Materials.Biomass.getFluid(20)).buildAndRegister(); RecipeMaps.CENTRIFUGE_RECIPES.recipeBuilder().duration(144).EUt(5).inputs(new ItemStack(Items.NETHER_WART)).fluidOutputs(Materials.Methane.getFluid(18)).buildAndRegister(); RecipeMaps.CENTRIFUGE_RECIPES.recipeBuilder().duration(144).EUt(5).inputs(new ItemStack(Blocks.BROWN_MUSHROOM)).fluidOutputs(Materials.Methane.getFluid(18)).buildAndRegister(); RecipeMaps.CENTRIFUGE_RECIPES.recipeBuilder().duration(144).EUt(5).inputs(new ItemStack(Blocks.RED_MUSHROOM)).fluidOutputs(Materials.Methane.getFluid(18)).buildAndRegister(); if (ConfigHolder.addFoodMethaneRecipes) { for (Item item : ForgeRegistries.ITEMS.getValuesCollection()) { if (item instanceof ItemFood) { ItemFood itemFood = (ItemFood) item; Collection<ItemStack> subItems = ModHandler.getAllSubItems(new ItemStack(item, 1, GTValues.W)); for (ItemStack itemStack : subItems) { int healAmount = itemFood.getHealAmount(itemStack); float saturationModifier = itemFood.getSaturationModifier(itemStack); if (healAmount > 0) { FluidStack outputStack = Materials.Methane.getFluid(Math.round(9 * healAmount * (1.0f + saturationModifier))); RecipeMaps.CENTRIFUGE_RECIPES.recipeBuilder().duration(144).EUt(5).inputs(itemStack).fluidOutputs(outputStack).buildAndRegister(); } } } } } }
Example #8
Source File: UpgradeFeeding.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void update(IUpgradableBlock chest, ItemStack stack) { if (UpgradeHelper.INSTANCE.getFrequencyTick(chest, stack, 100) != 0) { return; } Entity e = ((IMobileUpgradableBlock)chest).getEntity(); if (e instanceof EntityPlayer && hasUpgradeOperationCost(chest)) { EntityPlayer player = (EntityPlayer) e; if (!player.getFoodStats().needFood()) { return; } IBetterChest inv = (IBetterChest) chest; int idx = InvUtil.findInInvInternal(inv, null, test -> test.getItem() instanceof ItemFood); if (idx != -1) { ItemStack food = inv.getStackInSlot(idx); if (20 - player.getFoodStats().getFoodLevel() >= ((ItemFood)food.getItem()).getHealAmount(food) || player.getFoodStats().getFoodLevel() <= 17 && player.getHealth() <= player.getMaxHealth() - 1.0F || player.getFoodStats().getFoodLevel() <= 6) { inv.setInventorySlotContents(idx, ((ItemFood)food.getItem()).onItemUseFinish(food, chest.getWorldObj(), player)); drawUpgradeOperationCode(chest); inv.markDirty(); } } } }
Example #9
Source File: TileEntityAerialInterface.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
private int getFoodValue(ItemStack item){ return item != null && item.getItem() instanceof ItemFood ? ((ItemFood)item.getItem()).func_150905_g(item) : 0; }
Example #10
Source File: TileEntityCampfire.java From Sakura_mod with MIT License | 4 votes |
@Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { return FurnaceRecipes.instance().getSmeltingResult(stack).getItem() instanceof ItemFood; }
Example #11
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
public InteractEvent handleItemInteract(InteractEvent event, Player player, World world, ItemStack itemInHand) { if (lastInteractItemSecondaryTick == Sponge.getServer().getRunningTimeTicks() || lastInteractItemPrimaryTick == Sponge.getServer().getRunningTimeTicks()) { // ignore return event; } if (event instanceof InteractItemEvent.Primary) { lastInteractItemPrimaryTick = Sponge.getServer().getRunningTimeTicks(); } else { lastInteractItemSecondaryTick = Sponge.getServer().getRunningTimeTicks(); } final ItemType itemType = itemInHand.getType(); if (itemInHand.isEmpty() || itemType instanceof ItemFood) { return event; } final boolean primaryEvent = event instanceof InteractItemEvent.Primary || event instanceof InteractBlockEvent.Primary; if (!GPFlags.INTERACT_ITEM_PRIMARY && primaryEvent || !GPFlags.INTERACT_ITEM_SECONDARY && !primaryEvent || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return event; } if (primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_PRIMARY.toString(), itemInHand.getType(), world.getProperties())) { return event; } if (!primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_SECONDARY.toString(), itemInHand.getType(), world.getProperties())) { return event; } final Cause cause = event.getCause(); final EventContext context = cause.getContext(); final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE); final Vector3d interactPoint = event.getInteractionPoint().orElse(null); final Entity entity = context.get(EventContextKeys.ENTITY_HIT).orElse(null); final Location<World> location = entity != null ? entity.getLocation() : blockSnapshot != BlockSnapshot.NONE ? blockSnapshot.getLocation().get() : interactPoint != null ? new Location<World>(world, interactPoint) : player.getLocation(); final String ITEM_PERMISSION = primaryEvent ? GPPermissions.INTERACT_ITEM_PRIMARY : GPPermissions.INTERACT_ITEM_SECONDARY; final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); if (!itemInHand.isEmpty() && (itemInHand.getType().equals(GriefPreventionPlugin.instance.modificationTool) || itemInHand.getType().equals(GriefPreventionPlugin.instance.investigationTool))) { GPPermissionHandler.addEventLogEntry(event, location, itemInHand, blockSnapshot == null ? entity : blockSnapshot, player, ITEM_PERMISSION, null, Tristate.TRUE); if (investigateClaim(event, player, blockSnapshot, itemInHand)) { return event; } onPlayerHandleShovelAction(event, blockSnapshot, player, ((HandInteractEvent) event).getHandType(), playerData); return event; } final GPClaim claim = this.dataStore.getClaimAtPlayer(location, playerData, true); if (GPPermissionHandler.getClaimPermission(event, location, claim, ITEM_PERMISSION, player, itemType, player, TrustType.ACCESSOR, true) == Tristate.FALSE) { Text message = GriefPreventionPlugin.instance.messageData.permissionInteractItem .apply(ImmutableMap.of( "owner", claim.getOwnerName(), "item", itemInHand.getType().getId())).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message); if (event instanceof InteractItemEvent) { if (!SpongeImplHooks.isFakePlayer(((EntityPlayerMP) player)) && itemType == ItemTypes.WRITABLE_BOOK) { ((EntityPlayerMP) player).closeScreen(); } } event.setCancelled(true); } return event; }
Example #12
Source File: CompostRegistry.java From ExNihiloAdscensio with MIT License | 4 votes |
public static void recommendAllFood(File file) { if(FMLCommonHandler.instance().getSide().isServer()) { return; } IBlockState dirt = Blocks.DIRT.getDefaultState(); Color brown = new Color("7F3F0F"); Map<String, Compostable> recommended = Maps.newHashMap(); for(Item item : Item.REGISTRY) { if(item instanceof ItemFood) { ItemFood food = (ItemFood) item; List<ItemStack> stacks = Lists.newArrayList(); food.getSubItems(food, null, stacks); for(ItemStack foodStack : stacks) { ItemInfo foodItemInfo = new ItemInfo(foodStack); if(!containsItem(foodItemInfo)) { int hungerRestored = food.getHealAmount(foodStack); recommended.put(foodItemInfo.toString(), new Compostable(hungerRestored * 0.025F, brown, new ItemInfo(dirt))); } } } } String json = gson.toJson(recommended, new TypeToken<Map<String, Compostable>>(){}.getType()); try { Files.write(file.toPath(), json.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException e) { e.printStackTrace(); } }
Example #13
Source File: AutoEatMod.java From ForgeHax with MIT License | 4 votes |
@SubscribeEvent public void onUpdate(LocalPlayerUpdateEvent event) { if (getLocalPlayer().isCreative()) { return; } int currentSelected = LocalPlayerInventory.getSelected().getIndex(); boolean wasEating = eating; eating = false; LocalPlayerInventory.getHotbarInventory() .stream() .filter(InvItem::nonEmpty) .filter(this::isFoodItem) .filter(this::isGoodFood) .max( Comparator.comparingDouble(this::getPreferenceValue) .thenComparing(LocalPlayerInventory::getHotbarDistance)) .filter(this::shouldEat) .ifPresent( best -> { food = (ItemFood) best.getItem(); LocalPlayerInventory.setSelected(best, ticks -> !eating); eating = true; if (!checkFailsafe()) { reset(); eating = true; return; } if (currentSelected != best.getIndex()) { MinecraftForge.EVENT_BUS.post(new ForgeHaxEvent(Type.EATING_SELECT_FOOD)); lastHotbarIndex = best.getIndex(); selectedTicks = 0; } if (selectedTicks > select_wait.get()) { if (!wasEating) { MinecraftForge.EVENT_BUS.post(new ForgeHaxEvent(Type.EATING_START)); } Fields.Minecraft_rightClickDelayTimer.set(MC, 4); getPlayerController() .processRightClick(getLocalPlayer(), getWorld(), EnumHand.MAIN_HAND); ++eatingTicks; } }); if (lastHotbarIndex != -1) { if (lastHotbarIndex == LocalPlayerInventory.getSelected().getIndex()) { selectedTicks++; } else { selectedTicks = 0; } } lastHotbarIndex = LocalPlayerInventory.getSelected().getIndex(); if (wasEating && !eating) { reset(); } }
Example #14
Source File: AutoEatMod.java From ForgeHax with MIT License | 4 votes |
private ItemFood toFood(InvItem inv) { return (ItemFood) inv.getItem(); }
Example #15
Source File: AutoEatMod.java From ForgeHax with MIT License | 4 votes |
private boolean isFoodItem(InvItem inv) { return inv.getItem() instanceof ItemFood; }
Example #16
Source File: MoCEntityAmbient.java From mocreaturesdev with GNU General Public License v3.0 | 2 votes |
/** * List of edible foods * * @param item1 * @return */ public boolean isItemEdible(Item item1) { return (item1 instanceof ItemFood) || (item1 instanceof ItemSeeds) || item1.itemID == Item.wheat.itemID || item1.itemID == Item.sugar.itemID || item1.itemID == Item.cake.itemID || item1.itemID == Item.egg.itemID; }
Example #17
Source File: MoCEntityAnimal.java From mocreaturesdev with GNU General Public License v3.0 | 2 votes |
/** * List of edible foods * * @param item1 * @return */ public boolean isItemEdible(Item item1) { return (item1 instanceof ItemFood) || (item1 instanceof ItemSeeds) || item1.itemID == Item.wheat.itemID || item1.itemID == Item.sugar.itemID || item1.itemID == Item.cake.itemID || item1.itemID == Item.egg.itemID; }