mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Giant multiblock refactor
This commit is contained in:
1 parent
201111cb83
commit
aa47599278
259 files changed
+10117
-6495
No files matched your search
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.core.GameMode;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
|
||||
public class FarmFertilizerManager implements INBTTagable, IStreamable {
|
||||
private static final int BUFFER_FERTILIZER = 200;
|
||||
|
||||
private final int fertilizerValue;
|
||||
private int storedFertilizer;
|
||||
|
||||
public FarmFertilizerManager() {
|
||||
this.fertilizerValue = GameMode.getGameMode().getIntegerSetting("farms.fertilizer.value");
|
||||
}
|
||||
|
||||
public boolean hasFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return storedFertilizer >= amount;
|
||||
}
|
||||
|
||||
public void removeFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
storedFertilizer -= amount;
|
||||
if (storedFertilizer < 0) {
|
||||
storedFertilizer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean maintainFertilizer(FarmInventory inventory) {
|
||||
if (storedFertilizer <= BUFFER_FERTILIZER) {
|
||||
if (fertilizerValue < 0) {
|
||||
storedFertilizer += 2000;
|
||||
} else if (inventory.useFertilizer()) {
|
||||
storedFertilizer += fertilizerValue;
|
||||
}
|
||||
}
|
||||
|
||||
return storedFertilizer > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
storedFertilizer = data.getInteger("StoredFertilizer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
data.setInteger("StoredFertilizer", storedFertilizer);
|
||||
}
|
||||
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
if (storedFertilizer == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (storedFertilizer * scale) / (fertilizerValue + BUFFER_FERTILIZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeVarInt(storedFertilizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
storedFertilizer = data.readVarInt();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user