mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
add big number support
This commit is contained in:
1 parent
b61918ce71
commit
e0ddb5357d
5 files changed
+107
-13
No files matched your search
@@ -22,7 +22,7 @@ public class Calculator {
|
||||
public Calculator (){}
|
||||
|
||||
public Calculator (ItemStack itemStack, int amount){
|
||||
this(new ItemRecord(itemStack, amount), new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true);
|
||||
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){
|
||||
@@ -41,7 +41,7 @@ public class Calculator {
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
calculatorBuilder.add(new Calculator(
|
||||
new ItemRecord(itemStack, count*recipe.getInputAmount(itemStack)), records, catalystBuffer, true
|
||||
new ItemRecord(itemStack, count*recipe.getInputAmount(itemStack), false), records, catalystBuffer, true
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -77,12 +77,12 @@ public class Calculator {
|
||||
List<ItemRecord> input = new LinkedList<>();
|
||||
for(ItemStack itemStack : currentOperate.recipe.output){
|
||||
if(itemStack != null){
|
||||
output.add(new ItemRecord(itemStack, currentOperate.count*ItemStackWrapper.getUnifiedAmount(itemStack)));
|
||||
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)));
|
||||
input.add(new ItemRecord(itemStack, currentOperate.count*ItemStackWrapper.getUnifiedAmount(itemStack), false));
|
||||
}
|
||||
}
|
||||
return new Calculator.CostRecord(output, input);
|
||||
|
||||
@@ -11,17 +11,20 @@ public class ItemRecord{
|
||||
Item item;
|
||||
int meta;
|
||||
long amount;
|
||||
boolean approx;
|
||||
|
||||
public ItemRecord(ItemStack itemStack, long amount){
|
||||
public ItemRecord(ItemStack itemStack, long amount, boolean approx){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
this.amount = amount;
|
||||
this.approx = approx;
|
||||
}
|
||||
|
||||
public ItemRecord(Item item, int meta, long amount) {
|
||||
public ItemRecord(Item item, int meta, long amount, boolean approx) {
|
||||
this.item = item;
|
||||
this.meta = meta;
|
||||
this.amount = amount;
|
||||
this.approx = approx;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +48,7 @@ public class ItemRecord{
|
||||
public boolean add(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
amount += record.amount;
|
||||
approx = approx || record.approx;
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
@@ -65,6 +69,10 @@ public class ItemRecord{
|
||||
long i = amount>record.amount ? record.amount : amount;
|
||||
amount -= i;
|
||||
record.amount -= i;
|
||||
if(approx || record.approx){
|
||||
approx = true;
|
||||
record.approx = true;
|
||||
}
|
||||
return i!=0;
|
||||
}else {
|
||||
return false;
|
||||
@@ -72,14 +80,27 @@ public class ItemRecord{
|
||||
}
|
||||
|
||||
public ItemRecord copy(){
|
||||
return new ItemRecord(item, meta, amount);
|
||||
return new ItemRecord(item, meta, amount, approx);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack(){
|
||||
ItemStack itemStack = new ItemStack(item, 1, meta);
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
tagCompound.setLong("amount", amount);
|
||||
if(approx){
|
||||
tagCompound.setBoolean("approx", true);
|
||||
}
|
||||
itemStack.setTagCompound(tagCompound);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ItemRecord){
|
||||
ItemRecord record = ((ItemRecord) obj);
|
||||
return record.approx == approx && record.item == item && record.amount == amount && record.meta == meta;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,6 @@ public class ItemStackWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getNormalAmount(ItemStack itemStack){
|
||||
return itemStack.stackSize*100;
|
||||
}
|
||||
|
||||
public static String getDisplayAmount(ItemStack itemStack){
|
||||
if(itemStack != null){
|
||||
if(itemStack.getTagCompound() != null){
|
||||
@@ -39,7 +35,7 @@ public class ItemStackWrapper {
|
||||
if(i != 0){
|
||||
return i + "%";
|
||||
}else{
|
||||
return String.valueOf((l+99)/100);
|
||||
return getSimplifiedString((l+99)/100, itemStack.getTagCompound().getBoolean("approx"));
|
||||
}
|
||||
}else {
|
||||
return String.valueOf(itemStack.stackSize);
|
||||
@@ -58,6 +54,7 @@ public class ItemStackWrapper {
|
||||
if(itemStack.hasTagCompound()){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.stackSize = (i+99)/100;
|
||||
itemStack.setTagCompound(null);
|
||||
}else {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
@@ -65,6 +62,42 @@ public class ItemStackWrapper {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static String getSimplifiedString(long l, boolean approx){
|
||||
String s;
|
||||
if(l<999){
|
||||
s = String.valueOf(l);
|
||||
}else if(l<9999){
|
||||
s = String.format("%.2fK", (double)l/1000);
|
||||
}else if(l<99999){
|
||||
s = String.format("%.1fK", (double)l/1000);
|
||||
}else if(l<999999){
|
||||
s = String.format("%.0fK", (double)l/1000);
|
||||
}else if(l<9999999){
|
||||
s = String.format("%.2fM", (double)l/1000000);
|
||||
}else if(l<99999999){
|
||||
s = String.format("%.1fM", (double)l/1000000);
|
||||
}else if(l<999999999){
|
||||
s = String.format("%.0fM", (double)l/1000000);
|
||||
}else if(l<9999999999L){
|
||||
s = String.format("%.2fB", (double)l/1000000000);
|
||||
}else if(l<99999999999L){
|
||||
s = String.format("%.1fB", (double)l/1000000000);
|
||||
}else if(l<999999999999L){
|
||||
s = String.format("%.0fB", (double)l/1000000000);
|
||||
}else if(l<9999999999999L){
|
||||
s = String.format("%.2fT", (double)l/1000000000000L);
|
||||
}else if(l<99999999999999L){
|
||||
s = String.format("%.1fT", (double)l/1000000000000L);
|
||||
}else {
|
||||
s = String.format("%.0fT", (double)l/1000000000000L);
|
||||
}
|
||||
if(approx){
|
||||
return "≈" + s;
|
||||
}else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NBT {
|
||||
public static void initNBT(ItemStack itemStack){
|
||||
if(!itemStack.hasTagCompound()){
|
||||
|
||||
@@ -68,6 +68,28 @@ public class Recipe {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getExactInputIndex(ItemStack itemStack){
|
||||
for(int i = 0; i<12; i++){
|
||||
if(ItemStackWrapper.isStackEqual(input[i], itemStack)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getInputIndex(ItemStack itemStack){
|
||||
for(int i = 0; i<12; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(input[i], itemStack)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean getHasExactInput(ItemStack itemStack){
|
||||
return getExactInputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
public int getOutputAmount(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
@@ -90,6 +112,10 @@ public class Recipe {
|
||||
return getOutputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
public boolean getHasInput(ItemStack itemStack){
|
||||
return getInputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Recipe){
|
||||
@@ -138,6 +164,20 @@ public class Recipe {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public boolean isApprox(){
|
||||
for(ItemStack itemstack : input){
|
||||
if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(ItemStack itemstack : output){
|
||||
if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class ByteBufUtl{
|
||||
public static Recipe fromByte(ByteBuf buf){
|
||||
short a = buf.readShort();
|
||||
|
||||
+1
-1
@@ -266,7 +266,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
} catch (Exception e){
|
||||
} catch (NumberFormatException e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user