mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
use getters & setters for InfuseStorage (#5416)
* use getters & setters for InfuseStorage to prevent type/amount discrepancies * Fix a few checks when reading from network/NBT * Fix some spacing I screwed up by accident * fix metallurgic infuser gui texture for dark gauge
This commit is contained in:
1 parent
bbcea85fc4
commit
0dba7cb584
14 files changed
+135
-87
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package mekanism.common;
|
||||
|
||||
import mekanism.api.infuse.InfuseObject;
|
||||
import mekanism.api.infuse.InfuseRegistry;
|
||||
import mekanism.api.infuse.InfuseType;
|
||||
import mekanism.common.base.ISustainedData;
|
||||
@@ -8,9 +9,9 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InfuseStorage implements ISustainedData {
|
||||
|
||||
public InfuseType type;
|
||||
private InfuseType type;
|
||||
|
||||
public int amount;
|
||||
private int amount;
|
||||
|
||||
public InfuseStorage() {
|
||||
}
|
||||
@@ -30,6 +31,32 @@ public class InfuseStorage implements ISustainedData {
|
||||
} else if (type == storage.type) {
|
||||
amount = 0;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
type = null;
|
||||
amount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void increase(InfuseStorage input) {
|
||||
if (type == null) {
|
||||
type = input.type;
|
||||
amount = input.amount;
|
||||
} else if (type == input.type) {
|
||||
amount += input.amount;
|
||||
} else {
|
||||
Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception());
|
||||
}
|
||||
}
|
||||
|
||||
public void increase(InfuseObject input) {
|
||||
if (type == null) {
|
||||
type = input.type;
|
||||
amount = input.stored;
|
||||
} else if (type == input.type) {
|
||||
amount += input.stored;
|
||||
} else {
|
||||
Mekanism.logger.error("Tried to increase infusion storage with an incompatible type", new Exception());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,4 +79,30 @@ public class InfuseStorage implements ISustainedData {
|
||||
amount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public InfuseType getType() {
|
||||
return amount == 0 ? null : type;
|
||||
}
|
||||
|
||||
public InfuseStorage setType(InfuseType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return type == null ? 0 : amount;
|
||||
}
|
||||
|
||||
public InfuseStorage setAmount(int amount) {
|
||||
if (amount < 0) {
|
||||
throw new IllegalArgumentException("Amount must be positive");
|
||||
}
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setEmpty() {
|
||||
this.amount = 0;
|
||||
this.type = null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user