From d435b01578b45224c0043d051be5e350e600c27f Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Tue, 16 Apr 2019 12:19:15 +0200 Subject: [PATCH] Meat feeders now fill from tank in your inventory, closes #444 --- gradle.properties | 2 +- .../proxy/event/MeatFeederTickHandler.java | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 74b90928d..01809799e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G -mod_version=1.12.11 +mod_version=1.12.12 minecraft_version=1.12.2 teslacorelib_version=1.0.15.+ teslacorelib_mc_version=1.12.2 diff --git a/src/main/java/com/buuz135/industrial/proxy/event/MeatFeederTickHandler.java b/src/main/java/com/buuz135/industrial/proxy/event/MeatFeederTickHandler.java index 6d66f8dd3..1ab694a14 100644 --- a/src/main/java/com/buuz135/industrial/proxy/event/MeatFeederTickHandler.java +++ b/src/main/java/com/buuz135/industrial/proxy/event/MeatFeederTickHandler.java @@ -22,21 +22,40 @@ package com.buuz135.industrial.proxy.event; import com.buuz135.industrial.item.MeatFeederItem; +import com.buuz135.industrial.proxy.FluidsRegistry; import com.buuz135.industrial.proxy.ItemRegistry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class MeatFeederTickHandler { - public static boolean meatTick(ItemStack stack, EntityPlayer player) { - int filledAmount = ((MeatFeederItem) stack.getItem()).getFilledAmount(stack); + public static boolean meatTick(ItemStack feeder, EntityPlayer player) { + int filledAmount = ((MeatFeederItem) feeder.getItem()).getFilledAmount(feeder); if (filledAmount >= 400 && (player.getFoodStats().getSaturationLevel() < 20 || player.getFoodStats().getFoodLevel() < 20)) { - ((MeatFeederItem) stack.getItem()).drain(stack, 400); + ((MeatFeederItem) feeder.getItem()).drain(feeder, 400); player.getFoodStats().addStats(1, 1); return true; } + for (ItemStack stack : player.inventory.mainInventory) { + if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { + IFluidHandlerItem itemCap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); + if (!feeder.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) continue; + FluidStack amount = feeder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).drain(128000, false); + FluidStack fluidStack = itemCap.drain(new FluidStack(FluidsRegistry.MEAT, amount == null ? 128000 : 128000 - amount.amount), false); + if (fluidStack != null) { + int filled = feeder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).fill(fluidStack, true); + if (filled > 0) { + itemCap.drain(filled, true); + break; + } + } + } + } return false; }