mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 19:49:38 +00:00
Almost done with the new calculating core
This commit is contained in:
1 parent
e0ddb5357d
commit
8b4140ef08
4 files changed
+260
-284
No files matched your search
@@ -1,299 +1,53 @@
|
||||
package pers.towdium.justEnoughCalculation.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
* This is calculating core v3.0, I call it global coordinating calculation XD.
|
||||
* The procudure might be more complex, but can avoid some unexpected results.
|
||||
*/
|
||||
public class Calculator {
|
||||
List<OperateRecord> operateRecords;
|
||||
OperateRecord currentOperate;
|
||||
List<Calculator> calculators;
|
||||
List<ItemRecord> catalystBuffer;
|
||||
ItemRecord itemRecord;
|
||||
List<CostRecord> costRecords;
|
||||
|
||||
|
||||
public Calculator (){}
|
||||
|
||||
public Calculator (ItemStack itemStack, int amount){
|
||||
this(new ItemRecord(itemStack, amount, false), new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true);
|
||||
}
|
||||
|
||||
public Calculator (ItemRecord itemRecord, List<OperateRecord> operateRecords, List<ItemRecord> catalystBuffer, boolean exceedMode){
|
||||
this.catalystBuffer = catalystBuffer;
|
||||
this.itemRecord = itemRecord;
|
||||
this.operateRecords = operateRecords;
|
||||
for (Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item,1, itemRecord.meta), null)){
|
||||
if(checkRecipeValid(recipe)){
|
||||
long count = getOperateCount(recipe, exceedMode);
|
||||
this.currentOperate = new OperateRecord(recipe, count);
|
||||
ImmutableList.Builder<OperateRecord> builder = new ImmutableList.Builder<>();
|
||||
builder.addAll(operateRecords);
|
||||
builder.add(currentOperate);
|
||||
ImmutableList<OperateRecord> records = builder.build();
|
||||
ImmutableList.Builder<Calculator> calculatorBuilder = new ImmutableList.Builder<>();
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
calculatorBuilder.add(new Calculator(
|
||||
new ItemRecord(itemStack, count*recipe.getInputAmount(itemStack), false), records, catalystBuffer, true
|
||||
));
|
||||
public Calculator(ItemStack itemStack, long amount){
|
||||
costRecords = new ArrayList<>();
|
||||
costRecords.add(new CostRecord(new ItemRecord(itemStack, amount, false)));
|
||||
List<ItemRecord> cancellableItems = costRecords.get(0).getCancellableItems();
|
||||
LOOP2:
|
||||
while(cancellableItems.size() != 0){
|
||||
// all the items possible tp cancel
|
||||
for(ItemRecord itemRecord : cancellableItems){
|
||||
// all the recipes for one item
|
||||
LOOP1:
|
||||
for(Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(itemRecord.toItemStack(), null)){
|
||||
CostRecord record = new CostRecord(costRecords.get(costRecords.size()-1), new CostRecord(recipe, getCount(itemRecord, recipe)));
|
||||
for(CostRecord costRecord : costRecords){
|
||||
if(costRecord.equals(record)){
|
||||
continue LOOP1;
|
||||
}
|
||||
costRecords.add(record);
|
||||
cancellableItems = record.getCancellableItems();
|
||||
continue LOOP2;
|
||||
}
|
||||
}
|
||||
this.calculators = calculatorBuilder.build();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
catalystBuffer.add(itemRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Calculator:" + itemRecord.item.getUnlocalizedName() + " x " + itemRecord.amount;
|
||||
}
|
||||
|
||||
public CostRecord getCost(){
|
||||
if(currentOperate != null){
|
||||
CostRecord record = getCurrentCost();
|
||||
for(Calculator calculator : calculators){
|
||||
if(calculator.currentOperate != null){
|
||||
CostRecord buffer = calculator.getCost();
|
||||
record.merge(buffer);
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}else {
|
||||
return new CostRecord();
|
||||
}
|
||||
return costRecords.get(costRecords.size()-1);
|
||||
}
|
||||
|
||||
public CostRecord getCurrentCost(){
|
||||
List<ItemRecord> output = new LinkedList<>();
|
||||
List<ItemRecord> input = new LinkedList<>();
|
||||
for(ItemStack itemStack : currentOperate.recipe.output){
|
||||
if(itemStack != null){
|
||||
output.add(new ItemRecord(itemStack, currentOperate.count*ItemStackWrapper.getUnifiedAmount(itemStack), false));
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : currentOperate.recipe.input){
|
||||
if(itemStack != null){
|
||||
input.add(new ItemRecord(itemStack, currentOperate.count*ItemStackWrapper.getUnifiedAmount(itemStack), false));
|
||||
}
|
||||
}
|
||||
return new Calculator.CostRecord(output, input);
|
||||
protected long getCount(ItemRecord itemRecord, Recipe recipe){
|
||||
long a = recipe.getOutputAmount(itemRecord.toItemStack());
|
||||
return (long) ((double)itemRecord.amount/a + 0.5f);
|
||||
}
|
||||
|
||||
public CostRecord getEmptyCost(){
|
||||
return new CostRecord();
|
||||
}
|
||||
|
||||
protected boolean checkRecipeValid(Recipe recipe){
|
||||
for (OperateRecord record : operateRecords){
|
||||
if(record.recipe.equals(recipe) && record.count == getOperateCount(recipe)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected long getOperateCount(Recipe recipe){
|
||||
return (int)Math.ceil((float)itemRecord.amount/itemRecord.getOutputAmount(recipe));
|
||||
}
|
||||
|
||||
protected long getOperateCount(Recipe recipe, boolean exceed){
|
||||
if(exceed){
|
||||
return (int)Math.ceil((float)itemRecord.amount/itemRecord.getOutputAmount(recipe));
|
||||
} else {
|
||||
return itemRecord.amount/itemRecord.getOutputAmount(recipe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class CostRecord{
|
||||
List<ItemRecord> output;
|
||||
List<ItemRecord> input;
|
||||
List<ItemRecord> catalyst;
|
||||
|
||||
public CostRecord(){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new ArrayList<>();
|
||||
}
|
||||
|
||||
public CostRecord(List<ItemRecord> output, List<ItemRecord> input) {
|
||||
this.output = output;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public void merge(CostRecord costRecord){
|
||||
LOOP1:
|
||||
for(ItemRecord record : costRecord.output){
|
||||
for(ItemRecord record1 : output){
|
||||
if(record1.add(record))
|
||||
continue LOOP1;
|
||||
}
|
||||
output.add(record);
|
||||
}
|
||||
LOOP2:
|
||||
for(ItemRecord record : costRecord.input){
|
||||
for(ItemRecord record1 : input){
|
||||
if(record1.add(record))
|
||||
continue LOOP2;
|
||||
}
|
||||
input.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
public void unify(){
|
||||
cancelIO();
|
||||
for (int i = 0; i < output.size(); i++) {
|
||||
ItemRecord itemRecord = output.get(i);
|
||||
if (!itemRecord.isSameType(Calculator.this.itemRecord)) {
|
||||
CostRecord record = new Calculator(itemRecord, new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true).getCost();
|
||||
record.cancelIO();
|
||||
if (this.canCancelBy(record)) {
|
||||
List<ItemRecord> buffer = record.input;
|
||||
record.input = record.output;
|
||||
record.output = buffer;
|
||||
this.merge(record);
|
||||
this.cancelIO();
|
||||
} else {
|
||||
record = new Calculator(itemRecord, new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), false).getCost();
|
||||
record.cancelIO();
|
||||
if(this.canCancelBy(record)) {
|
||||
List<ItemRecord> buffer = record.input;
|
||||
record.input = record.output;
|
||||
record.output = buffer;
|
||||
this.merge(record);
|
||||
this.cancelIO();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cancelEmpty();
|
||||
}
|
||||
|
||||
protected boolean canCancelBy(CostRecord record){
|
||||
LOOP1:
|
||||
for(ItemRecord itemRecIn : record.output){
|
||||
for(ItemRecord itemRec : output){
|
||||
if(itemRec.isSameType(itemRecIn) && itemRec.amount>=itemRecIn.amount){
|
||||
continue LOOP1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LOOP2:
|
||||
for(ItemRecord itemRecIn : record.input){
|
||||
for(ItemRecord itemRec : input){
|
||||
if(itemRec.isSameType(itemRecIn) && itemRec.amount>=itemRecIn.amount){
|
||||
continue LOOP2;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void cancelIO(){
|
||||
ImmutableList.Builder<ItemRecord> catalystBuilder = new ImmutableList.Builder<>();
|
||||
if(catalyst != null){
|
||||
catalystBuilder.addAll(catalyst);
|
||||
}
|
||||
for (ItemRecord inputRec : input) {
|
||||
for (ItemRecord outputRec : output) {
|
||||
if (inputRec.cancel(outputRec) && inputRec.amount == 0) {
|
||||
LOOP:
|
||||
for (ItemRecord itemRecord : Calculator.this.catalystBuffer){
|
||||
if(itemRecord.isSameType(inputRec)){
|
||||
if(catalyst != null){
|
||||
for (ItemRecord exist : catalyst) {
|
||||
if (itemRecord.isSameType(exist)) {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
catalystBuilder.add(inputRec.copy());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catalyst = catalystBuilder.build();
|
||||
}
|
||||
|
||||
protected void cancelEmpty(){
|
||||
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord record : output){
|
||||
if(record.amount != 0){
|
||||
builder.add(record);
|
||||
}
|
||||
}
|
||||
output = builder.build();
|
||||
builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord record : input){
|
||||
if(record.amount != 0){
|
||||
builder.add(record);
|
||||
}
|
||||
}
|
||||
input = builder.build();
|
||||
}
|
||||
|
||||
public ItemStack[] getOutputStack(){
|
||||
ItemStack[] outputStack = new ItemStack[output.size()];
|
||||
int i = 0;
|
||||
for (ItemRecord record : output){
|
||||
outputStack[i] = record.toItemStack();
|
||||
i++;
|
||||
}
|
||||
return outputStack;
|
||||
}
|
||||
|
||||
public ItemStack[] getInputStack(){
|
||||
ItemStack[] inputStack = new ItemStack[input.size()];
|
||||
int i = 0;
|
||||
for (ItemRecord record : input){
|
||||
inputStack[i] = record.toItemStack();
|
||||
i++;
|
||||
}
|
||||
return inputStack;
|
||||
}
|
||||
|
||||
public ItemStack[] getCatalystStack(){
|
||||
ItemStack[] catalystStack = new ItemStack[catalyst.size()];
|
||||
int i = 0;
|
||||
for (ItemRecord record : catalyst){
|
||||
catalystStack[i] = record.toItemStack();
|
||||
i++;
|
||||
}
|
||||
return catalystStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OperateRecord{
|
||||
Recipe recipe;
|
||||
long count;
|
||||
|
||||
public OperateRecord(Recipe recipe, long count) {
|
||||
this.recipe = recipe;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof OperateRecord)){
|
||||
return false;
|
||||
} else {
|
||||
OperateRecord record = (OperateRecord) obj;
|
||||
return record.recipe.equals(recipe) && record.count == count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package pers.towdium.justEnoughCalculation.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class CostRecord{
|
||||
List<ItemRecord> output;
|
||||
List<ItemRecord> input;
|
||||
List<ItemRecord> catalyst;
|
||||
|
||||
public CostRecord(ItemRecord itemRecord){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new LinkedList<>();
|
||||
input.add(itemRecord);
|
||||
}
|
||||
|
||||
public CostRecord(Recipe recipe, long count){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new LinkedList<>();
|
||||
for(ItemStack itemStack : recipe.output){
|
||||
if(itemStack != null){
|
||||
output.add(new ItemRecord(itemStack, count));
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
input.add(new ItemRecord(itemStack, count));
|
||||
catalyst.add(new ItemRecord(itemStack, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate CostRecord merging two CostRecords
|
||||
* ItemRecord with amount 0 may be left there
|
||||
*/
|
||||
public CostRecord(CostRecord costRecord1, CostRecord costRecord2){
|
||||
output = new ArrayList<>();
|
||||
output.addAll(costRecord1.output);
|
||||
input = new ArrayList<>();
|
||||
input.addAll(costRecord1.input);
|
||||
catalyst = new LinkedList<>();
|
||||
catalyst.addAll(costRecord1.catalyst);
|
||||
// merge output
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.output){
|
||||
for(ItemRecord itemRecordExt : output){
|
||||
if(itemRecordAdd.isSameType(itemRecordExt)){
|
||||
itemRecordExt.add(itemRecordAdd);
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
output.add(itemRecordAdd);
|
||||
}
|
||||
// merge input
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.input){
|
||||
for(ItemRecord itemRecordExt : input){
|
||||
if(itemRecordAdd.isSameType(itemRecordExt)){
|
||||
itemRecordExt.add(itemRecordAdd);
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
input.add(itemRecordAdd);
|
||||
}
|
||||
// cancel catalyst by output
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.output){
|
||||
for (int i = 0; i < catalyst.size(); i++) {
|
||||
ItemRecord itemRecordExt = catalyst.get(i);
|
||||
if (itemRecordAdd.isSameType(itemRecordExt) && itemRecordExt.amount <= itemRecordAdd.amount) {
|
||||
catalyst.remove(i);
|
||||
continue LOOP;
|
||||
}else if(itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.amount -= itemRecordAdd.amount;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
// merge catalyst
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.catalyst){
|
||||
for (ItemRecord itemRecordExt : catalyst) {
|
||||
if (itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.amount += itemRecordAdd.amount;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
catalyst.add(itemRecordAdd);
|
||||
}
|
||||
// cancel input and output
|
||||
for(ItemRecord itemRecordIn : input){
|
||||
for(ItemRecord itemRecordOut : output){
|
||||
if(itemRecordIn.isSameType(itemRecordOut)){
|
||||
long a = itemRecordIn.amount;
|
||||
long b = itemRecordOut.amount;
|
||||
itemRecordIn.amount -= a>b ? b : a;
|
||||
itemRecordOut.amount -= a>b ? b : a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableList<ItemRecord> getCancellableItems(){
|
||||
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
if(!itemRecord.isLocked() && itemRecord.amount != 0){
|
||||
builder.add(itemRecord);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getOutputStack(){
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : output){
|
||||
if(itemRecord.amount != 0){
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getInputStack(){
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
if(itemRecord.amount != 0){
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getCatalystStack(){
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
LOOP:
|
||||
for(ItemRecord itemRecord : catalyst){
|
||||
if(itemRecord.amount != 0){
|
||||
for(ItemRecord record : output){
|
||||
if(itemRecord.isSameType(record)){
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
itemRecord.amount = 0;
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CostRecord) {
|
||||
for (ItemRecord itemRecordIn : output) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).output) {
|
||||
if ((itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) || !itemRecordExt.isSameType(itemRecordIn)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ItemRecord itemRecordIn : input) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).input) {
|
||||
if ((itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount)|| !itemRecordExt.isSameType(itemRecordIn)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).output) {
|
||||
for (ItemRecord itemRecordExt : output) {
|
||||
if ((itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) || !itemRecordExt.isSameType(itemRecordIn)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).input) {
|
||||
for (ItemRecord itemRecordExt : input) {
|
||||
if ((itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount)|| !itemRecordExt.isSameType(itemRecordIn)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,25 @@ public class ItemRecord{
|
||||
int meta;
|
||||
long amount;
|
||||
boolean approx;
|
||||
boolean locked;
|
||||
|
||||
/**
|
||||
* Generate ItemRecord based on the ItemStack and multiply the amount
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long multiplier){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
amount = ItemStackWrapper.getUnifiedAmount(itemStack) * multiplier;
|
||||
approx = itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("approx");
|
||||
}
|
||||
|
||||
public ItemRecord(ItemStack itemStack){
|
||||
this(itemStack, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate ItemRecord with customized amount
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long amount, boolean approx){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
@@ -94,6 +112,14 @@ public class ItemRecord{
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ItemRecord){
|
||||
|
||||
+11
-11
@@ -9,6 +9,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.Calculator;
|
||||
import pers.towdium.justEnoughCalculation.core.CostRecord;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiTooltipScreen;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.recipe.ContainerRecipe;
|
||||
@@ -20,6 +21,7 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -35,7 +37,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
GuiButton buttonMode;
|
||||
GuiButton buttonCalculate;
|
||||
GuiButton buttonView;
|
||||
Calculator.CostRecord costRecord;
|
||||
CostRecord costRecord;
|
||||
int activeSlot = -1;
|
||||
int page = 1;
|
||||
int total = 0;
|
||||
@@ -210,17 +212,17 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
if(costRecord != null){
|
||||
switch (mode){
|
||||
case OUTPUT:
|
||||
total = (costRecord.getOutputStack().length+35)/36;
|
||||
total = (costRecord.getOutputStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getOutputStack(), (page-1)*36);break;
|
||||
case INPUT:
|
||||
total = (costRecord.getInputStack().length+35)/36;
|
||||
total = (costRecord.getInputStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page-1)*36);break;
|
||||
case CATALYST:
|
||||
total = (costRecord.getCatalystStack().length+35)/36;
|
||||
total = (costRecord.getCatalystStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*36);break;
|
||||
}
|
||||
}else {
|
||||
fillSlotsWith(new ItemStack[0], 0);
|
||||
fillSlotsWith(new ArrayList<ItemStack>(), 0);
|
||||
total = 0;
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
@@ -248,11 +250,11 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSlotsWith(ItemStack[] itemStacks, int start){
|
||||
private void fillSlotsWith(List<ItemStack> itemStacks, int start){
|
||||
int pos = 1;
|
||||
for(int i=start; i<start+36; i++){
|
||||
if(i<=itemStacks.length-1){
|
||||
inventorySlots.getSlot(pos++).putStack(itemStacks[i]);
|
||||
if(i<=itemStacks.size()-1){
|
||||
inventorySlots.getSlot(pos++).putStack(itemStacks.get(i));
|
||||
}else {
|
||||
inventorySlots.putStackInSlot(pos++, null);
|
||||
}
|
||||
@@ -263,9 +265,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
try {
|
||||
int i = Integer.valueOf(textFieldAmount.getText());
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), i*100);
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
costRecord = calculator.getCost();
|
||||
} catch (NumberFormatException e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
|
||||
Reference in new issue
Block a user