mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-22 13:09:47 +00:00
Clean up Acclimatiser
This commit is contained in:
1 parent
6b7b6480c0
commit
84d8ad9144
14 files changed
+427
-396
No files matched your search
@@ -12,7 +12,7 @@ import binnie.craftgui.resource.Texture;
|
||||
import binnie.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.extrabees.core.ExtraBeeTexture;
|
||||
import binnie.genetics.Genetics;
|
||||
import binnie.genetics.machine.Acclimatiser;
|
||||
import binnie.genetics.machine.acclimatiser.Acclimatiser;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -38,12 +38,12 @@ public class WindowAcclimatiser extends WindowMachine {
|
||||
this.setTitle("Acclimatiser");
|
||||
int x = 16;
|
||||
final int y = 32;
|
||||
new ControlSlotArray(this, x, y, 2, 2).create(Acclimatiser.slotReserve);
|
||||
new ControlSlotArray(this, x, y, 2, 2).create(Acclimatiser.SLOT_RESERVE);
|
||||
x += 54;
|
||||
new ControlSlot(this, x + 18, y).assign(4);
|
||||
new ControlSlotArray(this, x, y + 18 + 18, 3, 1).create(Acclimatiser.slotAcclimatiser);
|
||||
new ControlSlotArray(this, x, y + 18 + 18, 3, 1).create(Acclimatiser.SLOT_ACCLIMATISER);
|
||||
x += 72;
|
||||
new ControlSlotArray(this, x, y, 2, 2).create(Acclimatiser.slotDone);
|
||||
new ControlSlotArray(this, x, y, 2, 2).create(Acclimatiser.SLOT_DRONE);
|
||||
new ControlEnergyBar(this, 21, 115, 16, 60, Position.Bottom);
|
||||
new ControlErrorState(this, 181.0f, 83.0f);
|
||||
new ControlPlayerInventory(this);
|
||||
|
||||
@@ -1,379 +0,0 @@
|
||||
package binnie.genetics.machine;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.Mods;
|
||||
import binnie.core.genetics.Gene;
|
||||
import binnie.core.genetics.Tolerance;
|
||||
import binnie.core.machines.IMachine;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.TileEntityMachine;
|
||||
import binnie.core.machines.inventory.ComponentInventorySlots;
|
||||
import binnie.core.machines.inventory.ComponentInventoryTransfer;
|
||||
import binnie.core.machines.inventory.InventorySlot;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.core.machines.power.ComponentPowerReceptor;
|
||||
import binnie.core.machines.power.ComponentProcessIndefinate;
|
||||
import binnie.core.machines.power.ErrorState;
|
||||
import binnie.craftgui.minecraft.IMachineInformation;
|
||||
import binnie.genetics.core.GeneticsGUI;
|
||||
import binnie.genetics.core.GeneticsTexture;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class Acclimatiser {
|
||||
public static final int[] slotReserve = new int[]{0, 1, 2, 3};
|
||||
public static final int slotTarget = 4;
|
||||
public static final int[] slotAcclimatiser = new int[]{5, 6, 7};
|
||||
public static final int[] slotDone = new int[]{8, 9, 10, 11};
|
||||
private static List<ToleranceSystem> toleranceSystems = new ArrayList<>();
|
||||
private static Map<ItemStack, Float> temperatureItems = new HashMap<>();
|
||||
private static Map<ItemStack, Float> humidityItems = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
private static ToleranceSystem getToleranceSystem(final ItemStack stack, final ItemStack acclim) {
|
||||
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
|
||||
if (root != null) {
|
||||
for (final ToleranceSystem system : Acclimatiser.toleranceSystems) {
|
||||
if (Objects.equals(root.getUID(), system.uid) && system.type.hasEffect(acclim)) {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addTolerance(final String uid, final IChromosomeType chromosome, final ToleranceType type) {
|
||||
Acclimatiser.toleranceSystems.add(new ToleranceSystem(uid, chromosome, type));
|
||||
}
|
||||
|
||||
public static float getTemperatureEffect(final ItemStack item) {
|
||||
for (final ItemStack stack : Acclimatiser.temperatureItems.keySet()) {
|
||||
if (stack.isItemEqual(item)) {
|
||||
return Acclimatiser.temperatureItems.get(stack);
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public static float getHumidityEffect(final ItemStack item) {
|
||||
for (final ItemStack stack : Acclimatiser.humidityItems.keySet()) {
|
||||
if (stack.isItemEqual(item)) {
|
||||
return Acclimatiser.humidityItems.get(stack);
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public static void addTemperatureItem(final ItemStack itemstack, final float amount) {
|
||||
if (itemstack == null) {
|
||||
return;
|
||||
}
|
||||
Acclimatiser.temperatureItems.put(itemstack, amount);
|
||||
}
|
||||
|
||||
public static void addHumidityItem(final ItemStack itemstack, final float amount) {
|
||||
if (itemstack == null) {
|
||||
return;
|
||||
}
|
||||
Acclimatiser.humidityItems.put(itemstack, amount);
|
||||
}
|
||||
|
||||
public static void setupRecipes() {
|
||||
if (BinnieCore.isApicultureActive()) {
|
||||
addTolerance(Binnie.Genetics.getBeeRoot().getUID(), EnumBeeChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
addTolerance(Binnie.Genetics.getBeeRoot().getUID(), EnumBeeChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
}
|
||||
if (BinnieCore.isLepidopteryActive()) {
|
||||
addTolerance(Binnie.Genetics.getButterflyRoot().getUID(), EnumButterflyChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
addTolerance(Binnie.Genetics.getButterflyRoot().getUID(), EnumButterflyChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
}
|
||||
if (BinnieCore.isBotanyActive()) {
|
||||
//TODO
|
||||
// addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
// addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
// addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.PH_TOLERANCE, ToleranceType.PH);
|
||||
}
|
||||
addTemperatureItem(new ItemStack(Items.BLAZE_POWDER), 0.5f);
|
||||
addTemperatureItem(new ItemStack(Items.BLAZE_ROD), 0.75f);
|
||||
addTemperatureItem(new ItemStack(Items.LAVA_BUCKET), 0.75f);
|
||||
addTemperatureItem(new ItemStack(Items.SNOWBALL), -0.15f);
|
||||
addTemperatureItem(new ItemStack(Blocks.ICE), -0.75f);
|
||||
addHumidityItem(new ItemStack(Items.WATER_BUCKET), 0.75f);
|
||||
addHumidityItem(new ItemStack(Blocks.SAND), -0.15f);
|
||||
addTemperatureItem(Mods.Forestry.stack("canLava"), 0.75f);
|
||||
addTemperatureItem(Mods.Forestry.stack("refractoryLava"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("canWater"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("refractoryWater"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("waxCapsuleWater"), 0.75f);
|
||||
}
|
||||
|
||||
public static boolean canAcclimatise(final ItemStack stack, final List<ItemStack> acclimatisers) {
|
||||
if (stack == null || acclimatisers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (final ItemStack acclim : acclimatisers) {
|
||||
if (canAcclimatise(stack, acclim)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canAcclimatise(final ItemStack stack, final ItemStack acclim) {
|
||||
final ToleranceSystem system = getToleranceSystem(stack, acclim);
|
||||
return system != null && system.canAlter(stack, acclim);
|
||||
}
|
||||
|
||||
public static ItemStack acclimatise(final ItemStack stack, final ItemStack acc) {
|
||||
final ToleranceSystem system = getToleranceSystem(stack, acc);
|
||||
if (system == null) {
|
||||
return stack;
|
||||
}
|
||||
return system.alter(stack, acc);
|
||||
}
|
||||
|
||||
public static Tolerance alterTolerance(final Tolerance tol, final float effect) {
|
||||
final int[] is = tol.getBounds();
|
||||
int[] range = new int[2];
|
||||
if (effect < 0.0f) {
|
||||
range = new int[]{is[0] - 1, is[1]};
|
||||
} else {
|
||||
range = new int[]{is[0], is[1] + 1};
|
||||
}
|
||||
if (range[0] < -5) {
|
||||
range[0] = -5;
|
||||
}
|
||||
if (range[1] > 5) {
|
||||
range[1] = 5;
|
||||
}
|
||||
final EnumTolerance[] up = {EnumTolerance.NONE, EnumTolerance.UP_1, EnumTolerance.UP_2, EnumTolerance.UP_3, EnumTolerance.UP_4, EnumTolerance.UP_5};
|
||||
final EnumTolerance[] down = {EnumTolerance.NONE, EnumTolerance.DOWN_1, EnumTolerance.DOWN_2, EnumTolerance.DOWN_3, EnumTolerance.DOWN_4, EnumTolerance.DOWN_5};
|
||||
final EnumTolerance[] both = {EnumTolerance.NONE, EnumTolerance.BOTH_1, EnumTolerance.BOTH_2, EnumTolerance.BOTH_3, EnumTolerance.BOTH_4, EnumTolerance.BOTH_5};
|
||||
if (range[0] == 0) {
|
||||
return Tolerance.get(up[range[1]]);
|
||||
}
|
||||
if (range[1] == 0) {
|
||||
return Tolerance.get(down[-range[0]]);
|
||||
}
|
||||
final int avg = (int) ((-range[0] + range[1]) / 2.0f + 0.6f);
|
||||
return Tolerance.get(both[avg]);
|
||||
}
|
||||
|
||||
public static class PackageAcclimatiser extends GeneticMachine.PackageGeneticBase implements IMachineInformation {
|
||||
public PackageAcclimatiser() {
|
||||
super("acclimatiser", GeneticsTexture.Acclimatiser, 9857609, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMachine(final Machine machine) {
|
||||
new ComponentGeneticGUI(machine, GeneticsGUI.Acclimatiser);
|
||||
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
|
||||
inventory.addSlot(4, "process");
|
||||
inventory.getSlot(4).setValidator(new SlotValidator.Individual());
|
||||
inventory.getSlot(4).setReadOnly();
|
||||
inventory.getSlot(4).forbidExtraction();
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.slotReserve, "input")) {
|
||||
slot.forbidExtraction();
|
||||
slot.setValidator(new SlotValidator.Individual());
|
||||
}
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.slotDone, "output")) {
|
||||
slot.setReadOnly();
|
||||
slot.setValidator(new SlotValidator.Individual());
|
||||
}
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.slotAcclimatiser, "acclimatiser")) {
|
||||
slot.setValidator(new ValidatorAcclimatiserItem());
|
||||
}
|
||||
final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
|
||||
transfer.addRestock(Acclimatiser.slotReserve, 4, 1);
|
||||
transfer.addStorage(4, Acclimatiser.slotDone, new ComponentInventoryTransfer.Condition() {
|
||||
@Override
|
||||
public boolean fufilled(final ItemStack stack) {
|
||||
return !Acclimatiser.canAcclimatise(stack, machine.getMachineUtil().getNonNullStacks(Acclimatiser.slotAcclimatiser));
|
||||
}
|
||||
});
|
||||
new ComponentPowerReceptor(machine, 5000);
|
||||
new ComponentAcclimatiserLogic(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity() {
|
||||
return new TileEntityMachine(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComponentAcclimatiserLogic extends ComponentProcessIndefinate {
|
||||
public ComponentAcclimatiserLogic(final IMachine machine) {
|
||||
super(machine, 2.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canWork() {
|
||||
if (this.getUtil().getStack(4) == null) {
|
||||
return new ErrorState.NoItem("No Individual to Acclimatise", 4);
|
||||
}
|
||||
if (this.getUtil().getNonNullStacks(Acclimatiser.slotAcclimatiser).isEmpty()) {
|
||||
return new ErrorState.NoItem("No Acclimatising Items", Acclimatiser.slotAcclimatiser);
|
||||
}
|
||||
return super.canWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canProgress() {
|
||||
if (!Acclimatiser.canAcclimatise(this.getUtil().getStack(4), this.getUtil().getNonNullStacks(Acclimatiser.slotAcclimatiser))) {
|
||||
return new ErrorState.InvalidItem("Cannot Acclimatise this individual with these items", 4);
|
||||
}
|
||||
return super.canProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inProgress() {
|
||||
return this.canWork() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTickTask() {
|
||||
super.onTickTask();
|
||||
if (this.getUtil().getRandom().nextInt(100) == 0) {
|
||||
this.attemptAcclimatisation();
|
||||
}
|
||||
}
|
||||
|
||||
protected void attemptAcclimatisation() {
|
||||
final List<ItemStack> acclms = new ArrayList<>();
|
||||
for (final ItemStack s : this.getUtil().getNonNullStacks(Acclimatiser.slotAcclimatiser)) {
|
||||
if (Acclimatiser.canAcclimatise(this.getUtil().getStack(4), s)) {
|
||||
acclms.add(s);
|
||||
}
|
||||
}
|
||||
final ItemStack acc = acclms.get(this.getUtil().getRandom().nextInt(acclms.size()));
|
||||
final ItemStack acclimed = Acclimatiser.acclimatise(this.getUtil().getStack(4), acc);
|
||||
if (acclimed != null) {
|
||||
this.getUtil().setStack(4, acclimed);
|
||||
boolean removed = false;
|
||||
for (final int i : Acclimatiser.slotAcclimatiser) {
|
||||
if (!removed && this.getUtil().getStack(i) != null && this.getUtil().getStack(i).isItemEqual(acc)) {
|
||||
this.getUtil().decreaseStack(i, 1);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ValidatorAcclimatiserItem extends SlotValidator {
|
||||
public ValidatorAcclimatiserItem() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final ItemStack stack) {
|
||||
for (final ToleranceType type : ToleranceType.values()) {
|
||||
if (type.hasEffect(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Acclimatising Items";
|
||||
}
|
||||
}
|
||||
|
||||
public enum ToleranceType {
|
||||
Temperature,
|
||||
Humidity,
|
||||
PH;
|
||||
|
||||
public float getEffect(final ItemStack stack) {
|
||||
switch (this) {
|
||||
case Temperature: {
|
||||
return Acclimatiser.getTemperatureEffect(stack);
|
||||
}
|
||||
case Humidity: {
|
||||
return Acclimatiser.getHumidityEffect(stack);
|
||||
}
|
||||
case PH: {
|
||||
if (Gardening.isAcidFertiliser(stack)) {
|
||||
return -0.5f * Gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
if (Gardening.isAlkalineFertiliser(stack)) {
|
||||
return 0.5f * Gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public boolean hasEffect(final ItemStack stack) {
|
||||
return this.getEffect(stack) != 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ToleranceSystem {
|
||||
String uid;
|
||||
IChromosomeType chromosomeOrdinal;
|
||||
ToleranceType type;
|
||||
|
||||
private ToleranceSystem(final String uid, final IChromosomeType chromosomeOrdinal, final ToleranceType type) {
|
||||
this.uid = uid;
|
||||
this.chromosomeOrdinal = chromosomeOrdinal;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean canAlter(final ItemStack stack, final ItemStack acclim) {
|
||||
final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
|
||||
final IGenome genome = member.getGenome();
|
||||
final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeOrdinal);
|
||||
final Tolerance tol = Tolerance.get(tolAllele.getValue());
|
||||
final float effect = this.type.getEffect(acclim);
|
||||
return (effect > 0.0f && tol.getBounds()[1] < 5) || (effect < 0.0f && tol.getBounds()[0] > -5);
|
||||
}
|
||||
|
||||
public ItemStack alter(final ItemStack stack, final ItemStack acc) {
|
||||
final Random rand = new Random();
|
||||
final float effect = this.type.getEffect(acc);
|
||||
if (rand.nextFloat() > Math.abs(effect)) {
|
||||
return stack;
|
||||
}
|
||||
final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
|
||||
final IGenome genome = member.getGenome();
|
||||
final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeOrdinal);
|
||||
final Tolerance tol = Tolerance.get(tolAllele.getValue());
|
||||
final Tolerance newTol = Acclimatiser.alterTolerance(tol, effect);
|
||||
if (rand.nextFloat() > 1.0f / (-newTol.getBounds()[0] + newTol.getBounds()[1])) {
|
||||
return stack;
|
||||
}
|
||||
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
|
||||
Inoculator.setGene(new Gene(newTol.getAllele(), this.chromosomeOrdinal, root), stack, rand.nextInt(2));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import binnie.core.machines.component.IInteraction;
|
||||
import binnie.core.machines.network.INetwork;
|
||||
import binnie.genetics.Genetics;
|
||||
import binnie.genetics.core.GeneticsTexture;
|
||||
import binnie.genetics.machine.incubator.Incubator;
|
||||
import binnie.genetics.machine.acclimatiser.PackageAcclimatiser;
|
||||
import binnie.genetics.machine.incubator.PackageIncubator;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,9 +21,9 @@ import net.minecraft.world.World;
|
||||
public enum LaboratoryMachine implements IMachineType {
|
||||
LabMachine(PackageLabMachine.class),
|
||||
Analyser(Analyser.PackageAnalyser.class),
|
||||
Incubator(Incubator.PackageIncubator.class),
|
||||
Incubator(PackageIncubator.class),
|
||||
Genepool(Genepool.PackageGenepool.class),
|
||||
Acclimatiser(Acclimatiser.PackageAcclimatiser.class);
|
||||
Acclimatiser(PackageAcclimatiser.class);
|
||||
|
||||
Class<? extends MachinePackage> clss;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import binnie.core.machines.inventory.ValidatorIcon;
|
||||
import binnie.genetics.CreativeTabGenetics;
|
||||
import binnie.genetics.Genetics;
|
||||
import binnie.genetics.item.GeneticsItems;
|
||||
import binnie.genetics.machine.acclimatiser.Acclimatiser;
|
||||
import binnie.genetics.machine.incubator.Incubator;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.botany.api.EnumFlowerChromosome;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.Mods;
|
||||
import binnie.core.genetics.Tolerance;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Acclimatiser {
|
||||
public static final int[] SLOT_RESERVE = new int[]{0, 1, 2, 3};
|
||||
public static final int SLOT_TARGET = 4;
|
||||
public static final int[] SLOT_ACCLIMATISER = new int[]{5, 6, 7};
|
||||
public static final int[] SLOT_DRONE = new int[]{8, 9, 10, 11};
|
||||
private static List<ToleranceSystem> toleranceSystems = new ArrayList<>();
|
||||
private static Map<ItemStack, Float> temperatureItems = new HashMap<>();
|
||||
private static Map<ItemStack, Float> humidityItems = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
private static ToleranceSystem getToleranceSystem(final ItemStack stack, final ItemStack acclim) {
|
||||
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
|
||||
if (root != null) {
|
||||
for (final ToleranceSystem system : Acclimatiser.toleranceSystems) {
|
||||
if (Objects.equals(root.getUID(), system.uid) && system.type.hasEffect(acclim)) {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addTolerance(final String uid, final IChromosomeType chromosome, final ToleranceType type) {
|
||||
Acclimatiser.toleranceSystems.add(new ToleranceSystem(uid, chromosome, type));
|
||||
}
|
||||
|
||||
public static float getTemperatureEffect(final ItemStack item) {
|
||||
for (final ItemStack stack : Acclimatiser.temperatureItems.keySet()) {
|
||||
if (stack.isItemEqual(item)) {
|
||||
return Acclimatiser.temperatureItems.get(stack);
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public static float getHumidityEffect(final ItemStack item) {
|
||||
for (final ItemStack stack : Acclimatiser.humidityItems.keySet()) {
|
||||
if (stack.isItemEqual(item)) {
|
||||
return Acclimatiser.humidityItems.get(stack);
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public static void addTemperatureItem(final ItemStack itemstack, final float amount) {
|
||||
if (itemstack == null) {
|
||||
return;
|
||||
}
|
||||
Acclimatiser.temperatureItems.put(itemstack, amount);
|
||||
}
|
||||
|
||||
public static void addHumidityItem(final ItemStack itemstack, final float amount) {
|
||||
if (itemstack == null) {
|
||||
return;
|
||||
}
|
||||
Acclimatiser.humidityItems.put(itemstack, amount);
|
||||
}
|
||||
|
||||
public static void setupRecipes() {
|
||||
if (BinnieCore.isApicultureActive()) {
|
||||
addTolerance(Binnie.Genetics.getBeeRoot().getUID(), EnumBeeChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
addTolerance(Binnie.Genetics.getBeeRoot().getUID(), EnumBeeChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
}
|
||||
if (BinnieCore.isLepidopteryActive()) {
|
||||
addTolerance(Binnie.Genetics.getButterflyRoot().getUID(), EnumButterflyChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
addTolerance(Binnie.Genetics.getButterflyRoot().getUID(), EnumButterflyChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
}
|
||||
if (BinnieCore.isBotanyActive()) {
|
||||
addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.HUMIDITY_TOLERANCE, ToleranceType.Humidity);
|
||||
addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.TEMPERATURE_TOLERANCE, ToleranceType.Temperature);
|
||||
addTolerance(Binnie.Genetics.getFlowerRoot().getUID(), EnumFlowerChromosome.PH_TOLERANCE, ToleranceType.PH);
|
||||
}
|
||||
addTemperatureItem(new ItemStack(Items.BLAZE_POWDER), 0.5f);
|
||||
addTemperatureItem(new ItemStack(Items.BLAZE_ROD), 0.75f);
|
||||
addTemperatureItem(new ItemStack(Items.LAVA_BUCKET), 0.75f);
|
||||
addTemperatureItem(new ItemStack(Items.SNOWBALL), -0.15f);
|
||||
addTemperatureItem(new ItemStack(Blocks.ICE), -0.75f);
|
||||
addHumidityItem(new ItemStack(Items.WATER_BUCKET), 0.75f);
|
||||
addHumidityItem(new ItemStack(Blocks.SAND), -0.15f);
|
||||
addTemperatureItem(Mods.Forestry.stack("canLava"), 0.75f);
|
||||
addTemperatureItem(Mods.Forestry.stack("refractoryLava"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("canWater"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("refractoryWater"), 0.75f);
|
||||
addHumidityItem(Mods.Forestry.stack("waxCapsuleWater"), 0.75f);
|
||||
}
|
||||
|
||||
public static boolean canAcclimatise(final ItemStack stack, final List<ItemStack> acclimatisers) {
|
||||
if (stack == null || acclimatisers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (final ItemStack acclim : acclimatisers) {
|
||||
if (canAcclimatise(stack, acclim)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canAcclimatise(final ItemStack stack, final ItemStack acclim) {
|
||||
final ToleranceSystem system = getToleranceSystem(stack, acclim);
|
||||
return system != null && system.canAlter(stack, acclim);
|
||||
}
|
||||
|
||||
public static ItemStack acclimatise(final ItemStack stack, final ItemStack acc) {
|
||||
final ToleranceSystem system = getToleranceSystem(stack, acc);
|
||||
if (system == null) {
|
||||
return stack;
|
||||
}
|
||||
return system.alter(stack, acc);
|
||||
}
|
||||
|
||||
public static Tolerance alterTolerance(final Tolerance tol, final float effect) {
|
||||
final int[] is = tol.getBounds();
|
||||
int[] range = new int[2];
|
||||
if (effect < 0.0f) {
|
||||
range = new int[]{is[0] - 1, is[1]};
|
||||
} else {
|
||||
range = new int[]{is[0], is[1] + 1};
|
||||
}
|
||||
if (range[0] < -5) {
|
||||
range[0] = -5;
|
||||
}
|
||||
if (range[1] > 5) {
|
||||
range[1] = 5;
|
||||
}
|
||||
final EnumTolerance[] up = {EnumTolerance.NONE, EnumTolerance.UP_1, EnumTolerance.UP_2, EnumTolerance.UP_3, EnumTolerance.UP_4, EnumTolerance.UP_5};
|
||||
final EnumTolerance[] down = {EnumTolerance.NONE, EnumTolerance.DOWN_1, EnumTolerance.DOWN_2, EnumTolerance.DOWN_3, EnumTolerance.DOWN_4, EnumTolerance.DOWN_5};
|
||||
final EnumTolerance[] both = {EnumTolerance.NONE, EnumTolerance.BOTH_1, EnumTolerance.BOTH_2, EnumTolerance.BOTH_3, EnumTolerance.BOTH_4, EnumTolerance.BOTH_5};
|
||||
if (range[0] == 0) {
|
||||
return Tolerance.get(up[range[1]]);
|
||||
}
|
||||
if (range[1] == 0) {
|
||||
return Tolerance.get(down[-range[0]]);
|
||||
}
|
||||
final int avg = (int) ((-range[0] + range[1]) / 2.0f + 0.6f);
|
||||
return Tolerance.get(both[avg]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import binnie.core.machines.IMachine;
|
||||
import binnie.core.machines.power.ComponentProcessIndefinate;
|
||||
import binnie.core.machines.power.ErrorState;
|
||||
import binnie.genetics.Genetics;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AcclimatiserLogic extends ComponentProcessIndefinate {
|
||||
public AcclimatiserLogic(final IMachine machine) {
|
||||
super(machine, 2.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canWork() {
|
||||
if (this.getUtil().getStack(Acclimatiser.SLOT_TARGET) == null) {
|
||||
return new ErrorState.NoItem(Genetics.proxy.localise("machine.labMachine.acclimatiser.no.individual"), Acclimatiser.SLOT_TARGET);
|
||||
}
|
||||
if (this.getUtil().getNonNullStacks(Acclimatiser.SLOT_ACCLIMATISER).isEmpty()) {
|
||||
return new ErrorState.NoItem(Genetics.proxy.localise("machine.labMachine.acclimatiser.no.item"), Acclimatiser.SLOT_ACCLIMATISER);
|
||||
}
|
||||
return super.canWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canProgress() {
|
||||
if (!Acclimatiser.canAcclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), this.getUtil().getNonNullStacks(Acclimatiser.SLOT_ACCLIMATISER))) {
|
||||
return new ErrorState.InvalidItem(Genetics.proxy.localise("machine.labMachine.acclimatiser.can.not.acclimatise"), Acclimatiser.SLOT_TARGET);
|
||||
}
|
||||
return super.canProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inProgress() {
|
||||
return this.canWork() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTickTask() {
|
||||
super.onTickTask();
|
||||
if (this.getUtil().getRandom().nextInt(100) == 0) {
|
||||
this.attemptAcclimatisation();
|
||||
}
|
||||
}
|
||||
|
||||
protected void attemptAcclimatisation() {
|
||||
final List<ItemStack> acclms = new ArrayList<>();
|
||||
for (final ItemStack s : this.getUtil().getNonNullStacks(Acclimatiser.SLOT_ACCLIMATISER)) {
|
||||
if (Acclimatiser.canAcclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), s)) {
|
||||
acclms.add(s);
|
||||
}
|
||||
}
|
||||
final ItemStack acc = acclms.get(this.getUtil().getRandom().nextInt(acclms.size()));
|
||||
final ItemStack acclimed = Acclimatiser.acclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), acc);
|
||||
if (acclimed != null) {
|
||||
this.getUtil().setStack(Acclimatiser.SLOT_TARGET, acclimed);
|
||||
boolean removed = false;
|
||||
for (final int i : Acclimatiser.SLOT_ACCLIMATISER) {
|
||||
if (!removed && this.getUtil().getStack(i) != null && this.getUtil().getStack(i).isItemEqual(acc)) {
|
||||
this.getUtil().decreaseStack(i, 1);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.TileEntityMachine;
|
||||
import binnie.core.machines.inventory.ComponentInventorySlots;
|
||||
import binnie.core.machines.inventory.ComponentInventoryTransfer;
|
||||
import binnie.core.machines.inventory.InventorySlot;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.core.machines.power.ComponentPowerReceptor;
|
||||
import binnie.craftgui.minecraft.IMachineInformation;
|
||||
import binnie.genetics.core.GeneticsGUI;
|
||||
import binnie.genetics.core.GeneticsTexture;
|
||||
import binnie.genetics.machine.ComponentGeneticGUI;
|
||||
import binnie.genetics.machine.GeneticMachine;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PackageAcclimatiser extends GeneticMachine.PackageGeneticBase implements IMachineInformation {
|
||||
public PackageAcclimatiser() {
|
||||
super("acclimatiser", GeneticsTexture.Acclimatiser, 9857609, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMachine(final Machine machine) {
|
||||
new ComponentGeneticGUI(machine, GeneticsGUI.Acclimatiser);
|
||||
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
|
||||
inventory.addSlot(4, "process");
|
||||
inventory.getSlot(4).setValidator(new SlotValidator.Individual());
|
||||
inventory.getSlot(4).setReadOnly();
|
||||
inventory.getSlot(4).forbidExtraction();
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.SLOT_RESERVE, "input")) {
|
||||
slot.forbidExtraction();
|
||||
slot.setValidator(new SlotValidator.Individual());
|
||||
}
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.SLOT_DRONE, "output")) {
|
||||
slot.setReadOnly();
|
||||
slot.setValidator(new SlotValidator.Individual());
|
||||
}
|
||||
for (final InventorySlot slot : inventory.addSlotArray(Acclimatiser.SLOT_ACCLIMATISER, "acclimatiser")) {
|
||||
slot.setValidator(new ValidatorAcclimatiserItem());
|
||||
}
|
||||
final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
|
||||
transfer.addRestock(Acclimatiser.SLOT_RESERVE, 4, 1);
|
||||
transfer.addStorage(4, Acclimatiser.SLOT_DRONE, new ComponentInventoryTransfer.Condition() {
|
||||
@Override
|
||||
public boolean fufilled(final ItemStack stack) {
|
||||
return !Acclimatiser.canAcclimatise(stack, machine.getMachineUtil().getNonNullStacks(Acclimatiser.SLOT_ACCLIMATISER));
|
||||
}
|
||||
});
|
||||
new ComponentPowerReceptor(machine, 5000);
|
||||
new AcclimatiserLogic(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity() {
|
||||
return new TileEntityMachine(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import binnie.core.genetics.Gene;
|
||||
import binnie.core.genetics.Tolerance;
|
||||
import binnie.genetics.machine.Inoculator;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
class ToleranceSystem {
|
||||
String uid;
|
||||
IChromosomeType chromosomeOrdinal;
|
||||
ToleranceType type;
|
||||
|
||||
ToleranceSystem(final String uid, final IChromosomeType chromosomeOrdinal, final ToleranceType type) {
|
||||
this.uid = uid;
|
||||
this.chromosomeOrdinal = chromosomeOrdinal;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean canAlter(final ItemStack stack, final ItemStack acclim) {
|
||||
final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
|
||||
final IGenome genome = member.getGenome();
|
||||
final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeOrdinal);
|
||||
final Tolerance tol = Tolerance.get(tolAllele.getValue());
|
||||
final float effect = this.type.getEffect(acclim);
|
||||
return (effect > 0.0f && tol.getBounds()[1] < 5) || (effect < 0.0f && tol.getBounds()[0] > -5);
|
||||
}
|
||||
|
||||
public ItemStack alter(final ItemStack stack, final ItemStack acc) {
|
||||
final Random rand = new Random();
|
||||
final float effect = this.type.getEffect(acc);
|
||||
if (rand.nextFloat() > Math.abs(effect)) {
|
||||
return stack;
|
||||
}
|
||||
final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
|
||||
final IGenome genome = member.getGenome();
|
||||
final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeOrdinal);
|
||||
final Tolerance tol = Tolerance.get(tolAllele.getValue());
|
||||
final Tolerance newTol = Acclimatiser.alterTolerance(tol, effect);
|
||||
if (rand.nextFloat() > 1.0f / (-newTol.getBounds()[0] + newTol.getBounds()[1])) {
|
||||
return stack;
|
||||
}
|
||||
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
|
||||
Inoculator.setGene(new Gene(newTol.getAllele(), this.chromosomeOrdinal, root), stack, rand.nextInt(2));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public enum ToleranceType {
|
||||
Temperature,
|
||||
Humidity,
|
||||
PH;
|
||||
|
||||
public float getEffect(final ItemStack stack) {
|
||||
switch (this) {
|
||||
case Temperature: {
|
||||
return Acclimatiser.getTemperatureEffect(stack);
|
||||
}
|
||||
case Humidity: {
|
||||
return Acclimatiser.getHumidityEffect(stack);
|
||||
}
|
||||
case PH: {
|
||||
if (Gardening.isAcidFertiliser(stack)) {
|
||||
return -0.5f * Gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
if (Gardening.isAlkalineFertiliser(stack)) {
|
||||
return 0.5f * Gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public boolean hasEffect(final ItemStack stack) {
|
||||
return this.getEffect(stack) != 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ValidatorAcclimatiserItem extends SlotValidator {
|
||||
public ValidatorAcclimatiserItem() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final ItemStack stack) {
|
||||
for (final ToleranceType type : ToleranceType.values()) {
|
||||
if (type.hasEffect(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Acclimatising Items";
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -64,9 +63,4 @@ public class Incubator {
|
||||
return LARVAE_RECIPE;
|
||||
}
|
||||
|
||||
private class IncubatorCrafting {
|
||||
ItemStack input;
|
||||
FluidStack fluid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import binnie.core.machines.power.ComponentProcessIndefinate;
|
||||
import binnie.core.machines.power.ErrorState;
|
||||
import binnie.core.machines.power.IProcess;
|
||||
import binnie.core.machines.transfer.TransferRequest;
|
||||
import binnie.genetics.Genetics;
|
||||
import binnie.genetics.api.IIncubatorRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -26,7 +27,7 @@ public class IncubatorLogic extends ComponentProcessIndefinate implements IProce
|
||||
@Override
|
||||
public ErrorState canWork() {
|
||||
if (this.recipe == null) {
|
||||
return new ErrorState("No Recipe", "There is no valid recipe");
|
||||
return new ErrorState(Genetics.proxy.localise("machine.labMachine.incubator.no.recipe"), Genetics.proxy.localise("machine.labMachine.incubator.no.recipe.info"));
|
||||
}
|
||||
return super.canWork();
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ public class PackagePolymeriser extends GeneticMachine.PackageGeneticBase implem
|
||||
slot.setReadOnly();
|
||||
}
|
||||
ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
|
||||
transfer.addRestock(Polymeriser.SLOT_SERUM_RESERVE, 0, 1);
|
||||
transfer.addStorage(0, Polymeriser.SLOT_SERUM_FINISHED, new ComponentInventoryTransfer.Condition() {
|
||||
transfer.addRestock(Polymeriser.SLOT_SERUM_RESERVE, Polymeriser.SLOT_SERUM, 1);
|
||||
transfer.addStorage(Polymeriser.SLOT_SERUM, Polymeriser.SLOT_SERUM_FINISHED, new ComponentInventoryTransfer.Condition() {
|
||||
@Override
|
||||
public boolean fufilled(final ItemStack stack) {
|
||||
return !stack.isItemDamaged();
|
||||
|
||||
Reference in new issue
Block a user