mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 07:35:47 +00:00
This commit is contained in:
1 parent
d392666dc4
commit
d4c2d7220d
12 files changed
+119
-30
No files matched your search
@@ -633,7 +633,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
for (FarmTarget target : farmTargets) {
|
||||
// Check fertilizer and water
|
||||
if (!fertilizerManager.hasFertilizer(fertilizerConsumption)) {
|
||||
if (!fertilizerManager.hasFertilizer(inventory, fertilizerConsumption)) {
|
||||
farmWorkStatus.hasFertilizer = false;
|
||||
continue;
|
||||
}
|
||||
@@ -645,7 +645,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
if (cultivateTarget(worldObj, this, target, logic, farmListeners)) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(fertilizerConsumption);
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
|
||||
farmWorkStatus.didWork = true;
|
||||
@@ -729,7 +729,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
// Check fertilizer
|
||||
Boolean hasFertilizer = fertilizerManager.hasFertilizer(fertilizerConsumption);
|
||||
Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
|
||||
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
|
||||
return false;
|
||||
}
|
||||
@@ -750,7 +750,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(fertilizerConsumption);
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
@@ -765,7 +765,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
return fertilizerManager.getStoredFertilizerScaled(scale);
|
||||
return fertilizerManager.getStoredFertilizerScaled(inventory, scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
@@ -23,24 +22,22 @@ import forestry.core.network.IStreamable;
|
||||
|
||||
public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStreamable {
|
||||
private static final int BUFFER_FERTILIZER = 200;
|
||||
|
||||
private final int fertilizerValue = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.value");
|
||||
private int storedFertilizer;
|
||||
|
||||
public FarmFertilizerManager() {
|
||||
storedFertilizer = 0;
|
||||
}
|
||||
|
||||
public boolean hasFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
public boolean hasFertilizer(InventoryFarm inventory, int amount) {
|
||||
if (inventory.getFertilizerValue() < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return storedFertilizer >= amount;
|
||||
}
|
||||
|
||||
public void removeFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
public void removeFertilizer(InventoryFarm inventory, int amount) {
|
||||
if (inventory.getFertilizerValue() < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,6 +49,7 @@ public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStrea
|
||||
|
||||
public boolean maintainFertilizer(InventoryFarm inventory) {
|
||||
if (storedFertilizer <= BUFFER_FERTILIZER) {
|
||||
int fertilizerValue = inventory.getFertilizerValue();
|
||||
if (fertilizerValue < 0) {
|
||||
storedFertilizer += 2000;
|
||||
} else if (inventory.useFertilizer()) {
|
||||
@@ -73,12 +71,12 @@ public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStrea
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
public int getStoredFertilizerScaled(InventoryFarm inventory, int scale) {
|
||||
if (storedFertilizer == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return storedFertilizer * scale / (fertilizerValue + BUFFER_FERTILIZER);
|
||||
return storedFertilizer * scale / (inventory.getFertilizerValue() + BUFFER_FERTILIZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,22 +11,23 @@
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
@@ -49,6 +50,8 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
public static final int SLOT_CAN_COUNT = 1;
|
||||
|
||||
public static final int SLOT_COUNT = SLOT_RESOURCES_COUNT + SLOT_GERMLINGS_COUNT + SLOT_PRODUCTION_COUNT + SLOT_FERTILIZER_COUNT + SLOT_CAN_COUNT;
|
||||
|
||||
private static final int FERTILIZER_MODIFIER = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.modifier");
|
||||
|
||||
private final FarmController farmController;
|
||||
|
||||
@@ -135,9 +138,14 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
if (itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Item item = itemstack.getItem();
|
||||
return PluginCore.items.fertilizerCompound == item;
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,6 +212,21 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
public int getFertilizerValue() {
|
||||
ItemStack fertilizerStack = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizerStack == null || fertilizerStack.stackSize <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return fertilizer.getValue() * FERTILIZER_MODIFIER;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean useFertilizer() {
|
||||
ItemStack fertilizer = getStackInSlot(SLOT_FERTILIZER);
|
||||
|
||||
Reference in new issue
Block a user