Star to rework Machine localisation

This commit is contained in:
Nedelosk committed 2017-06-28 19:10:09 +02:00
1 parent 18f30c8c0d
commit b6d5901f07
17 files changed
+303 -63

No files matched your search

@@ -3,6 +3,7 @@ package binnie.core.machines;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
@@ -103,7 +104,16 @@ class BlockMachine extends Block implements IBlockMachine, ITileEntityProvider {
MachinePackage machinePackage = this.getPackage(meta);
return (machinePackage == null) ? "Unnamed Machine" : machinePackage.getDisplayName();
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
MachinePackage machinePackage = this.getPackage(stack.getMetadata());
if(machinePackage != null){
tooltip.add(machinePackage.getInformation());
}
}
@Override
public int damageDropped(IBlockState state) {
return state.getValue(MACHINE_TYPE);
@@ -4,7 +4,7 @@ import javax.annotation.Nullable;
interface IBlockMachine {
@Nullable
MachinePackage getPackage(final int meta);
MachinePackage getPackage(int meta);
String getMachineName(final int meta);
String getMachineName(int meta);
}
@@ -0,0 +1,57 @@
package binnie.core.machines.power;
import javax.annotation.Nullable;
import binnie.core.util.I18N;
public enum CoreErrorCode implements IErrorStateDefinition {
NO_ITEM("no.item", EnumErrorType.ITEM),
NO_SPACE("no.space", EnumErrorType.ITEM),
NO_SPACE_TANK("no.space.tank", CoreErrorCode.NO_SPACE),
INVALID_ITEM("invalid.item", EnumErrorType.ITEM),
INSUFFICIENT_POWER("insufficient.power", EnumErrorType.POWER),
TANK_FULL("tank.full", EnumErrorType.TANK),
INSUFFICIENT_LIQUID("insufficient.liquid", EnumErrorType.TANK),
NO_RECIPE("no.recipe"),
INVALID_RECIPE("invalid.recipe");
String name;
@Nullable
IErrorStateDefinition parent;
@Nullable
EnumErrorType type;
CoreErrorCode(String name) {
this(name, null, EnumErrorType.NONE);
}
CoreErrorCode(String name, EnumErrorType type) {
this(name, null, type);
}
CoreErrorCode(String name, IErrorStateDefinition parent) {
this(name, parent, EnumErrorType.NONE);
}
CoreErrorCode(String name, IErrorStateDefinition parent, EnumErrorType type) {
this.name = name;
this.parent = parent;
}
public String getDescription(){
return I18N.localise("binniecore.errors." + name + ".desc");
}
public String getName(){
return I18N.localise("binniecore.errors." + name + ".name");
}
@Override
@Nullable
public EnumErrorType getType() {
if(parent != null){
return parent.getType();
}
return type;
}
}
@@ -0,0 +1,20 @@
package binnie.core.machines.power;
public enum EnumErrorType {
NONE,
ITEM,
TANK,
POWER;
public boolean isItemError() {
return this == EnumErrorType.ITEM;
}
public boolean isTankError() {
return this == EnumErrorType.TANK;
}
public boolean isPowerError() {
return this == EnumErrorType.POWER;
}
}
@@ -13,10 +13,44 @@ public class ErrorState implements INbtReadable, INbtWritable {
private boolean itemError;
private boolean tankError;
private boolean powerError;
public ErrorState(final String name, final String desc) {
this.name = "";
this.desc = "";
public ErrorState(IErrorStateDefinition definition) {
this(definition, definition);
}
public ErrorState(IErrorStateDefinition definition, int[] data) {
this(definition, definition, data);
}
public ErrorState(IErrorStateDefinition definition, int data) {
this(definition, definition, new int[]{data});
}
public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition) {
this(nameDefinition.getName(), definition.getDescription());
EnumErrorType type = definition.getType();
this.itemError = type.isItemError();
this.tankError = type.isTankError();
this.powerError = type.isPowerError();
}
public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, int data) {
this(nameDefinition.getName(), definition.getDescription(), new int[]{data});
EnumErrorType type = definition.getType();
this.itemError = type.isItemError();
this.tankError = type.isTankError();
this.powerError = type.isPowerError();
}
public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, int[] data) {
this(nameDefinition.getName(), definition.getDescription(), data);
EnumErrorType type = definition.getType();
this.itemError = type.isItemError();
this.tankError = type.isTankError();
this.powerError = type.isPowerError();
}
public ErrorState(String name, String desc) {
this.data = new int[0];
this.progress = false;
this.itemError = false;
@@ -26,9 +60,7 @@ public class ErrorState implements INbtReadable, INbtWritable {
this.desc = desc;
}
public ErrorState(final String name, final String desc, final int[] data) {
this.name = "";
this.desc = "";
public ErrorState(String name, String desc, int[] data) {
this.data = new int[0];
this.progress = false;
this.itemError = false;
@@ -103,12 +135,20 @@ public class ErrorState implements INbtReadable, INbtWritable {
public Item(final String name, final String desc, final int[] slots) {
super(name, desc, slots);
}
public Item(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, final int[] slots) {
super(nameDefinition, definition, slots);
}
}
public static class Tank extends ErrorState {
public Tank(final String name, final String desc, final int[] slots) {
super(name, desc, slots);
}
public Tank(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, final int[] slots) {
super(nameDefinition, definition, slots);
}
}
public static class NoItem extends Item {
@@ -119,14 +159,27 @@ public class ErrorState implements INbtReadable, INbtWritable {
public NoItem(final String desc, final int[] slots) {
super("No Item", desc, slots);
}
public NoItem(IErrorStateDefinition definition, final int[] slots) {
super("No Item", definition.getDescription(), slots);
}
public NoItem(IErrorStateDefinition definition, final int slot) {
this(definition.getDescription(), new int[]{slot});
}
}
public static class InvalidItem extends Item {
public InvalidItem(final String desc, final int slot) {
this("Invalid Item", desc, slot);
@Deprecated
public InvalidItem(final String desc, int slot) {
this(CoreErrorCode.INVALID_ITEM.getName(), desc, slot);
}
public InvalidItem(IErrorStateDefinition definition, int slot) {
super(definition.getName(), definition.getDescription(), new int[]{slot});
}
public InvalidItem(final String name, final String desc, final int slot) {
public InvalidItem(String name, String desc, int slot) {
super(name, desc, new int[]{slot});
}
}
@@ -139,13 +192,18 @@ public class ErrorState implements INbtReadable, INbtWritable {
public static class InsufficientPower extends ErrorState {
public InsufficientPower() {
super("Insufficient Power", "Not enough power to operate");
super(CoreErrorCode.INSUFFICIENT_POWER);
}
}
public static class TankSpace extends Tank {
@Deprecated
public TankSpace(final String desc, final int tank) {
super("Tank Full", desc, new int[]{tank});
super(CoreErrorCode.TANK_FULL.getName(), desc, new int[]{tank});
}
public TankSpace(IErrorStateDefinition definition, final int tank) {
super(CoreErrorCode.TANK_FULL, definition, new int[]{tank});
}
}
@@ -0,0 +1,9 @@
package binnie.core.machines.power;
public interface IErrorStateDefinition {
String getDescription();
String getName();
EnumErrorType getType();
}
@@ -0,0 +1,67 @@
package binnie.genetics.machine;
import javax.annotation.Nullable;
import binnie.core.machines.power.CoreErrorCode;
import binnie.core.machines.power.EnumErrorType;
import binnie.core.machines.power.IErrorStateDefinition;
import binnie.core.util.I18N;
public enum GeneticsErrorCode implements IErrorStateDefinition {
NO_OWNER("no.owner"),
NO_INDIVIDUAL("no.individual", CoreErrorCode.NO_ITEM),
//Acclimatiser
ACCLIMATISER_NO_ITEM("acclimatiser.no.item", CoreErrorCode.NO_ITEM),
ACCLIMATISER_CAN_NOT_WORK(".acclimatiser.can.not.acclimatise", CoreErrorCode.INVALID_ITEM),
//Analyser
ANALYSER_NO_ITEM("analyser.no.item", CoreErrorCode.NO_ITEM),
ANALYSER_ALREADY_ANALYSED("analyser.already.analysed", EnumErrorType.ITEM),
ANALYSER_INSUFFICIENT_DYE("analyser.insufficient.dye", EnumErrorType.ITEM),
//Genepool
GENEPOOL_INSUFFICIENT_ETHANOL("genepool.insufficient.ethanol", CoreErrorCode.INSUFFICIENT_LIQUID),
GENEPOOL_INSUFFICIENT_ENZYME("genepool.insufficient.enzyme", CoreErrorCode.NO_ITEM),
//Incubator
INCUBATOR_INSUFFICIENT_LIQUID("incubator.insufficient.liquid");
String name;
@Nullable
IErrorStateDefinition parent;
@Nullable
EnumErrorType type;
GeneticsErrorCode(String name) {
this(name, null, EnumErrorType.NONE);
}
GeneticsErrorCode(String name, EnumErrorType type) {
this(name, null, type);
}
GeneticsErrorCode(String name, IErrorStateDefinition parent) {
this(name, parent, EnumErrorType.NONE);
}
GeneticsErrorCode(String name, IErrorStateDefinition parent, EnumErrorType type) {
this.name = name;
this.parent = parent;
}
public String getDescription(){
return I18N.localise("genetics.errors." + name + ".desc");
}
public String getName(){
if(parent != null){
return parent.getName();
}
return I18N.localise("genetics.errors." + name + ".name");
}
@Override
public EnumErrorType getType() {
if(parent != null){
return parent.getType();
}
return type;
}
}
@@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack;
import binnie.core.machines.IMachine;
import binnie.core.machines.power.ComponentProcessIndefinate;
import binnie.core.machines.power.ErrorState;
import binnie.core.util.I18N;
import binnie.genetics.machine.GeneticsErrorCode;
public class AcclimatiserLogic extends ComponentProcessIndefinate {
public AcclimatiserLogic(final IMachine machine) {
@@ -18,10 +18,10 @@ public class AcclimatiserLogic extends ComponentProcessIndefinate {
@Override
public ErrorState canWork() {
if (this.getUtil().getStack(Acclimatiser.SLOT_TARGET).isEmpty()) {
return new ErrorState.NoItem(I18N.localise("genetics.machine.labMachine.acclimatiser.errors.no.individual.desc"), Acclimatiser.SLOT_TARGET);
return new ErrorState(GeneticsErrorCode.NO_INDIVIDUAL, Acclimatiser.SLOT_TARGET);
}
if (this.getUtil().getNonEmptyStacks(Acclimatiser.SLOT_ACCLIMATISER).isEmpty()) {
return new ErrorState.NoItem(I18N.localise("genetics.machine.labMachine.acclimatiser.errors.no.item.desc"), Acclimatiser.SLOT_ACCLIMATISER);
return new ErrorState(GeneticsErrorCode.ACCLIMATISER_NO_ITEM, Acclimatiser.SLOT_ACCLIMATISER);
}
return super.canWork();
}
@@ -29,7 +29,7 @@ public class AcclimatiserLogic extends ComponentProcessIndefinate {
@Override
public ErrorState canProgress() {
if (!Acclimatiser.canAcclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), this.getUtil().getNonEmptyStacks(Acclimatiser.SLOT_ACCLIMATISER))) {
return new ErrorState.InvalidItem(I18N.localise("genetics.machine.labMachine.acclimatiser.errors.can.not.acclimatise.desc"), Acclimatiser.SLOT_TARGET);
return new ErrorState(GeneticsErrorCode.ACCLIMATISER_CAN_NOT_WORK, Acclimatiser.SLOT_TARGET);
}
return super.canProgress();
}
@@ -49,7 +49,7 @@ public class WindowAcclimatiser extends WindowMachine {
@Override
public String getTitle() {
return I18N.localise("genetics.machine.labMachine.acclimatiser");
return I18N.localise("genetics.lab_machine.acclimatiser");
}
@Override
@@ -6,7 +6,7 @@ import binnie.core.machines.Machine;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import binnie.core.util.I18N;
import binnie.genetics.machine.GeneticsErrorCode;
public class AnalyserLogic extends ComponentProcessSetCost implements IProcess {
private static final float DYE_PER_TICK = 0.002f;
@@ -18,11 +18,11 @@ public class AnalyserLogic extends ComponentProcessSetCost implements IProcess {
@Override
public ErrorState canWork() {
if (this.getUtil().isSlotEmpty(Analyser.SLOT_TARGET)) {
return new ErrorState.NoItem(I18N.localise("genetics.machine.labMachine.analyser.errors.no.item.desc"), Analyser.SLOT_TARGET);
return new ErrorState(GeneticsErrorCode.ANALYSER_NO_ITEM, Analyser.SLOT_TARGET);
}
final boolean analysed = Analyser.isAnalysed(this.getUtil().getStack(Analyser.SLOT_TARGET));
if (analysed) {
return new ErrorState.InvalidItem(I18N.localise("genetics.machine.labMachine.analyser.errors.already.analysed.desc"), I18N.localise("genetics.machine.labMachine.analyser.errors.already.analysed.info"), Analyser.SLOT_TARGET);
return new ErrorState(GeneticsErrorCode.ANALYSER_ALREADY_ANALYSED, Analyser.SLOT_TARGET);
}
return super.canWork();
}
@@ -30,10 +30,10 @@ public class AnalyserLogic extends ComponentProcessSetCost implements IProcess {
@Override
public ErrorState canProgress() {
if(getMachine().getOwner() == null){
return new ErrorState.InvalidItem(I18N.localise("genetics.genetics.machine.errors.no.owner.desc"), I18N.localise("genetics.genetics.machine.errors.no.owner.info"), Analyser.SLOT_TARGET);
return new ErrorState(GeneticsErrorCode.NO_OWNER, Analyser.SLOT_TARGET);
}
if (this.getUtil().getSlotCharge(Analyser.SLOT_DYE) == 0.0f) {
return new ErrorState.Item(I18N.localise("genetics.machine.labMachine.analyser.errors.insufficient.dye.desc"), I18N.localise("genetics.machine.labMachine.analyser.errors.insufficient.dye.info"), new int[]{13});
return new ErrorState(GeneticsErrorCode.ANALYSER_INSUFFICIENT_DYE, new int[]{Analyser.SLOT_DYE});
}
return super.canProgress();
}
@@ -17,6 +17,6 @@ public class SlotValidatorUnanalysed extends SlotValidator {
@Override
public String getTooltip() {
return I18N.localise("genetics.machine.labMachine.analyser.tooltips.slots.unanalysed");
return I18N.localise("genetics.machine.lab_machine.analyser.tooltips.slots.unanalysed");
}
}
@@ -63,7 +63,7 @@ public class WindowAnalyser extends WindowMachine {
@Override
public String getTitle() {
return I18N.localise("genetics.machine.labMachine.analyser");
return I18N.localise("genetics.lab_machine.analyser");
}
@Override
@@ -7,12 +7,14 @@ import forestry.api.genetics.ISpeciesRoot;
import binnie.Binnie;
import binnie.core.machines.Machine;
import binnie.core.machines.MachineUtil;
import binnie.core.machines.inventory.IChargedSlots;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.CoreErrorCode;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import binnie.core.util.I18N;
import binnie.genetics.item.GeneticLiquid;
import binnie.genetics.machine.GeneticsErrorCode;
public class GenepoolLogic extends ComponentProcessSetCost implements IProcess {
public static final float ENZYME_PER_PROCESS = 0.25f;
@@ -42,22 +44,23 @@ public class GenepoolLogic extends ComponentProcessSetCost implements IProcess {
@Override
public ErrorState canWork() {
if (this.getUtil().isSlotEmpty(Genepool.SLOT_BEE)) {
return new ErrorState.NoItem(I18N.localise("genetics.machine.errors.no.individual.desc"), Genepool.SLOT_BEE);
return new ErrorState(GeneticsErrorCode.NO_INDIVIDUAL, Genepool.SLOT_BEE);
}
return super.canWork();
}
@Override
public ErrorState canProgress() {
ItemStack individual = this.getUtil().getStack(Genepool.SLOT_BEE);
if (!this.getUtil().spaceInTank(Genepool.TANK_DNA, getDNAAmount(individual))) {
return new ErrorState.NoSpace(I18N.localise("genetics.machine.errors.tanks.no.room.desc"), new int[]{0});
MachineUtil util = getUtil();
ItemStack individual = util.getStack(Genepool.SLOT_BEE);
if (!util.spaceInTank(Genepool.TANK_DNA, getDNAAmount(individual))) {
return new ErrorState(CoreErrorCode.NO_SPACE_TANK, new int[]{Genepool.SLOT_BEE});
}
if (!this.getUtil().liquidInTank(Genepool.TANK_ETHANOL, 1)) {
return new ErrorState.InsufficientLiquid(I18N.localise("genetics.machine.labMachine.genepool.errors.not.enough.ethanol.desc"), Genepool.TANK_ETHANOL);
if (!util.liquidInTank(Genepool.TANK_ETHANOL, 1)) {
return new ErrorState(GeneticsErrorCode.GENEPOOL_INSUFFICIENT_ETHANOL, Genepool.TANK_ETHANOL);
}
if (this.getUtil().getSlotCharge(Genepool.SLOT_ENZYME) == 0.0f) {
return new ErrorState.NoItem(I18N.localise("genetics.machine.labMachine.genepool.errors.insufficient.enzyme.desc"), Genepool.SLOT_ENZYME);
if (util.getSlotCharge(Genepool.SLOT_ENZYME) == 0.0f) {
return new ErrorState(GeneticsErrorCode.GENEPOOL_INSUFFICIENT_ENZYME, Genepool.SLOT_ENZYME);
}
return super.canProgress();
}
@@ -65,18 +68,20 @@ public class GenepoolLogic extends ComponentProcessSetCost implements IProcess {
@Override
protected void onFinishTask() {
super.onFinishTask();
ItemStack individual = this.getUtil().getStack(Genepool.SLOT_BEE);
final int amount = getDNAAmount(individual);
this.getUtil().fillTank(Genepool.TANK_DNA, GeneticLiquid.RawDNA.get(amount));
this.getUtil().deleteStack(Genepool.SLOT_BEE);
MachineUtil util = getUtil();
ItemStack individual = util.getStack(Genepool.SLOT_BEE);
int amount = getDNAAmount(individual);
util.fillTank(Genepool.TANK_DNA, GeneticLiquid.RawDNA.get(amount));
util.deleteStack(Genepool.SLOT_BEE);
}
@Override
protected void onTickTask() {
ItemStack individual = this.getUtil().getStack(Genepool.SLOT_BEE);
MachineUtil util = getUtil();
ItemStack individual = util.getStack(Genepool.SLOT_BEE);
this.ethanolDrain += getDNAAmount(individual) * 1.2f * this.getProgressPerTick() / 100.0f;
if (this.ethanolDrain >= 1.0f) {
this.getUtil().drainTank(Genepool.TANK_ETHANOL, 1);
util.drainTank(Genepool.TANK_ETHANOL, 1);
--this.ethanolDrain;
}
IChargedSlots chargedSlots = this.getMachine().getInterface(IChargedSlots.class);
@@ -59,7 +59,7 @@ public class WindowGenepool extends WindowMachine {
@Override
public String getTitle() {
return I18N.localise("genetics.machine.labMachine.genepool");
return I18N.localise("genetics.machine.lab_machine.genepool");
}
@Override
@@ -10,11 +10,12 @@ import net.minecraftforge.oredict.OreDictionary;
import binnie.core.machines.Machine;
import binnie.core.machines.power.ComponentProcessIndefinate;
import binnie.core.machines.power.CoreErrorCode;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import binnie.core.machines.transfer.TransferRequest;
import binnie.core.util.I18N;
import binnie.genetics.api.IIncubatorRecipe;
import binnie.genetics.machine.GeneticsErrorCode;
public class IncubatorLogic extends ComponentProcessIndefinate implements IProcess {
@Nullable
@@ -36,7 +37,7 @@ public class IncubatorLogic extends ComponentProcessIndefinate implements IProce
@Override
public ErrorState canWork() {
if (this.recipe == null) {
return new ErrorState(I18N.localise("genetics.machine.errors.no.recipe.desc"), I18N.localise("genetics.machine.errors.no.recipe.info"));
return new ErrorState(CoreErrorCode.NO_RECIPE);
}
return super.canWork();
}
@@ -45,10 +46,10 @@ public class IncubatorLogic extends ComponentProcessIndefinate implements IProce
public ErrorState canProgress() {
if (this.recipe != null) {
if (!this.recipe.isInputLiquidSufficient(this.getUtil().getFluid(Incubator.TANK_INPUT))) {
return new ErrorState.InsufficientLiquid(I18N.localise("genetics.machine.labMachine.incubator.errors.no.liquid.desc"), Incubator.TANK_INPUT);
return new ErrorState(GeneticsErrorCode.INCUBATOR_INSUFFICIENT_LIQUID, Incubator.TANK_INPUT);
}
if (!this.roomForOutput) {
return new ErrorState.TankSpace(I18N.localise("genetics.machine.labMachine.incubator.errors.no.room.desc"), Incubator.TANK_OUTPUT);
return new ErrorState(CoreErrorCode.NO_SPACE_TANK, Incubator.TANK_OUTPUT);
}
}
return super.canProgress();