mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 19:49:38 +00:00
Chore: reformat code
This commit is contained in:
1 parent
434c1498de
commit
4b5de3267e
28 files changed
+872
-814
No files matched your search
@@ -35,8 +35,7 @@ import java.util.ArrayList;
|
||||
dependencies = "after:NotEnoughItems")
|
||||
public class JustEnoughCalculation {
|
||||
public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator")
|
||||
.setTextureName(Reference.MODID + ":" +
|
||||
"itemCalculator");
|
||||
.setTextureName(Reference.MODID + ":" + "itemCalculator");
|
||||
public static SimpleNetworkWrapper networkWrapper;
|
||||
public static Logger log = LogManager.getLogger(Reference.MODID);
|
||||
|
||||
@@ -53,15 +52,10 @@ public class JustEnoughCalculation {
|
||||
JECConfig.preInit(event);
|
||||
GameRegistry.registerItem(itemCalculator, itemCalculator.getUnlocalizedName().substring(5));
|
||||
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);
|
||||
networkWrapper
|
||||
.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1,
|
||||
Side.SERVER);
|
||||
networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2,
|
||||
Side.SERVER);
|
||||
networkWrapper
|
||||
.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT);
|
||||
networkWrapper
|
||||
.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER);
|
||||
networkWrapper.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1, Side.SERVER);
|
||||
networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2, Side.SERVER);
|
||||
networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT);
|
||||
networkWrapper.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -70,9 +64,8 @@ public class JustEnoughCalculation {
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().
|
||||
register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory"));
|
||||
}*/
|
||||
ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(itemCalculator), "SIS", "SRS",
|
||||
"SOS", 'S', "stone", 'I', "dyeBlack", 'R',
|
||||
"dustRedstone", 'O', "ingotIron") {
|
||||
ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(itemCalculator), "SIS", "SRS", "SOS", 'S', "stone",
|
||||
'I', "dyeBlack", 'R', "dustRedstone", 'O', "ingotIron") {
|
||||
{
|
||||
try {
|
||||
Field f = ShapedOreRecipe.class.getDeclaredField("input");
|
||||
@@ -169,11 +162,11 @@ public class JustEnoughCalculation {
|
||||
if (type != null) {
|
||||
switch (this.getType()) {
|
||||
case Boolean:
|
||||
return config.get(this.getCategory(), this.getName(),
|
||||
(Boolean) this.getDefault(), this.getComment());
|
||||
return config.get(this.getCategory(), this.getName(), (Boolean) this.getDefault(),
|
||||
this.getComment());
|
||||
case ListString:
|
||||
return config.get(this.getCategory(), this.getName(),
|
||||
(String[]) this.getDefault(), this.getComment());
|
||||
return config.get(this.getCategory(), this.getName(), (String[]) this.getDefault(),
|
||||
this.getComment());
|
||||
}
|
||||
config.getCategory(EnumCategory.General.toString()).get(this.getName());
|
||||
}
|
||||
@@ -204,8 +197,7 @@ public class JustEnoughCalculation {
|
||||
public static Object empty;
|
||||
|
||||
public static void preInit(FMLPreInitializationEvent event) {
|
||||
config = new Configuration(new File(event.getModConfigurationDirectory(),
|
||||
"JustEnoughCalculation" + ".cfg"),
|
||||
config = new Configuration(new File(event.getModConfigurationDirectory(), "JustEnoughCalculation" + ".cfg"),
|
||||
Reference.VERSION);
|
||||
config.load();
|
||||
handleFormerVersion();
|
||||
@@ -231,6 +223,6 @@ public class JustEnoughCalculation {
|
||||
public static class Reference {
|
||||
public static final String MODID = "jecalculation";
|
||||
public static final String MODNAME = "Just Enough Calculation";
|
||||
public static final String VERSION = "@VERSION@";
|
||||
public static final String VERSION = "0.4.0";
|
||||
}
|
||||
}
|
||||
@@ -15,28 +15,30 @@ import java.util.List;
|
||||
|
||||
public class Calculator {
|
||||
List<CostRecord> costRecords;
|
||||
|
||||
public Calculator(ItemStack itemStack, long amount){
|
||||
|
||||
public Calculator(ItemStack itemStack, long amount) {
|
||||
int count = 0;
|
||||
costRecords = new ArrayList<>();
|
||||
costRecords.add(new CostRecord(new ItemRecord(itemStack, amount, false)));
|
||||
List<ItemRecord> cancellableItems = costRecords.get(0).getCancellableItems();
|
||||
LOOP2:
|
||||
while(cancellableItems.size() != 0){
|
||||
while (cancellableItems.size() != 0) {
|
||||
if (count > 100) {
|
||||
return;
|
||||
}
|
||||
// all the items possible tp cancel
|
||||
for(ItemRecord itemRecord : cancellableItems){
|
||||
for (ItemRecord itemRecord : cancellableItems) {
|
||||
// all the recipes for one item
|
||||
LOOP1:
|
||||
for(Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(itemRecord.toItemStack(), null)){
|
||||
for (Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler()
|
||||
.getAllRecipeOf(itemRecord.toItemStack(), null)) {
|
||||
long times = getCount(itemRecord, recipe);
|
||||
ItemRecord buffer = itemRecord.copy();
|
||||
buffer.amount = recipe.getOutputAmount(buffer.toItemStack())*times;
|
||||
CostRecord record = new CostRecord(costRecords.get(costRecords.size()-1), new CostRecord(recipe, times, itemRecord.approx, buffer));
|
||||
for(CostRecord costRecord : costRecords){
|
||||
if(costRecord.equals(record)){
|
||||
buffer.amount = recipe.getOutputAmount(buffer.toItemStack()) * times;
|
||||
CostRecord record = new CostRecord(costRecords.get(costRecords.size() - 1),
|
||||
new CostRecord(recipe, times, itemRecord.approx, buffer));
|
||||
for (CostRecord costRecord : costRecords) {
|
||||
if (costRecord.equals(record)) {
|
||||
continue LOOP1;
|
||||
}
|
||||
costRecords.add(record);
|
||||
@@ -50,12 +52,12 @@ public class Calculator {
|
||||
}
|
||||
}
|
||||
|
||||
public CostRecord getCost(){
|
||||
return costRecords.get(costRecords.size()-1);
|
||||
public CostRecord getCost() {
|
||||
return costRecords.get(costRecords.size() - 1);
|
||||
}
|
||||
|
||||
protected long getCount(ItemRecord itemRecord, Recipe recipe){
|
||||
protected long getCount(ItemRecord itemRecord, Recipe recipe) {
|
||||
long a = recipe.getOutputAmount(itemRecord.toItemStack());
|
||||
return (long)Math.ceil(itemRecord.amount/(double)a);
|
||||
return (long) Math.ceil(itemRecord.amount / (double) a);
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,13 @@ import java.util.List;
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class CostRecord{
|
||||
public class CostRecord {
|
||||
private List<ItemRecord> output;
|
||||
private List<ItemRecord> input;
|
||||
private List<ItemRecord> catalyst;
|
||||
private List<ItemRecord> procedure;
|
||||
|
||||
public CostRecord(ItemRecord itemRecord){
|
||||
public CostRecord(ItemRecord itemRecord) {
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new LinkedList<>();
|
||||
@@ -24,21 +24,21 @@ public class CostRecord{
|
||||
input.add(itemRecord);
|
||||
}
|
||||
|
||||
public CostRecord(Recipe recipe, long count, boolean approx, ItemRecord dest){
|
||||
public CostRecord(Recipe recipe, long count, boolean approx, ItemRecord dest) {
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new LinkedList<>();
|
||||
procedure = new ArrayList<>();
|
||||
boolean b = recipe.isApprox() || approx;
|
||||
for(ItemStack itemStack : recipe.output){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : recipe.output) {
|
||||
if (itemStack != null) {
|
||||
ItemRecord record = new ItemRecord(itemStack, count);
|
||||
record.approx = b;
|
||||
output.add(record);
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : recipe.input) {
|
||||
if (itemStack != null) {
|
||||
ItemRecord record = new ItemRecord(itemStack, count);
|
||||
record.approx = b;
|
||||
input.add(record);
|
||||
@@ -54,31 +54,31 @@ public class CostRecord{
|
||||
* Generate CostRecord merging two CostRecords
|
||||
* ItemRecord with amount 0 may be left there
|
||||
*/
|
||||
public CostRecord(CostRecord costRecord1, CostRecord costRecord2){
|
||||
public CostRecord(CostRecord costRecord1, CostRecord costRecord2) {
|
||||
output = new ArrayList<>();
|
||||
for (ItemRecord record : costRecord1.output){
|
||||
for (ItemRecord record : costRecord1.output) {
|
||||
output.add(record.copy());
|
||||
}
|
||||
input = new ArrayList<>();
|
||||
for (ItemRecord record : costRecord1.input){
|
||||
for (ItemRecord record : costRecord1.input) {
|
||||
input.add(record.copy());
|
||||
}
|
||||
catalyst = new LinkedList<>();
|
||||
for (ItemRecord record : costRecord1.catalyst){
|
||||
for (ItemRecord record : costRecord1.catalyst) {
|
||||
catalyst.add(record.copy());
|
||||
}
|
||||
procedure = new ArrayList<>();
|
||||
for (ItemRecord record : costRecord1.procedure){
|
||||
for (ItemRecord record : costRecord1.procedure) {
|
||||
procedure.add(record.copy());
|
||||
}
|
||||
for (ItemRecord record : costRecord2.procedure){
|
||||
for (ItemRecord record : costRecord2.procedure) {
|
||||
procedure.add(record.copy());
|
||||
}
|
||||
// merge output
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.output){
|
||||
for(ItemRecord itemRecordExt : output){
|
||||
if(itemRecordAdd.isSameType(itemRecordExt)){
|
||||
for (ItemRecord itemRecordAdd : costRecord2.output) {
|
||||
for (ItemRecord itemRecordExt : output) {
|
||||
if (itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.add(itemRecordAdd);
|
||||
continue LOOP;
|
||||
}
|
||||
@@ -87,9 +87,9 @@ public class CostRecord{
|
||||
}
|
||||
// merge input
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.input){
|
||||
for(ItemRecord itemRecordExt : input){
|
||||
if(itemRecordAdd.isSameType(itemRecordExt)){
|
||||
for (ItemRecord itemRecordAdd : costRecord2.input) {
|
||||
for (ItemRecord itemRecordExt : input) {
|
||||
if (itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.add(itemRecordAdd);
|
||||
continue LOOP;
|
||||
}
|
||||
@@ -98,13 +98,13 @@ public class CostRecord{
|
||||
}
|
||||
// cancel catalyst by output
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.output){
|
||||
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)) {
|
||||
} else if (itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.minus(itemRecordAdd);
|
||||
continue LOOP;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class CostRecord{
|
||||
}
|
||||
// merge catalyst
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.catalyst){
|
||||
for (ItemRecord itemRecordAdd : costRecord2.catalyst) {
|
||||
for (ItemRecord itemRecordExt : catalyst) {
|
||||
if (itemRecordAdd.isSameType(itemRecordExt)) {
|
||||
itemRecordExt.add(itemRecordAdd);
|
||||
@@ -122,38 +122,38 @@ public class CostRecord{
|
||||
catalyst.add(itemRecordAdd.copy());
|
||||
}
|
||||
// cancel input and output
|
||||
for(ItemRecord itemRecordIn : input){
|
||||
for(ItemRecord itemRecordOut : output){
|
||||
if(itemRecordIn.isSameType(itemRecordOut)){
|
||||
for (ItemRecord itemRecordIn : input) {
|
||||
for (ItemRecord itemRecordOut : output) {
|
||||
if (itemRecordIn.isSameType(itemRecordOut)) {
|
||||
itemRecordIn.cancel(itemRecordOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableList<ItemRecord> getCancellableItems(){
|
||||
ImmutableList<ItemRecord> getCancellableItems() {
|
||||
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
if(!itemRecord.isLocked() && itemRecord.amount != 0){
|
||||
for (ItemRecord itemRecord : input) {
|
||||
if (!itemRecord.isLocked() && itemRecord.amount != 0) {
|
||||
builder.add(itemRecord);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getOutputStack(){
|
||||
public ImmutableList<ItemStack> getOutputStack() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : output){
|
||||
if(itemRecord.amount != 0){
|
||||
for (ItemRecord itemRecord : output) {
|
||||
if (itemRecord.amount != 0) {
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getProcedureStack(){
|
||||
public ImmutableList<ItemStack> getProcedureStack() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for (int i = procedure.size()-1; i >=0; i--) {
|
||||
for (int i = procedure.size() - 1; i >= 0; i--) {
|
||||
ItemRecord itemRecord = procedure.get(i);
|
||||
if (itemRecord.amount != 0) {
|
||||
builder.add(itemRecord.toItemStack());
|
||||
@@ -162,23 +162,23 @@ public class CostRecord{
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getInputStack(){
|
||||
public ImmutableList<ItemStack> getInputStack() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
if(itemRecord.amount != 0){
|
||||
for (ItemRecord itemRecord : input) {
|
||||
if (itemRecord.amount != 0) {
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getCatalystStack(){
|
||||
public ImmutableList<ItemStack> getCatalystStack() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
LOOP:
|
||||
for(ItemRecord itemRecord : catalyst){
|
||||
if(itemRecord.amount != 0){
|
||||
for(ItemRecord record : input){
|
||||
if(itemRecord.isSameType(record) && record.amount != 0){
|
||||
for (ItemRecord itemRecord : catalyst) {
|
||||
if (itemRecord.amount != 0) {
|
||||
for (ItemRecord record : input) {
|
||||
if (itemRecord.isSameType(record) && record.amount != 0) {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
@@ -198,10 +198,10 @@ public class CostRecord{
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : output) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).output) {
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
if (itemRecordExt.isSameType(itemRecordIn)) {
|
||||
if (itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
@@ -211,10 +211,10 @@ public class CostRecord{
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : input) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).input) {
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
if (itemRecordExt.isSameType(itemRecordIn)) {
|
||||
if (itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
@@ -224,10 +224,10 @@ public class CostRecord{
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).output) {
|
||||
for (ItemRecord itemRecordExt : output) {
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
if (itemRecordExt.isSameType(itemRecordIn)) {
|
||||
if (itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
@@ -237,10 +237,10 @@ public class CostRecord{
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).input) {
|
||||
for (ItemRecord itemRecordExt : input) {
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
if (itemRecordExt.isSameType(itemRecordIn)) {
|
||||
if (itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ItemRecord{
|
||||
public class ItemRecord {
|
||||
Item item;
|
||||
int meta;
|
||||
long amount;
|
||||
@@ -17,21 +17,21 @@ public class ItemRecord{
|
||||
/**
|
||||
* Generate ItemRecord based on the ItemStack and multiply the amount
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long multiplier){
|
||||
public ItemRecord(ItemStack itemStack, long multiplier) {
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getItemDamage();
|
||||
amount = ItemStackWrapper.getUnifiedAmount(itemStack) * multiplier;
|
||||
approx = itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("percentage");
|
||||
}
|
||||
|
||||
public ItemRecord(ItemStack itemStack){
|
||||
public ItemRecord(ItemStack itemStack) {
|
||||
this(itemStack, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate ItemRecord with customized amount
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long amount, boolean approx){
|
||||
public ItemRecord(ItemStack itemStack, long amount, boolean approx) {
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getItemDamage();
|
||||
this.amount = amount;
|
||||
@@ -50,62 +50,62 @@ public class ItemRecord{
|
||||
return "itemRecord:" + item.getUnlocalizedName() + " x " + amount;
|
||||
}
|
||||
|
||||
protected int getOutputAmount(Recipe recipe){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta){
|
||||
protected int getOutputAmount(Recipe recipe) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta) {
|
||||
return ItemStackWrapper.getUnifiedAmount(recipe.output[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isSameType(ItemRecord record){
|
||||
public boolean isSameType(ItemRecord record) {
|
||||
return item == record.item && meta == record.meta;
|
||||
}
|
||||
|
||||
public boolean add(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
public boolean add(ItemRecord record) {
|
||||
if (isSameType(record)) {
|
||||
amount += record.amount;
|
||||
approx = approx || record.approx;
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean minus(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
public boolean minus(ItemRecord record) {
|
||||
if (isSameType(record)) {
|
||||
amount -= record.amount;
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cancel(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
long i = amount>record.amount ? record.amount : amount;
|
||||
public boolean cancel(ItemRecord record) {
|
||||
if (isSameType(record)) {
|
||||
long i = amount > record.amount ? record.amount : amount;
|
||||
amount -= i;
|
||||
record.amount -= i;
|
||||
if(approx || record.approx){
|
||||
if (approx || record.approx) {
|
||||
approx = true;
|
||||
record.approx = true;
|
||||
}
|
||||
return i!=0;
|
||||
}else {
|
||||
return i != 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemRecord copy(){
|
||||
public ItemRecord copy() {
|
||||
return new ItemRecord(item, meta, amount, approx);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack(){
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack itemStack = new ItemStack(item, 1, meta);
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
tagCompound.setLong("amount", amount);
|
||||
if(approx){
|
||||
if (approx) {
|
||||
tagCompound.setBoolean("approx", true);
|
||||
}
|
||||
itemStack.setTagCompound(tagCompound);
|
||||
@@ -122,10 +122,10 @@ public class ItemRecord{
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ItemRecord){
|
||||
if (obj instanceof ItemRecord) {
|
||||
ItemRecord record = ((ItemRecord) obj);
|
||||
return record.approx == approx && record.item == item && record.amount == amount && record.meta == meta;
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,66 +9,69 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
*/
|
||||
public class ItemStackWrapper {
|
||||
|
||||
public static boolean isTypeEqual(ItemStack one, ItemStack two){
|
||||
return one != null && two != null && one.getItem() == two.getItem() && one.getItemDamage() == two.getItemDamage();
|
||||
public static boolean isTypeEqual(ItemStack one, ItemStack two) {
|
||||
return one != null && two != null && one.getItem() == two.getItem() &&
|
||||
one.getItemDamage() == two.getItemDamage();
|
||||
}
|
||||
|
||||
public static boolean isStackEqual(ItemStack one, ItemStack two){
|
||||
public static boolean isStackEqual(ItemStack one, ItemStack two) {
|
||||
return ItemStack.areItemStacksEqual(one, two);
|
||||
}
|
||||
|
||||
public static int getUnifiedAmount(ItemStack itemStack){
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
public static int getUnifiedAmount(ItemStack itemStack) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) {
|
||||
return itemStack.getTagCompound().getInteger("percentage");
|
||||
}else {
|
||||
return itemStack.stackSize*100;
|
||||
} else {
|
||||
return itemStack.stackSize * 100;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDisplayAmount(ItemStack itemStack){
|
||||
if(itemStack != null){
|
||||
if(itemStack.getTagCompound() != null){
|
||||
if(itemStack.getTagCompound().getBoolean("mark")){
|
||||
public static String getDisplayAmount(ItemStack itemStack) {
|
||||
if (itemStack != null) {
|
||||
if (itemStack.getTagCompound() != null) {
|
||||
if (itemStack.getTagCompound().getBoolean("mark")) {
|
||||
return "";
|
||||
}
|
||||
long l = itemStack.getTagCompound().hasKey("amount") ? itemStack.getTagCompound().getLong("amount") : -1;
|
||||
if(l == 0 && itemStack.stackSize == 0){
|
||||
long l = itemStack.getTagCompound().hasKey("amount") ?
|
||||
itemStack.getTagCompound().getLong("amount") :
|
||||
-1;
|
||||
if (l == 0 && itemStack.stackSize == 0) {
|
||||
return "";
|
||||
}
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i != 0){
|
||||
if (i != 0) {
|
||||
return i + "%";
|
||||
}else{
|
||||
if(l==-1){
|
||||
} else {
|
||||
if (l == -1) {
|
||||
return String.valueOf(itemStack.stackSize);
|
||||
}
|
||||
return getSimplifiedString((l+99)/100, itemStack.getTagCompound().getBoolean("approx"));
|
||||
return getSimplifiedString((l + 99) / 100, itemStack.getTagCompound().getBoolean("approx"));
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
return String.valueOf(itemStack.stackSize);
|
||||
}
|
||||
}
|
||||
else return "";
|
||||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
public static ItemStack toPercentage(ItemStack itemStack){
|
||||
if(itemStack == null){
|
||||
public static ItemStack toPercentage(ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
NBT.setInt(itemStack, "percentage", itemStack.stackSize*100);
|
||||
NBT.setInt(itemStack, "percentage", itemStack.stackSize * 100);
|
||||
itemStack.stackSize = 1;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack toNormal(ItemStack itemStack){
|
||||
if(itemStack == null){
|
||||
public static ItemStack toNormal(ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
if(itemStack.hasTagCompound()){
|
||||
if (itemStack.hasTagCompound()) {
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.stackSize = (i+99)/100;
|
||||
itemStack.stackSize = (i + 99) / 100;
|
||||
itemStack.setTagCompound(null);
|
||||
}else {
|
||||
} else {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
itemStack.setTagCompound(null);
|
||||
@@ -76,174 +79,175 @@ public class ItemStackWrapper {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static String getSimplifiedString(long l, boolean approx){
|
||||
public static String getSimplifiedString(long l, boolean approx) {
|
||||
String s;
|
||||
if(approx){
|
||||
if(l<999){
|
||||
if (approx) {
|
||||
if (l < 999) {
|
||||
s = String.valueOf(l);
|
||||
}else if(l<9999){
|
||||
s = String.format("≈%.1fK", (double)l/1000);
|
||||
}else if(l<99999){
|
||||
s = String.format("≈%.0fK", (double)l/1000);
|
||||
}else if(l<999999){
|
||||
s = String.format("≈%.1fM", (double)l/1000000);
|
||||
}else if(l<9999999){
|
||||
s = String.format("≈%.1fM", (double)l/1000000);
|
||||
}else if(l<99999999){
|
||||
s = String.format("≈%.0fM", (double)l/1000000);
|
||||
}else if(l<999999999){
|
||||
s = String.format("≈%.1fB", (double)l/1000000000);
|
||||
}else if(l<9999999999L){
|
||||
s = String.format("≈%.1fB", (double)l/1000000000);
|
||||
}else if(l<99999999999L){
|
||||
s = String.format("≈%.0fB", (double)l/1000000000);
|
||||
}else if(l<999999999999L){
|
||||
s = String.format("≈%.1fT", (double)l/1000000000000L);
|
||||
}else if(l<9999999999999L){
|
||||
s = String.format("≈%.1fT", (double)l/1000000000000L);
|
||||
}else if(l<99999999999999L){
|
||||
s = String.format("≈%.0fT", (double)l/1000000000000L);
|
||||
}else if(l<999999999999999L){
|
||||
s = String.format("≈%.1fG", (double)l/1000000000000000L);
|
||||
}else if(l<9999999999999999L){
|
||||
s = String.format("≈%.1fG", (double)l/1000000000000000L);
|
||||
}else {
|
||||
s = String.format("≈%.0fG", (double)l/1000000000000000L);
|
||||
} else if (l < 9999) {
|
||||
s = String.format("≈%.1fK", (double) l / 1000);
|
||||
} else if (l < 99999) {
|
||||
s = String.format("≈%.0fK", (double) l / 1000);
|
||||
} else if (l < 999999) {
|
||||
s = String.format("≈%.1fM", (double) l / 1000000);
|
||||
} else if (l < 9999999) {
|
||||
s = String.format("≈%.1fM", (double) l / 1000000);
|
||||
} else if (l < 99999999) {
|
||||
s = String.format("≈%.0fM", (double) l / 1000000);
|
||||
} else if (l < 999999999) {
|
||||
s = String.format("≈%.1fB", (double) l / 1000000000);
|
||||
} else if (l < 9999999999L) {
|
||||
s = String.format("≈%.1fB", (double) l / 1000000000);
|
||||
} else if (l < 99999999999L) {
|
||||
s = String.format("≈%.0fB", (double) l / 1000000000);
|
||||
} else if (l < 999999999999L) {
|
||||
s = String.format("≈%.1fT", (double) l / 1000000000000L);
|
||||
} else if (l < 9999999999999L) {
|
||||
s = String.format("≈%.1fT", (double) l / 1000000000000L);
|
||||
} else if (l < 99999999999999L) {
|
||||
s = String.format("≈%.0fT", (double) l / 1000000000000L);
|
||||
} else if (l < 999999999999999L) {
|
||||
s = String.format("≈%.1fG", (double) l / 1000000000000000L);
|
||||
} else if (l < 9999999999999999L) {
|
||||
s = String.format("≈%.1fG", (double) l / 1000000000000000L);
|
||||
} else {
|
||||
s = String.format("≈%.0fG", (double) l / 1000000000000000L);
|
||||
}
|
||||
}else {
|
||||
if(l<999){
|
||||
} else {
|
||||
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("%.0fB", (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("%.0fT", (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 if(l<999999999999999L){
|
||||
s = String.format("%.0fG", (double)l/1000000000000L);
|
||||
}else if(l<9999999999999999L){
|
||||
s = String.format("%.2fG", (double)l/1000000000000000L);
|
||||
}else if(l<99999999999990999L){
|
||||
s = String.format("%.1fG", (double)l/1000000000000000L);
|
||||
}else {
|
||||
s = String.format("%.0fG", (double)l/1000000000000000L);
|
||||
} 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("%.0fB", (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("%.0fT", (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 if (l < 999999999999999L) {
|
||||
s = String.format("%.0fG", (double) l / 1000000000000L);
|
||||
} else if (l < 9999999999999999L) {
|
||||
s = String.format("%.2fG", (double) l / 1000000000000000L);
|
||||
} else if (l < 99999999999990999L) {
|
||||
s = String.format("%.1fG", (double) l / 1000000000000000L);
|
||||
} else {
|
||||
s = String.format("%.0fG", (double) l / 1000000000000000L);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static long getGhostItemAmount(ItemStack itemStack){
|
||||
if (itemStack.hasTagCompound()){
|
||||
public static long getGhostItemAmount(ItemStack itemStack) {
|
||||
if (itemStack.hasTagCompound()) {
|
||||
long l = itemStack.getTagCompound().getLong("amount");
|
||||
return (l+99)/100;
|
||||
}else {
|
||||
return (l + 99) / 100;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NBT {
|
||||
public static void initNBT(ItemStack itemStack){
|
||||
if(!itemStack.hasTagCompound()){
|
||||
public static void initNBT(ItemStack itemStack) {
|
||||
if (!itemStack.hasTagCompound()) {
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setItem(ItemStack dest, String key, ItemStack content){
|
||||
public static void setItem(ItemStack dest, String key, ItemStack content) {
|
||||
initNBT(dest);
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
if (content != null){
|
||||
if (content != null) {
|
||||
content.writeToNBT(buffer);
|
||||
dest.getTagCompound().setTag(key, buffer);
|
||||
}else {
|
||||
} else {
|
||||
dest.getTagCompound().removeTag(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ItemStack getItem(ItemStack itemStack, String key){
|
||||
public static ItemStack getItem(ItemStack itemStack, String key) {
|
||||
NBTTagCompound tagCompound = itemStack.getTagCompound();
|
||||
if(tagCompound == null){
|
||||
if (tagCompound == null) {
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound itemTagCompound = tagCompound.getCompoundTag(key);
|
||||
if(itemTagCompound == null){
|
||||
if (itemTagCompound == null) {
|
||||
return null;
|
||||
}
|
||||
return ItemStack.loadItemStackFromNBT(itemTagCompound);
|
||||
}
|
||||
|
||||
public static void setString(ItemStack dest, String key, String value){
|
||||
public static void setString(ItemStack dest, String key, String value) {
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setString(key, value);
|
||||
}
|
||||
|
||||
public static void setInt(ItemStack dest, String key, int value){
|
||||
public static void setInt(ItemStack dest, String key, int value) {
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setInteger(key, value);
|
||||
}
|
||||
|
||||
public static void setBool(ItemStack dest, String key, boolean value){
|
||||
public static void setBool(ItemStack dest, String key, boolean value) {
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setBoolean(key, value);
|
||||
}
|
||||
|
||||
public static void setLong(ItemStack dest, String key, long value){
|
||||
public static void setLong(ItemStack dest, String key, long value) {
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setLong(key, value);
|
||||
}
|
||||
|
||||
public static String getString(ItemStack dest, String key){
|
||||
if(dest.getTagCompound() != null){
|
||||
public static String getString(ItemStack dest, String key) {
|
||||
if (dest.getTagCompound() != null) {
|
||||
return dest.getTagCompound().getString(key);
|
||||
}
|
||||
else return "";
|
||||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
public static boolean getBool(ItemStack dest, String key) {
|
||||
return dest.getTagCompound() != null && dest.getTagCompound().getBoolean(key);
|
||||
}
|
||||
|
||||
public static int getInt(ItemStack dest, String key){
|
||||
if(dest.getTagCompound() != null){
|
||||
public static int getInt(ItemStack dest, String key) {
|
||||
if (dest.getTagCompound() != null) {
|
||||
return dest.getTagCompound().getInteger(key);
|
||||
}
|
||||
else return 0;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static long getLong(ItemStack dest, String key){
|
||||
if(dest.getTagCompound() != null){
|
||||
public static long getLong(ItemStack dest, String key) {
|
||||
if (dest.getTagCompound() != null) {
|
||||
return dest.getTagCompound().getLong(key);
|
||||
}
|
||||
else return 0;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Click {
|
||||
public static boolean leftClick(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null || itemStack.stackSize>=64){
|
||||
public static boolean leftClick(ItemStack itemStack, boolean doChange) {
|
||||
if (itemStack == null || itemStack.stackSize >= 64) {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
itemStack.getTagCompound().setInteger("percentage", itemStack.getTagCompound().getInteger("percentage")+1);
|
||||
}else {
|
||||
} else {
|
||||
if (doChange) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) {
|
||||
itemStack.getTagCompound()
|
||||
.setInteger("percentage", itemStack.getTagCompound().getInteger("percentage") + 1);
|
||||
} else {
|
||||
itemStack.stackSize += 1;
|
||||
}
|
||||
}
|
||||
@@ -251,20 +255,20 @@ public class ItemStackWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean leftShift(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null || itemStack.stackSize>=64){
|
||||
public static boolean leftShift(ItemStack itemStack, boolean doChange) {
|
||||
if (itemStack == null || itemStack.stackSize >= 64) {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
} else {
|
||||
if (doChange) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) {
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i+10);
|
||||
}else {
|
||||
if(itemStack.stackSize == 1){
|
||||
itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i + 10);
|
||||
} else {
|
||||
if (itemStack.stackSize == 1) {
|
||||
itemStack.stackSize = 10;
|
||||
}else if(itemStack.stackSize <= 54){
|
||||
} else if (itemStack.stackSize <= 54) {
|
||||
itemStack.stackSize += 10;
|
||||
}else {
|
||||
} else {
|
||||
itemStack.stackSize = 64;
|
||||
}
|
||||
}
|
||||
@@ -273,19 +277,19 @@ public class ItemStackWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean rightClick(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null){
|
||||
public static boolean rightClick(ItemStack itemStack, boolean doChange) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
} else {
|
||||
if (doChange) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) {
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i == 1 || i == 0){
|
||||
if (i == 1 || i == 0) {
|
||||
itemStack.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
itemStack.getTagCompound().setInteger("percentage", --i);
|
||||
}else {
|
||||
} else {
|
||||
itemStack.stackSize -= 1;
|
||||
}
|
||||
}
|
||||
@@ -293,22 +297,22 @@ public class ItemStackWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean rightShift(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null){
|
||||
public static boolean rightShift(ItemStack itemStack, boolean doChange) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
} else {
|
||||
if (doChange) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")) {
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i == 0 || i == 1){
|
||||
if (i == 0 || i == 1) {
|
||||
itemStack.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
itemStack.getTagCompound().setInteger("percentage", i <= 10 ? 1 : i-10);
|
||||
}else {
|
||||
if(itemStack.stackSize == 1){
|
||||
itemStack.getTagCompound().setInteger("percentage", i <= 10 ? 1 : i - 10);
|
||||
} else {
|
||||
if (itemStack.stackSize == 1) {
|
||||
itemStack.stackSize = 0;
|
||||
}else if(itemStack.stackSize <= 10){
|
||||
} else if (itemStack.stackSize <= 10) {
|
||||
itemStack.stackSize = 1;
|
||||
} else {
|
||||
itemStack.stackSize -= 10;
|
||||
|
||||
@@ -14,13 +14,13 @@ public class Recipe {
|
||||
ItemStack[] input;
|
||||
|
||||
public Recipe(ItemStack[] output, ItemStack[] input) {
|
||||
if(output.length != 4 || input.length != 12){
|
||||
if (output.length != 4 || input.length != 12) {
|
||||
throw new IllegalArgumentException("Incorrect array size");
|
||||
}
|
||||
this.output = new ItemStack[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ItemStack itemstack = output[i];
|
||||
if(itemstack != null){
|
||||
if (itemstack != null) {
|
||||
boolean flag = false;
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (this.output[j] != null && ItemStackWrapper.isTypeEqual(this.output[j], itemstack)) {
|
||||
@@ -36,12 +36,12 @@ public class Recipe {
|
||||
}
|
||||
this.input = new ItemStack[12];
|
||||
for (ItemStack itemstack : input) {
|
||||
if(itemstack != null){
|
||||
for(int i=0; i<12; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(this.input[i], itemstack)){
|
||||
if (itemstack != null) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (ItemStackWrapper.isTypeEqual(this.input[i], itemstack)) {
|
||||
this.input[i].stackSize += itemstack.stackSize;
|
||||
break;
|
||||
} else if (this.input[i] == null){
|
||||
} else if (this.input[i] == null) {
|
||||
this.input[i] = itemstack.copy();
|
||||
break;
|
||||
}
|
||||
@@ -50,20 +50,21 @@ public class Recipe {
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getOutput(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
public ItemStack getOutput(ItemStack itemStack) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (ItemStackWrapper.isTypeEqual(output[i], itemStack)) {
|
||||
return output[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getOutputIndex(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
for(ItemStack buffer : input){
|
||||
if(ItemStackWrapper.isTypeEqual(buffer, output[i]) && ItemStackWrapper.getUnifiedAmount(output[i])<ItemStackWrapper.getUnifiedAmount(buffer)){
|
||||
public int getOutputIndex(ItemStack itemStack) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (ItemStackWrapper.isTypeEqual(output[i], itemStack)) {
|
||||
for (ItemStack buffer : input) {
|
||||
if (ItemStackWrapper.isTypeEqual(buffer, output[i]) &&
|
||||
ItemStackWrapper.getUnifiedAmount(output[i]) < ItemStackWrapper.getUnifiedAmount(buffer)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -73,148 +74,148 @@ public class Recipe {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getExactInputIndex(ItemStack itemStack){
|
||||
for(int i = 0; i<12; i++){
|
||||
if(ItemStackWrapper.isStackEqual(input[i], itemStack)){
|
||||
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)){
|
||||
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){
|
||||
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)){
|
||||
public int getOutputAmount(ItemStack itemStack) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (ItemStackWrapper.isTypeEqual(output[i], itemStack)) {
|
||||
return ItemStackWrapper.getUnifiedAmount(output[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getInputAmount(ItemStack itemStack){
|
||||
for(int i = 0; i<12; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(input[i], itemStack)){
|
||||
public int getInputAmount(ItemStack itemStack) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (ItemStackWrapper.isTypeEqual(input[i], itemStack)) {
|
||||
return ItemStackWrapper.getUnifiedAmount(input[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getHasOutput(ItemStack itemStack){
|
||||
public boolean getHasOutput(ItemStack itemStack) {
|
||||
return getOutputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
public boolean getHasInput(ItemStack itemStack){
|
||||
public boolean getHasInput(ItemStack itemStack) {
|
||||
return getInputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Recipe){
|
||||
for(int i=0; i<4; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(output[i], ((Recipe)obj).output[i])){
|
||||
if (obj instanceof Recipe) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!ItemStackWrapper.isStackEqual(output[i], ((Recipe) obj).output[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(input[i], ((Recipe)obj).input[i])){
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (!ItemStackWrapper.isStackEqual(input[i], ((Recipe) obj).input[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutputEqual(Recipe recipe){
|
||||
for(int i=0; i<4; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(output[i], recipe.output[i])){
|
||||
public boolean isOutputEqual(Recipe recipe) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!ItemStackWrapper.isStackEqual(output[i], recipe.output[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getOutput(){
|
||||
public ImmutableList<ItemStack> getOutput() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemStack itemStack : output){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : output) {
|
||||
if (itemStack != null) {
|
||||
builder.add(itemStack.copy());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getInput(){
|
||||
public ImmutableList<ItemStack> getInput() {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemStack itemStack : input){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : input) {
|
||||
if (itemStack != null) {
|
||||
builder.add(itemStack.copy());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public boolean isApprox(){
|
||||
for(ItemStack itemstack : input){
|
||||
if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){
|
||||
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")){
|
||||
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){
|
||||
public static class ByteBufUtl {
|
||||
public static Recipe fromByte(ByteBuf buf) {
|
||||
short a = buf.readShort();
|
||||
if(a == 0){
|
||||
if (a == 0) {
|
||||
return null;
|
||||
}
|
||||
short b = buf.readShort();
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=0; i<a; i++){
|
||||
for (int i = 0; i < a; i++) {
|
||||
output[i] = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
for(int i=0; i<b; i++){
|
||||
for (int i = 0; i < b; i++) {
|
||||
input[i] = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
return new Recipe(output, input);
|
||||
}
|
||||
|
||||
public static void toByte(ByteBuf buf, Recipe recipe){
|
||||
if(recipe == null){
|
||||
public static void toByte(ByteBuf buf, Recipe recipe) {
|
||||
if (recipe == null) {
|
||||
buf.writeShort(0);
|
||||
return;
|
||||
}
|
||||
short a = 0;
|
||||
short b = 0;
|
||||
for(ItemStack itemStack : recipe.output){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : recipe.output) {
|
||||
if (itemStack != null) {
|
||||
a++;
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
for (ItemStack itemStack : recipe.input) {
|
||||
if (itemStack != null) {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
@@ -222,58 +223,58 @@ public class Recipe {
|
||||
buf.writeShort(b);
|
||||
ItemStack[] output1 = recipe.output;
|
||||
for (ItemStack itemStack : output1) {
|
||||
if(itemStack != null){
|
||||
if (itemStack != null) {
|
||||
ByteBufUtils.writeItemStack(buf, itemStack);
|
||||
}
|
||||
}
|
||||
ItemStack[] input1 = recipe.input;
|
||||
for (ItemStack itemStack : input1) {
|
||||
if(itemStack != null){
|
||||
if (itemStack != null) {
|
||||
ByteBufUtils.writeItemStack(buf, itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class NBTUtl{
|
||||
public static NBTTagCompound toNBT(Recipe recipe){
|
||||
public static class NBTUtl {
|
||||
public static NBTTagCompound toNBT(Recipe recipe) {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
for(int i=0; i<4; i++){
|
||||
if(recipe.output[i] != null){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (recipe.output[i] != null) {
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
recipe.output[i].writeToNBT(buffer);
|
||||
tagCompound.setTag(i+"", buffer);
|
||||
tagCompound.setTag(i + "", buffer);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
if(recipe.input[i] != null){
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (recipe.input[i] != null) {
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
recipe.input[i].writeToNBT(buffer);
|
||||
tagCompound.setTag((i+4)+"", buffer);
|
||||
tagCompound.setTag((i + 4) + "", buffer);
|
||||
}
|
||||
}
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public static Recipe fromNBT (NBTTagCompound tagCompound){
|
||||
public static Recipe fromNBT(NBTTagCompound tagCompound) {
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
boolean inputNull = true;
|
||||
boolean outputNull = true;
|
||||
for(int i=0; i<4; i++){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i));
|
||||
if(buffer != null){
|
||||
if (buffer != null) {
|
||||
output[i] = ItemStack.loadItemStackFromNBT(buffer);
|
||||
if(output[i] != null){
|
||||
if (output[i] != null) {
|
||||
outputNull = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i+4));
|
||||
if(buffer != null){
|
||||
for (int i = 0; i < 12; i++) {
|
||||
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i + 4));
|
||||
if (buffer != null) {
|
||||
input[i] = ItemStack.loadItemStackFromNBT(buffer);
|
||||
if(input[i]!= null){
|
||||
if (input[i] != null) {
|
||||
inputNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GuiEventHandler {
|
||||
long time = new Date().getTime();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onMouseClick(InputEvent.MouseInputEvent event){
|
||||
public void onMouseClick(InputEvent.MouseInputEvent event) {
|
||||
/*if(event.gui instanceof GuiRecipeEditor){
|
||||
if(new Date().getTime() - time < 200){
|
||||
event.setCanceled(true);
|
||||
@@ -89,8 +89,8 @@ public class GuiEventHandler {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onOpen(GuiOpenEvent event){
|
||||
if(event.gui instanceof GuiCalculator){
|
||||
public void onOpen(GuiOpenEvent event) {
|
||||
if (event.gui instanceof GuiCalculator) {
|
||||
((GuiCalculator) event.gui).onOpen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,27 +4,30 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.guis.calculator.ContainerCalculator;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.*;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onLogin(LoadFromFile event){
|
||||
public void onLogin(LoadFromFile event) {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().handleLogin(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSave(SaveToFile event){
|
||||
public void onSave(SaveToFile event) {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().handleSave(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTooltip(ItemTooltipEvent event){
|
||||
if(event.entityPlayer.openContainer instanceof ContainerCalculator){
|
||||
long l = event.itemStack.hasTagCompound() ? (event.itemStack.getTagCompound().getLong("amount")+99)/100 : 0;
|
||||
if(l > 999){
|
||||
public void onTooltip(ItemTooltipEvent event) {
|
||||
if (event.entityPlayer.openContainer instanceof ContainerCalculator) {
|
||||
long l = event.itemStack.hasTagCompound() ?
|
||||
(event.itemStack.getTagCompound().getLong("amount") + 99) / 100 :
|
||||
0;
|
||||
if (l > 999) {
|
||||
event.toolTip.add("Amount: " + l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,23 @@ package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.guis.calculator.ContainerCalculator;
|
||||
import me.towdium.jecalculation.gui.guis.calculator.GuiCalculator;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
public static final class GuiId{
|
||||
public static final class GuiId {
|
||||
public static final int CALCULATOR = 0;
|
||||
public static final int RECIPE_VIEWER = 1;
|
||||
public static final int RECIPE_EDITOR = 2;
|
||||
@@ -33,10 +33,15 @@ public class GuiHandler implements IGuiHandler {
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
switch (ID) {
|
||||
case GuiId.CALCULATOR: return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem()));
|
||||
case GuiId.RECIPE_VIEWER: return new GuiRecipeViewer(new ContainerRecipeViewer(), null);
|
||||
case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor(), null);
|
||||
case GuiId.RECIPE_PICKER: return new GuiRecipePicker(new ContainerRecipe(), null, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null));
|
||||
case GuiId.CALCULATOR:
|
||||
return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem()));
|
||||
case GuiId.RECIPE_VIEWER:
|
||||
return new GuiRecipeViewer(new ContainerRecipeViewer(), null);
|
||||
case GuiId.RECIPE_EDITOR:
|
||||
return new GuiRecipeEditor(new ContainerRecipeEditor(), null);
|
||||
case GuiId.RECIPE_PICKER:
|
||||
return new GuiRecipePicker(new ContainerRecipe(), null,
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.towdium.jecalculation.gui.commom;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -10,7 +11,6 @@ import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -22,15 +22,22 @@ import java.lang.reflect.Method;
|
||||
*/
|
||||
public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
protected GuiScreen parent;
|
||||
protected RenderItem renderItem = new RenderItem(){
|
||||
protected RenderItem renderItem = new RenderItem() {
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer p_77021_1_, TextureManager p_77021_2_, ItemStack p_77021_3_, int p_77021_4_, int p_77021_5_, String text) {
|
||||
if(p_77021_3_!=null && p_77021_3_.hasTagCompound() && p_77021_3_.getTagCompound().getBoolean("jecalculation")){
|
||||
public void renderItemOverlayIntoGUI(FontRenderer p_77021_1_,
|
||||
TextureManager p_77021_2_,
|
||||
ItemStack p_77021_3_,
|
||||
int p_77021_4_,
|
||||
int p_77021_5_,
|
||||
String text) {
|
||||
if (p_77021_3_ != null && p_77021_3_.hasTagCompound() &&
|
||||
p_77021_3_.getTagCompound().getBoolean("jecalculation")) {
|
||||
boolean b = p_77021_1_.getUnicodeFlag();
|
||||
p_77021_1_.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, ItemStackWrapper.getDisplayAmount(p_77021_3_));
|
||||
super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_,
|
||||
ItemStackWrapper.getDisplayAmount(p_77021_3_));
|
||||
p_77021_1_.setUnicodeFlag(b);
|
||||
}else {
|
||||
} else {
|
||||
super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, text);
|
||||
}
|
||||
|
||||
@@ -51,13 +58,13 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int mouseButton){
|
||||
public void click(int mouseX, int mouseY, int mouseButton) {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
public void click(int index){
|
||||
for(Object button : buttonList){
|
||||
if(((GuiButton) button).id == index){
|
||||
public void click(int index) {
|
||||
for (Object button : buttonList) {
|
||||
if (((GuiButton) button).id == index) {
|
||||
actionPerformed(((GuiButton) button));
|
||||
}
|
||||
}
|
||||
@@ -67,11 +74,12 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public void updateLayout(){}
|
||||
public void updateLayout() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode){
|
||||
if(keyCode == 1){
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (keyCode == 1) {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +87,7 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
@Override
|
||||
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
|
||||
RenderItem buffer1 = itemRender;
|
||||
RenderItem buffer2 = GuiContainerManager.drawItems;
|
||||
RenderItem buffer2 = GuiContainerManager.drawItems;
|
||||
itemRender = renderItem;
|
||||
GuiContainerManager.drawItems = renderItem;
|
||||
super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
|
||||
@@ -87,14 +95,15 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
GuiContainerManager.drawItems = buffer2;
|
||||
}
|
||||
|
||||
protected Slot getSlotUnderMouse(int x, int y){
|
||||
protected Slot getSlotUnderMouse(int x, int y) {
|
||||
Method getSlot = null;
|
||||
try {
|
||||
getSlot = GuiContainer.class.getDeclaredMethod("getSlotAtPosition", int.class, int.class);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
try {
|
||||
getSlot = GuiContainer.class.getDeclaredMethod("func_146975_c", int.class, int.class);
|
||||
} catch (NoSuchMethodException ignored_) {}
|
||||
} catch (NoSuchMethodException ignored_) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
getSlot.setAccessible(true);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package me.towdium.jecalculation.gui.commom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
@@ -16,29 +13,40 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CODE IS DONE BY Zyin055
|
||||
* A GuiScreen replacement that supports putting tooltips onto GuiButtons.
|
||||
* SEE HERE: www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437428-guide-1-7-2-how-to-make-button-tooltips
|
||||
*/
|
||||
public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler
|
||||
{
|
||||
public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler {
|
||||
int mousedOverButtonId = -1;
|
||||
|
||||
/** Show a white "?" in the top right part of any button with a tooltip assigned to it */
|
||||
/**
|
||||
* Show a white "?" in the top right part of any button with a tooltip assigned to it
|
||||
*/
|
||||
public static boolean ShowTooltipButtonEffect = true;
|
||||
|
||||
/** Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered */
|
||||
/**
|
||||
* Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered
|
||||
*/
|
||||
public static boolean ShowTooltipButtonMouseoverEffect = true;
|
||||
|
||||
/** Putting this string into a tooltip will cause a line break */
|
||||
/**
|
||||
* Putting this string into a tooltip will cause a line break
|
||||
*/
|
||||
public String tooltipNewlineDelimeter = "_p";
|
||||
|
||||
/** The amount of time in milliseconds until a tooltip is rendered */
|
||||
/**
|
||||
* The amount of time in milliseconds until a tooltip is rendered
|
||||
*/
|
||||
public long tooltipDelay = 900;
|
||||
|
||||
/** The maximum width in pixels a tooltip can occupy before word wrapping occurs */
|
||||
/**
|
||||
* The maximum width in pixels a tooltip can occupy before word wrapping occurs
|
||||
*/
|
||||
public int tooltipMaxWidth = 150;
|
||||
|
||||
protected int tooltipXOffset = 0;
|
||||
@@ -56,18 +64,17 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
|
||||
if(ShowTooltipButtonEffect)
|
||||
if (ShowTooltipButtonEffect)
|
||||
RenderTooltipButtonEffect();
|
||||
if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
|
||||
for(Object button : buttonList){
|
||||
if(((GuiButton) button).id == mousedOverButtonId){
|
||||
for (Object button : buttonList) {
|
||||
if (((GuiButton) button).id == mousedOverButtonId) {
|
||||
RenderTooltipButtonMouseoverEffect(((GuiButton) button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float f)
|
||||
{
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
for (Object button : buttonList) {
|
||||
if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) {
|
||||
mousedOverButtonId = ((GuiButton) button).id;
|
||||
@@ -110,45 +117,38 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
/**
|
||||
* This method must be overriden. Gets a tooltip String for a specific button.
|
||||
* Recommended to use a switch/case statement for buttonId for easy implementation.
|
||||
*
|
||||
* @param buttonId The ID of the button this tooltip corresponds to
|
||||
* @return The tooltip string for the specified buttonId. null if no tooltip exists for this button.
|
||||
*/
|
||||
protected abstract String GetButtonTooltip(int buttonId);
|
||||
|
||||
/**
|
||||
* Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons
|
||||
* Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons
|
||||
* that are being mouseovered.
|
||||
*/
|
||||
protected void DrawTooltipScreen(int mouseX, int mouseY)
|
||||
{
|
||||
|
||||
|
||||
protected void DrawTooltipScreen(int mouseX, int mouseY) {
|
||||
|
||||
|
||||
//find out which button is being mouseovered
|
||||
|
||||
|
||||
//calculate how long this button has been mouseovered for
|
||||
if(mousedOverButtonId > -1)
|
||||
{
|
||||
if (mousedOverButtonId > -1) {
|
||||
long systemTime = System.currentTimeMillis();
|
||||
|
||||
if(prevSystemTime > 0)
|
||||
if (prevSystemTime > 0)
|
||||
mouseoverTime += systemTime - prevSystemTime;
|
||||
|
||||
prevSystemTime = systemTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mouseoverTime = 0;
|
||||
}
|
||||
|
||||
//render the button's tooltip
|
||||
if(mouseoverTime > tooltipDelay)
|
||||
{
|
||||
if (mouseoverTime > tooltipDelay) {
|
||||
String tooltip = GetButtonTooltip(mousedOverButtonId);
|
||||
if(tooltip != null)
|
||||
{
|
||||
if (tooltip != null) {
|
||||
RenderTooltip(mouseX, mouseY, tooltip);
|
||||
}
|
||||
}
|
||||
@@ -156,26 +156,27 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
|
||||
/**
|
||||
* Determines if a GuiButton is being mouseovered.
|
||||
*
|
||||
* @return true if this button is mouseovered
|
||||
*/
|
||||
private boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button)
|
||||
{
|
||||
return mouseX >= button.xPosition + button.getButtonWidth() - 10 && mouseX <= button.xPosition + button.getButtonWidth() &&
|
||||
mouseY >= button.yPosition && mouseY <= button.yPosition + 10;
|
||||
private boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button) {
|
||||
return mouseX >= button.xPosition + button.getButtonWidth() - 10 &&
|
||||
mouseX <= button.xPosition + button.getButtonWidth() && mouseY >= button.yPosition &&
|
||||
mouseY <= button.yPosition + 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render anything special onto all buttons that have tooltips assigned to them.
|
||||
*/
|
||||
private void RenderTooltipButtonEffect()
|
||||
{
|
||||
private void RenderTooltipButtonEffect() {
|
||||
for (Object buttonObj : buttonList) {
|
||||
GuiButton button = ((GuiButton) buttonObj);
|
||||
if (GetButtonTooltip(button.id) != null) {
|
||||
|
||||
boolean flag = fontRendererObj.getUnicodeFlag();
|
||||
fontRendererObj.setUnicodeFlag(true);
|
||||
fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 -guiLeft, button.yPosition + 1 - guiTop, 14737632);
|
||||
fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 - guiLeft,
|
||||
button.yPosition + 1 - guiTop, 14737632);
|
||||
fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
}
|
||||
@@ -184,36 +185,35 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
/**
|
||||
* Render anything special onto buttons that have tooltips assigned to them when they are mousevered.
|
||||
*/
|
||||
private void RenderTooltipButtonMouseoverEffect(GuiButton button)
|
||||
{
|
||||
private void RenderTooltipButtonMouseoverEffect(GuiButton button) {
|
||||
boolean flag = fontRendererObj.getUnicodeFlag();
|
||||
fontRendererObj.setUnicodeFlag(true);
|
||||
fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7 - guiLeft, button.yPosition+1 - guiTop, 14737632);
|
||||
fontRendererObj
|
||||
.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition + button.getButtonWidth() - 7 - guiLeft,
|
||||
button.yPosition + 1 - guiTop, 14737632);
|
||||
fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a tooltip at (x,y).
|
||||
*/
|
||||
private void RenderTooltip(int x, int y, String tooltip)
|
||||
{
|
||||
private void RenderTooltip(int x, int y, String tooltip) {
|
||||
String[] tooltipArray = ParseTooltipArrayFromString(tooltip);
|
||||
this.drawHoveringText(ImmutableList.copyOf(tooltipArray), x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String representation of a tooltip into a String[], and also decodes any font codes used.
|
||||
*
|
||||
* @param s Ex: "Hello,_nI am your _ltooltip_r and you love me."
|
||||
* @return An array of Strings such that each String width does not exceed tooltipMaxWidth
|
||||
*/
|
||||
private String[] ParseTooltipArrayFromString(String s)
|
||||
{
|
||||
private String[] ParseTooltipArrayFromString(String s) {
|
||||
s = DecodeStringCodes(s);
|
||||
String[] tooltipSections = s.split(tooltipNewlineDelimeter);
|
||||
ArrayList<String> tooltipArrayList = new ArrayList();
|
||||
|
||||
for(String section : tooltipSections)
|
||||
{
|
||||
for (String section : tooltipSections) {
|
||||
String tooltip = "";
|
||||
String[] tooltipWords = section.split(" ");
|
||||
|
||||
@@ -238,45 +238,29 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
|
||||
/**
|
||||
* Decodes any font codes into something useable by the fontRendererObj.
|
||||
*
|
||||
* @param s E.x.: "Hello,_nI am your _ltooltip_r and you love me."
|
||||
* @return E.x. output (html not included): <br>"Hello,<br>I am your <b>tooltip</b> and you love me."
|
||||
*/
|
||||
private String DecodeStringCodes(String s)
|
||||
{
|
||||
return s.replace("_0", FontCodes.BLACK)
|
||||
.replace("_1", FontCodes.DARK_BLUE)
|
||||
.replace("_2", FontCodes.DARK_GREEN)
|
||||
.replace("_3", FontCodes.DARK_AQUA)
|
||||
.replace("_4", FontCodes.DARK_RED)
|
||||
.replace("_5", FontCodes.DARK_PURPLE)
|
||||
.replace("_6", FontCodes.GOLD)
|
||||
.replace("_7", FontCodes.GRAY)
|
||||
.replace("_8", FontCodes.DARK_GREY)
|
||||
.replace("_9", FontCodes.BLUE)
|
||||
.replace("_a", FontCodes.GREEN)
|
||||
.replace("_b", FontCodes.AQUA)
|
||||
.replace("_c", FontCodes.RED)
|
||||
.replace("_d", FontCodes.LIGHT_PURPLE)
|
||||
.replace("_e", FontCodes.YELLOW)
|
||||
.replace("_f", FontCodes.WHITE)
|
||||
.replace("_k", FontCodes.OBFUSCATED)
|
||||
.replace("_l", FontCodes.BOLD)
|
||||
.replace("_m", FontCodes.STRIKETHROUGH)
|
||||
.replace("_n", FontCodes.UNDERLINE)
|
||||
.replace("_o", FontCodes.ITALICS)
|
||||
.replace("_r", FontCodes.RESET);
|
||||
private String DecodeStringCodes(String s) {
|
||||
return s.replace("_0", FontCodes.BLACK).replace("_1", FontCodes.DARK_BLUE).replace("_2", FontCodes.DARK_GREEN)
|
||||
.replace("_3", FontCodes.DARK_AQUA).replace("_4", FontCodes.DARK_RED)
|
||||
.replace("_5", FontCodes.DARK_PURPLE).replace("_6", FontCodes.GOLD).replace("_7", FontCodes.GRAY)
|
||||
.replace("_8", FontCodes.DARK_GREY).replace("_9", FontCodes.BLUE).replace("_a", FontCodes.GREEN)
|
||||
.replace("_b", FontCodes.AQUA).replace("_c", FontCodes.RED).replace("_d", FontCodes.LIGHT_PURPLE)
|
||||
.replace("_e", FontCodes.YELLOW).replace("_f", FontCodes.WHITE).replace("_k", FontCodes.OBFUSCATED)
|
||||
.replace("_l", FontCodes.BOLD).replace("_m", FontCodes.STRIKETHROUGH).replace("_n", FontCodes.UNDERLINE)
|
||||
.replace("_o", FontCodes.ITALICS).replace("_r", FontCodes.RESET);
|
||||
}
|
||||
|
||||
/***
|
||||
* Gets the width of the tooltip in pixels.
|
||||
*/
|
||||
private int GetTooltipWidth(String[] tooltipArray)
|
||||
{
|
||||
private int GetTooltipWidth(String[] tooltipArray) {
|
||||
int longestWidth = 0;
|
||||
for(String s : tooltipArray)
|
||||
{
|
||||
for (String s : tooltipArray) {
|
||||
int width = mc.fontRenderer.getStringWidth(s);
|
||||
if(width > longestWidth)
|
||||
if (width > longestWidth)
|
||||
longestWidth = width;
|
||||
}
|
||||
return longestWidth;
|
||||
@@ -285,11 +269,9 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
/**
|
||||
* Gets the height of the tooltip in pixels.
|
||||
*/
|
||||
private int GetTooltipHeight(String[] tooltipArray)
|
||||
{
|
||||
private int GetTooltipHeight(String[] tooltipArray) {
|
||||
int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2;
|
||||
if (tooltipArray.length > 1)
|
||||
{
|
||||
if (tooltipArray.length > 1) {
|
||||
tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
|
||||
}
|
||||
return tooltipHeight;
|
||||
@@ -312,7 +294,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) {
|
||||
itemStack.stackSize=0;
|
||||
itemStack.stackSize = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,8 +304,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
}
|
||||
|
||||
|
||||
public class FontCodes
|
||||
{
|
||||
public class FontCodes {
|
||||
//color codes for rendered strings
|
||||
public static final String BLACK = "\2470";
|
||||
public static final String DARK_BLUE = "\2471";
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.towdium.jecalculation.gui.commom.recipe;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,26 +14,30 @@ import me.towdium.jecalculation.core.Recipe;
|
||||
*/
|
||||
public class ContainerRecipe extends Container {
|
||||
|
||||
public ContainerRecipe(){
|
||||
public ContainerRecipe() {
|
||||
InventoryRecipe inventoryRecipe = new InventoryRecipe();
|
||||
int i, left, top;
|
||||
i = 0; left = 9; top = 9;
|
||||
for(int a = 0; a < 2; a++){
|
||||
for(int b =0; b < 2; b++){
|
||||
addSlotToContainer(new Slot(inventoryRecipe,i+2*a+b,left+b*59,top+a*24));
|
||||
i = 0;
|
||||
left = 9;
|
||||
top = 9;
|
||||
for (int a = 0; a < 2; a++) {
|
||||
for (int b = 0; b < 2; b++) {
|
||||
addSlotToContainer(new Slot(inventoryRecipe, i + 2 * a + b, left + b * 59, top + a * 24));
|
||||
}
|
||||
}
|
||||
i = 4; left = 9; top = 69;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 3; b++){
|
||||
addSlotToContainer(new Slot(inventoryRecipe,i+3*a+b,left+b*59,top+a*24));
|
||||
i = 4;
|
||||
left = 9;
|
||||
top = 69;
|
||||
for (int a = 0; a < 4; a++) {
|
||||
for (int b = 0; b < 3; b++) {
|
||||
addSlotToContainer(new Slot(inventoryRecipe, i + 3 * a + b, left + b * 59, top + a * 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 15)
|
||||
if (p_75139_1_ <= 15)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
@@ -46,20 +50,20 @@ public class ContainerRecipe extends Container {
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
if(slotId<0 || slotId>=16){
|
||||
if (slotId < 0 || slotId >= 16) {
|
||||
return null;
|
||||
}
|
||||
Slot slot = getSlot(slotId);
|
||||
if(slot != null){
|
||||
if (slot != null) {
|
||||
ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex());
|
||||
if(itemStack != null){
|
||||
if(clickedButton == 0 && mode == 0){
|
||||
if (itemStack != null) {
|
||||
if (clickedButton == 0 && mode == 0) {
|
||||
ItemStackWrapper.Click.leftClick(slot.getStack(), true);
|
||||
}else if(clickedButton == 0 && mode == 1){
|
||||
} else if (clickedButton == 0 && mode == 1) {
|
||||
ItemStackWrapper.Click.leftShift(slot.getStack(), true);
|
||||
}else if(clickedButton == 1 && mode == 0){
|
||||
} else if (clickedButton == 1 && mode == 0) {
|
||||
ItemStackWrapper.Click.rightClick(slot.getStack(), true);
|
||||
}else if(clickedButton == 1 && mode == 1){
|
||||
} else if (clickedButton == 1 && mode == 1) {
|
||||
ItemStackWrapper.Click.rightShift(slot.getStack(), true);
|
||||
}
|
||||
slot.putStack(itemStack.stackSize == 0 ? null : itemStack);
|
||||
@@ -78,33 +82,33 @@ public class ContainerRecipe extends Container {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Recipe buildRecipe(){
|
||||
public Recipe buildRecipe() {
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
boolean flag1 = false, flag2 = false;
|
||||
for(int i=0; i<4; i++){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ItemStack buffer = getSlot(i).getStack();
|
||||
if(buffer != null && buffer.hasTagCompound()){
|
||||
if (buffer != null && buffer.hasTagCompound()) {
|
||||
buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
if(buffer.getTagCompound().hasNoTags()){
|
||||
if (buffer.getTagCompound().hasNoTags()) {
|
||||
buffer.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
output[i] = buffer;
|
||||
if(output[i] != null){
|
||||
if (output[i] != null) {
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=4; i<16; i++){
|
||||
for (int i = 4; i < 16; i++) {
|
||||
ItemStack buffer = getSlot(i).getStack();
|
||||
if(buffer != null && buffer.hasTagCompound()){
|
||||
if (buffer != null && buffer.hasTagCompound()) {
|
||||
buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
if(buffer.getTagCompound().hasNoTags()){
|
||||
if (buffer.getTagCompound().hasNoTags()) {
|
||||
buffer.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
input[i-4] = buffer;
|
||||
if(input[i-4] != null){
|
||||
input[i - 4] = buffer;
|
||||
if (input[i - 4] != null) {
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.towdium.jecalculation.gui.commom.recipe;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import me.towdium.jecalculation.gui.commom.GuiTooltipScreen;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -11,7 +12,6 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -31,39 +31,45 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int i, left, top;
|
||||
i = 0; left = 31 + guiLeft; top = 7 + guiTop;
|
||||
for(int a = 0; a < 2; a++){
|
||||
for(int b =0; b < 2; b++){
|
||||
buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "#"));
|
||||
i = 0;
|
||||
left = 31 + guiLeft;
|
||||
top = 7 + guiTop;
|
||||
for (int a = 0; a < 2; a++) {
|
||||
for (int b = 0; b < 2; b++) {
|
||||
buttonList.add(new GuiButton(i + 2 * a + b, left + b * 59, top + a * 24, 20, 20, "#"));
|
||||
}
|
||||
}
|
||||
i = 4; left = 31 + guiLeft; top = 67 + guiTop;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 3; b++){
|
||||
buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "#"));
|
||||
i = 4;
|
||||
left = 31 + guiLeft;
|
||||
top = 67 + guiTop;
|
||||
for (int a = 0; a < 4; a++) {
|
||||
for (int b = 0; b < 3; b++) {
|
||||
buttonList.add(new GuiButton(i + 3 * a + b, left + b * 59, top + a * 24, 20, 20, "#"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipe.png"));
|
||||
this.mc.getTextureManager()
|
||||
.bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipe.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
if(activeSlot != -1){
|
||||
if (activeSlot != -1) {
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
|
||||
this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 2,
|
||||
this.guiTop + slot.yDisplayPosition - 2, 176, 0, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
int buttonId = button.id;
|
||||
if(buttonId <= 15){
|
||||
if (buttonId <= 15) {
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
if(button.displayString.equals("#")){
|
||||
if (button.displayString.equals("#")) {
|
||||
slot.putStack(ItemStackWrapper.toPercentage(slot.getStack()));
|
||||
button.displayString = "%";
|
||||
}else {
|
||||
} else {
|
||||
slot.putStack(ItemStackWrapper.toNormal(slot.getStack()));
|
||||
button.displayString = "#";
|
||||
}
|
||||
@@ -93,9 +99,9 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (keyCode == 1) {
|
||||
if(activeSlot != -1){
|
||||
if (activeSlot != -1) {
|
||||
setActiveSlot(-1);
|
||||
}else {
|
||||
} else {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
@@ -104,11 +110,11 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
boolean b = false;
|
||||
if(slotIn != null){
|
||||
if (slotIn != null) {
|
||||
b = slotIn.getHasStack();
|
||||
}
|
||||
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
|
||||
if(slotIn != null && b && !slotIn.getHasStack()){
|
||||
if (slotIn != null && b && !slotIn.getHasStack()) {
|
||||
((GuiButton) buttonList.get(slotIn.getSlotIndex())).displayString = "#";
|
||||
}
|
||||
}
|
||||
@@ -121,40 +127,40 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
this.activeSlot = activeSlot;
|
||||
}
|
||||
|
||||
public void displayRecipe(Recipe recipe){
|
||||
public void displayRecipe(Recipe recipe) {
|
||||
List<ItemStack> output = recipe.getOutput();
|
||||
List<ItemStack> input = recipe.getInput();
|
||||
for(int i=0; i<4; i++){
|
||||
if(i<output.size()){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < output.size()) {
|
||||
ItemStack itemStack = output.get(i);
|
||||
this.inventorySlots.getSlot(i).putStack(itemStack);
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
if(itemStack.getTagCompound().hasKey("percentage")){
|
||||
if (itemStack.getTagCompound().hasKey("percentage")) {
|
||||
((GuiButton) buttonList.get(i)).displayString = "%";
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
this.inventorySlots.getSlot(i).putStack(null);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
if(i<input.size()){
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (i < input.size()) {
|
||||
ItemStack itemStack = input.get(i);
|
||||
this.inventorySlots.getSlot(i+4).putStack(itemStack);
|
||||
this.inventorySlots.getSlot(i + 4).putStack(itemStack);
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
if(itemStack.getTagCompound().hasKey("percentage")){
|
||||
if (itemStack.getTagCompound().hasKey("percentage")) {
|
||||
((GuiButton) buttonList.get(i + 4)).displayString = "%";
|
||||
}
|
||||
}else {
|
||||
this.inventorySlots.getSlot(i+4).putStack(null);
|
||||
} else {
|
||||
this.inventorySlots.getSlot(i + 4).putStack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String GetButtonTooltip(int buttonId) {
|
||||
if(buttonId == 0){
|
||||
if (buttonId == 0) {
|
||||
return StatCollector.translateToLocal("gui.calculator.tooltipUse");
|
||||
}else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -164,11 +170,11 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
//JustEnoughCalculation.log.info(itemStack.toString());
|
||||
ItemStack buffer = itemStack.copy();
|
||||
ItemStackWrapper.NBT.setBool(buffer, "jecalculation", true);
|
||||
buffer.stackSize=1;
|
||||
buffer.stackSize = 1;
|
||||
Slot slot = getSlotUnderMouse(i, i1);
|
||||
if(slot!=null){
|
||||
if (slot != null) {
|
||||
slot.putStack(buffer);
|
||||
itemStack.stackSize=0;
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+15
-11
@@ -13,28 +13,32 @@ public class ContainerCalculator extends Container {
|
||||
EntityPlayer player;
|
||||
InventoryCalculator inventoryCalculator;
|
||||
|
||||
public ContainerCalculator(EntityPlayer player, ItemStack itemCalculator){
|
||||
public ContainerCalculator(EntityPlayer player, ItemStack itemCalculator) {
|
||||
this.player = player;
|
||||
this.inventoryCalculator = new InventoryCalculator(itemCalculator);
|
||||
addSlotToContainer(new Slot(inventoryCalculator, 0,9,9));
|
||||
addSlotToContainer(new Slot(inventoryCalculator, 0, 9, 9));
|
||||
int i, left, top;
|
||||
i = 1; left = 8; top = 80;
|
||||
for(int a = 0; a < 3; a++){
|
||||
for(int b =0; b < 9; b++){
|
||||
addSlotToContainer(new Slot(inventoryCalculator,i+9*a+b,left+b*18,top+a*18));
|
||||
i = 1;
|
||||
left = 8;
|
||||
top = 80;
|
||||
for (int a = 0; a < 3; a++) {
|
||||
for (int b = 0; b < 9; b++) {
|
||||
addSlotToContainer(new Slot(inventoryCalculator, i + 9 * a + b, left + b * 18, top + a * 18));
|
||||
}
|
||||
}
|
||||
i = 28; left = 8; top = 32;
|
||||
for(int a = 0; a < 1; a++){
|
||||
for(int b =0; b < 6; b++){
|
||||
addSlotToContainer(new Slot(inventoryCalculator,i+9*a+b,left+b*18,top+a*18));
|
||||
i = 28;
|
||||
left = 8;
|
||||
top = 32;
|
||||
for (int a = 0; a < 1; a++) {
|
||||
for (int b = 0; b < 6; b++) {
|
||||
addSlotToContainer(new Slot(inventoryCalculator, i + 9 * a + b, left + b * 18, top + a * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 33)
|
||||
if (p_75139_1_ <= 33)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -4,8 +4,16 @@ import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.Calculator;
|
||||
import me.towdium.jecalculation.core.CostRecord;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.gui.commom.GuiTooltipScreen;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import me.towdium.jecalculation.network.packets.PacketSyncRecord;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
@@ -14,21 +22,13 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import me.towdium.jecalculation.core.Calculator;
|
||||
import me.towdium.jecalculation.core.CostRecord;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.gui.commom.GuiTooltipScreen;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiCalculator extends GuiTooltipScreen{
|
||||
public class GuiCalculator extends GuiTooltipScreen {
|
||||
static int recentLen = 6;
|
||||
GuiTextField textFieldAmount;
|
||||
GuiButton buttonLeft;
|
||||
@@ -49,8 +49,8 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
public enum EnumMode {
|
||||
INPUT, PROCEDURE, OUTPUT, CATALYST;
|
||||
|
||||
int toInt(){
|
||||
switch (this){
|
||||
int toInt() {
|
||||
switch (this) {
|
||||
case INPUT:
|
||||
return 1;
|
||||
case PROCEDURE:
|
||||
@@ -64,8 +64,8 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
static EnumMode fromInt(int i){
|
||||
switch (i){
|
||||
static EnumMode fromInt(int i) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return INPUT;
|
||||
case 2:
|
||||
@@ -80,7 +80,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
public GuiCalculator(ContainerCalculator containerCalculator){
|
||||
public GuiCalculator(ContainerCalculator containerCalculator) {
|
||||
super(containerCalculator, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord());
|
||||
items = new HashMap<>(27);
|
||||
@@ -89,41 +89,45 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonLeft = new GuiButton(4, guiLeft+7, guiTop+139, 20, 20, "<");
|
||||
buttonRight = new GuiButton(5, guiLeft+65, guiTop+139, 20, 20, ">");
|
||||
buttonEdit = new GuiButton(3, guiLeft+7, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.edit"));
|
||||
buttonLeft = new GuiButton(4, guiLeft + 7, guiTop + 139, 20, 20, "<");
|
||||
buttonRight = new GuiButton(5, guiLeft + 65, guiTop + 139, 20, 20, ">");
|
||||
buttonEdit = new GuiButton(3, guiLeft + 7, guiTop + 53, 79, 20,
|
||||
StatCollector.translateToLocal("gui.calculator.edit"));
|
||||
//buttonCalculate = new GuiButton(1, guiLeft+111, guiTop+7, 58, 20, StatCollector.translateToLocal("gui.calculator.calculate"));
|
||||
buttonView = new GuiButton(7, guiLeft+90, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.view"));
|
||||
buttonView = new GuiButton(7, guiLeft + 90, guiTop + 53, 79, 20,
|
||||
StatCollector.translateToLocal("gui.calculator.view"));
|
||||
//buttonList.add(buttonCalculate);
|
||||
buttonList.add(new GuiButton(2, guiLeft+101, guiTop+7, 68, 20, StatCollector.translateToLocal("gui.calculator.add")));
|
||||
buttonList.add(new GuiButton(2, guiLeft + 101, guiTop + 7, 68, 20,
|
||||
StatCollector.translateToLocal("gui.calculator.add")));
|
||||
buttonList.add(buttonEdit);
|
||||
buttonList.add(buttonView);
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
buttonMode = new GuiButton(6, guiLeft+89, guiTop+139, 80, 20, StatCollector.translateToLocal("gui.calculator.input"));
|
||||
buttonMode = new GuiButton(6, guiLeft + 89, guiTop + 139, 80, 20,
|
||||
StatCollector.translateToLocal("gui.calculator.input"));
|
||||
buttonList.add(buttonMode);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 57, 18);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft + 39, guiTop + 8, 57, 18);
|
||||
Slot dest = inventorySlots.getSlot(0);
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStack itemStack = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
|
||||
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
|
||||
ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
|
||||
for(int i=0; i<recentLen; i++){
|
||||
inventorySlots.getSlot(28+i).putStack(ItemStackWrapper.NBT.getItem(calculatorItem, "recent"+i));
|
||||
for (int i = 0; i < recentLen; i++) {
|
||||
inventorySlots.getSlot(28 + i).putStack(ItemStackWrapper.NBT.getItem(calculatorItem, "recent" + i));
|
||||
}
|
||||
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
|
||||
mode = EnumMode.fromInt(ItemStackWrapper.NBT.getInt(calculatorItem, "mode"));
|
||||
init = true;
|
||||
onOpen();
|
||||
if(!JustEnoughCalculation.JECConfig.initialized){
|
||||
if (!JustEnoughCalculation.JECConfig.initialized) {
|
||||
ArrayList<String> idents = new ArrayList<>();
|
||||
LOOP:
|
||||
for(ICraftingHandler handler : GuiCraftingRecipe.craftinghandlers){
|
||||
if(handler instanceof TemplateRecipeHandler){
|
||||
if(((TemplateRecipeHandler) handler).getOverlayIdentifier() == null){
|
||||
for (ICraftingHandler handler : GuiCraftingRecipe.craftinghandlers) {
|
||||
if (handler instanceof TemplateRecipeHandler) {
|
||||
if (((TemplateRecipeHandler) handler).getOverlayIdentifier() == null) {
|
||||
continue;
|
||||
}
|
||||
for (String id : idents){
|
||||
if(((TemplateRecipeHandler) handler).getOverlayIdentifier().equals(id) ){
|
||||
for (String id : idents) {
|
||||
if (((TemplateRecipeHandler) handler).getOverlayIdentifier().equals(id)) {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +135,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
String[] strings = new String[idents.size()];
|
||||
for(int i=0; i<idents.size(); i++){
|
||||
for (int i = 0; i < idents.size(); i++) {
|
||||
strings[i] = idents.get(i);
|
||||
}
|
||||
JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().set(strings);
|
||||
@@ -143,14 +147,17 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiCalculator.png"));
|
||||
this.mc.getTextureManager().bindTexture(
|
||||
new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiCalculator.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
if(activeSlot == 0){
|
||||
if (activeSlot == 0) {
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
|
||||
}else if(activeSlot > 0){
|
||||
this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 2,
|
||||
this.guiTop + slot.yDisplayPosition - 2, 176, 0, 20, 20);
|
||||
} else if (activeSlot > 0) {
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-1, this.guiTop+slot.yDisplayPosition-1, 196, 0, 18, 18);
|
||||
this.drawTexturedModalRect(this.guiLeft + slot.xDisplayPosition - 1,
|
||||
this.guiTop + slot.yDisplayPosition - 1, 196, 0, 18, 18);
|
||||
}
|
||||
textFieldAmount.drawTextBox();
|
||||
drawMissingTexture();
|
||||
@@ -160,24 +167,29 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
|
||||
fontRendererObj.drawString("x", 30, 13, 4210752);
|
||||
drawCenteredStringWithoutShadow(fontRendererObj, StatCollector.translateToLocal("gui.calculator.recent"), 143, 36, 4210752);
|
||||
drawCenteredStringWithoutShadow(fontRendererObj, StatCollector.translateToLocal("gui.calculator.recent"), 143,
|
||||
36, 4210752);
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String GetButtonTooltip(int buttonId) {
|
||||
switch (buttonId){
|
||||
case 2: return StatCollector.translateToLocal("gui.calculator.addTooltip");
|
||||
case 3: return StatCollector.translateToLocal("gui.calculator.editTooltip");
|
||||
case 6: return StatCollector.translateToLocal("gui.calculator.modeTooltip");
|
||||
case 7: return StatCollector.translateToLocal("gui.calculator.viewTooltip");
|
||||
switch (buttonId) {
|
||||
case 2:
|
||||
return StatCollector.translateToLocal("gui.calculator.addTooltip");
|
||||
case 3:
|
||||
return StatCollector.translateToLocal("gui.calculator.editTooltip");
|
||||
case 6:
|
||||
return StatCollector.translateToLocal("gui.calculator.modeTooltip");
|
||||
case 7:
|
||||
return StatCollector.translateToLocal("gui.calculator.viewTooltip");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
switch (button.id){
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
switch (button.id) {
|
||||
/*case 1:
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
mode = EnumMode.INPUT;
|
||||
@@ -185,31 +197,34 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
break;*/
|
||||
case 2:
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(),
|
||||
textFieldAmount.getText());
|
||||
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this));
|
||||
break;
|
||||
case 3:
|
||||
List<Integer> list;
|
||||
if (activeSlot == -1) {
|
||||
list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(0).getStack(), null);
|
||||
}else {
|
||||
list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(activeSlot).getStack(), null);
|
||||
list = JustEnoughCalculation.proxy.getPlayerHandler()
|
||||
.getAllRecipeIndexOf(inventorySlots.getSlot(0).getStack(), null);
|
||||
} else {
|
||||
list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(
|
||||
inventorySlots.getSlot(activeSlot).getStack(), null);
|
||||
}
|
||||
|
||||
mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, list));
|
||||
break;
|
||||
case 4:
|
||||
if(page>1){
|
||||
if (page > 1) {
|
||||
page--;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if(page<total){
|
||||
if (page < total) {
|
||||
page++;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
switch (mode){
|
||||
switch (mode) {
|
||||
case INPUT:
|
||||
mode = EnumMode.PROCEDURE;
|
||||
break;
|
||||
@@ -223,9 +238,10 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mode = EnumMode.INPUT;
|
||||
break;
|
||||
}
|
||||
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(),
|
||||
textFieldAmount.getText());
|
||||
page = 1;
|
||||
break;
|
||||
case 7:
|
||||
@@ -236,12 +252,12 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
//+JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
textFieldAmount.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
if(mouseButton == 1 && buttonMode.mousePressed(mc, mouseX, mouseY)){
|
||||
switch (mode){
|
||||
if (mouseButton == 1 && buttonMode.mousePressed(mc, mouseX, mouseY)) {
|
||||
switch (mode) {
|
||||
case INPUT:
|
||||
mode = EnumMode.CATALYST;
|
||||
break;
|
||||
@@ -255,21 +271,22 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mode = EnumMode.OUTPUT;
|
||||
break;
|
||||
}
|
||||
mc.thePlayer.playSound("random.click", 0.8f, 0.8f );
|
||||
mc.thePlayer.playSound("random.click", 0.8f, 0.8f);
|
||||
updateLayout();
|
||||
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt());
|
||||
}
|
||||
Slot s = getSlotUnderMouse(mouseX,mouseY);
|
||||
if(s != null && s.getSlotIndex() > 27 && s.getStack() != null){
|
||||
Slot s = getSlotUnderMouse(mouseX, mouseY);
|
||||
if (s != null && s.getSlotIndex() > 27 && s.getStack() != null) {
|
||||
inventorySlots.getSlot(0).putStack(s.getStack());
|
||||
mode = EnumMode.INPUT;
|
||||
refreshRecipe();
|
||||
updateLayout();
|
||||
}else if(s != null && s.getSlotIndex() > 0 && s.getSlotIndex() <= 27 && s.getStack() != null){
|
||||
} else if (s != null && s.getSlotIndex() > 0 && s.getSlotIndex() <= 27 && s.getStack() != null) {
|
||||
GuiCraftingRecipe.openRecipeGui("item", s.getStack().copy());
|
||||
}
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler()
|
||||
.syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
//Slot slot = getSlotUnderMouse(mouseX, mouseY);
|
||||
/*if(slot != null && slot.getSlotIndex() == 0 && mouseButton == 0){
|
||||
setActiveSlot(slot.getSlotIndex());
|
||||
@@ -280,26 +297,27 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode){
|
||||
if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)){
|
||||
if(keyCode == 1){
|
||||
if(activeSlot != -1){
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)) {
|
||||
if (keyCode == 1) {
|
||||
if (activeSlot != -1) {
|
||||
inventorySlots.getSlot(activeSlot).putStack(buffer);
|
||||
setActiveSlot(-1);
|
||||
}else {
|
||||
} else {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(),
|
||||
textFieldAmount.getText());
|
||||
|
||||
refreshRecipe();
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLayout(){
|
||||
switch (mode){
|
||||
public void updateLayout() {
|
||||
switch (mode) {
|
||||
case OUTPUT:
|
||||
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.output");
|
||||
break;
|
||||
@@ -313,36 +331,42 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.catalyst");
|
||||
break;
|
||||
}
|
||||
boolean b = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null);
|
||||
if(activeSlot == -1){
|
||||
boolean b = JustEnoughCalculation.proxy.getPlayerHandler()
|
||||
.getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null);
|
||||
if (activeSlot == -1) {
|
||||
buttonEdit.enabled = b;
|
||||
}else {
|
||||
buttonEdit.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(activeSlot).getStack(), null);
|
||||
} else {
|
||||
buttonEdit.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(
|
||||
inventorySlots.getSlot(activeSlot).getStack(), null);
|
||||
}
|
||||
//buttonCalculate.enabled = b;
|
||||
buttonView.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipe(null);
|
||||
if(costRecord != null){
|
||||
switch (mode){
|
||||
if (costRecord != null) {
|
||||
switch (mode) {
|
||||
case OUTPUT:
|
||||
total = (costRecord.getOutputStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getOutputStack(), (page-1)*27);break;
|
||||
total = (costRecord.getOutputStack().size() + 26) / 27;
|
||||
fillSlotsWith(costRecord.getOutputStack(), (page - 1) * 27);
|
||||
break;
|
||||
case PROCEDURE:
|
||||
total = (costRecord.getProcedureStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getProcedureStack(), (page-1)*27);break;
|
||||
total = (costRecord.getProcedureStack().size() + 26) / 27;
|
||||
fillSlotsWith(costRecord.getProcedureStack(), (page - 1) * 27);
|
||||
break;
|
||||
case INPUT:
|
||||
total = (costRecord.getInputStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page-1)*27);break;
|
||||
total = (costRecord.getInputStack().size() + 26) / 27;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page - 1) * 27);
|
||||
break;
|
||||
case CATALYST:
|
||||
total = (costRecord.getCatalystStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*27);break;
|
||||
total = (costRecord.getCatalystStack().size() + 26) / 27;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page - 1) * 27);
|
||||
break;
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
fillSlotsWith(new ArrayList<ItemStack>(), 0);
|
||||
total = 0;
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
if(JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()){
|
||||
if (JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()) {
|
||||
checkItem();
|
||||
}
|
||||
}
|
||||
@@ -352,43 +376,44 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
public void setActiveSlot(int activeSlot) {
|
||||
if(activeSlot == -1){
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
}else {
|
||||
if (activeSlot == -1) {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(),
|
||||
textFieldAmount.getText());
|
||||
} else {
|
||||
buffer = inventorySlots.getSlot(activeSlot).getStack();
|
||||
}
|
||||
this.activeSlot = activeSlot;
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
public void onOpen(){
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
public void onOpen() {
|
||||
if (inventorySlots.getSlot(0).getStack() != null) {
|
||||
refreshRecipe();
|
||||
}
|
||||
if(init){
|
||||
if (init) {
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
protected void fillSlotsWith(List<ItemStack> itemStacks, int start){
|
||||
protected void fillSlotsWith(List<ItemStack> itemStacks, int start) {
|
||||
int pos = 1;
|
||||
for(int i=start; i<start+27; i++){
|
||||
if(i<=itemStacks.size()-1){
|
||||
for (int i = start; i < start + 27; i++) {
|
||||
if (i <= itemStacks.size() - 1) {
|
||||
ItemStack buffer = itemStacks.get(i);
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
inventorySlots.getSlot(pos++).putStack(buffer);
|
||||
}else {
|
||||
} else {
|
||||
inventorySlots.getSlot(pos++).putStack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void refreshRecipe(){
|
||||
protected void refreshRecipe() {
|
||||
ItemStack dest = inventorySlots.getSlot(0).getStack();
|
||||
int i;
|
||||
try{
|
||||
try {
|
||||
i = Integer.valueOf(textFieldAmount.getText());
|
||||
} catch ( NumberFormatException e ){
|
||||
} catch (NumberFormatException e) {
|
||||
i = 1;
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@@ -399,78 +424,79 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
};
|
||||
Timer t = new Timer();
|
||||
t.schedule(r, 1000);
|
||||
if(inventorySlots.getSlot(0).getStack() == null) {
|
||||
if (inventorySlots.getSlot(0).getStack() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(dest == null) {
|
||||
if (dest == null) {
|
||||
return;
|
||||
}
|
||||
Calculator calculator = new Calculator(dest, i*100);
|
||||
Calculator calculator = new Calculator(dest, i * 100);
|
||||
costRecord = calculator.getCost();
|
||||
dest = dest.copy();
|
||||
dest.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStack[] stack = new ItemStack[6];
|
||||
for(int j=0; j<recentLen; j++){
|
||||
stack[j] = ItemStackWrapper.NBT.getItem(calculatorItem, "recent"+j);
|
||||
for (int j = 0; j < recentLen; j++) {
|
||||
stack[j] = ItemStackWrapper.NBT.getItem(calculatorItem, "recent" + j);
|
||||
}
|
||||
int duplicate = -1;
|
||||
for(int j=0; j<recentLen; j++){
|
||||
if(stack[j] != null && ItemStackWrapper.isTypeEqual(dest, stack[j])){
|
||||
for (int j = 0; j < recentLen; j++) {
|
||||
if (stack[j] != null && ItemStackWrapper.isTypeEqual(dest, stack[j])) {
|
||||
duplicate = j;
|
||||
}
|
||||
}
|
||||
if(duplicate == -1){
|
||||
if (duplicate == -1) {
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest);
|
||||
inventorySlots.getSlot(28).putStack(dest);
|
||||
for(int j=0; j<recentLen-1; j++){
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent"+(j+1), stack[j]);
|
||||
inventorySlots.getSlot(27+2+j).putStack(stack[j]);
|
||||
for (int j = 0; j < recentLen - 1; j++) {
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent" + (j + 1), stack[j]);
|
||||
inventorySlots.getSlot(27 + 2 + j).putStack(stack[j]);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest);
|
||||
inventorySlots.getSlot(28).putStack(dest);
|
||||
for(int j=0; j<duplicate; j++){
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent"+(j+1), stack[j]);
|
||||
inventorySlots.getSlot(27+2+j).putStack(stack[j]);
|
||||
for (int j = 0; j < duplicate; j++) {
|
||||
ItemStackWrapper.NBT.setItem(calculatorItem, "recent" + (j + 1), stack[j]);
|
||||
inventorySlots.getSlot(27 + 2 + j).putStack(stack[j]);
|
||||
}
|
||||
}
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(dest, textFieldAmount.getText());
|
||||
}
|
||||
|
||||
protected void drawMissingTexture(){
|
||||
for(int i=0; i<27; i++){
|
||||
Slot slot = inventorySlots.getSlot(i+1);
|
||||
if(items.containsKey(i)){
|
||||
protected void drawMissingTexture() {
|
||||
for (int i = 0; i < 27; i++) {
|
||||
Slot slot = inventorySlots.getSlot(i + 1);
|
||||
if (items.containsKey(i)) {
|
||||
int store = items.get(i);
|
||||
int a = store == 0 ? 0 : store*0x8000000+0x12ff0000;
|
||||
drawRect(slot.xDisplayPosition+guiLeft-1, slot.yDisplayPosition+guiTop-1, slot.xDisplayPosition+guiLeft+17, slot.yDisplayPosition+guiTop+17, a);
|
||||
int a = store == 0 ? 0 : store * 0x8000000 + 0x12ff0000;
|
||||
drawRect(slot.xDisplayPosition + guiLeft - 1, slot.yDisplayPosition + guiTop - 1,
|
||||
slot.xDisplayPosition + guiLeft + 17, slot.yDisplayPosition + guiTop + 17, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkItem(){
|
||||
if(mode != EnumMode.INPUT){
|
||||
for(int i=0; i<27; i++){
|
||||
protected void checkItem() {
|
||||
if (mode != EnumMode.INPUT) {
|
||||
for (int i = 0; i < 27; i++) {
|
||||
items.put(i, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(int i=0; i<27; i++){
|
||||
ItemStack itemStack = inventorySlots.getSlot(i+1).getStack();
|
||||
if(itemStack == null){
|
||||
for (int i = 0; i < 27; i++) {
|
||||
ItemStack itemStack = inventorySlots.getSlot(i + 1).getStack();
|
||||
if (itemStack == null) {
|
||||
items.put(i, 0);
|
||||
continue;
|
||||
}
|
||||
int amount = 0;
|
||||
for(ItemStack itemStackPlayer : mc.thePlayer.inventory.mainInventory){
|
||||
if(ItemStackWrapper.isTypeEqual(itemStackPlayer, itemStack)){
|
||||
for (ItemStack itemStackPlayer : mc.thePlayer.inventory.mainInventory) {
|
||||
if (ItemStackWrapper.isTypeEqual(itemStackPlayer, itemStack)) {
|
||||
amount += itemStackPlayer.stackSize;
|
||||
}
|
||||
}
|
||||
int d = (int)(amount/(double)ItemStackWrapper.getGhostItemAmount(itemStack)*15);
|
||||
d = d>15 ? 0 : 15-d;
|
||||
int d = (int) (amount / (double) ItemStackWrapper.getGhostItemAmount(itemStack) * 15);
|
||||
d = d > 15 ? 0 : 15 - d;
|
||||
items.put(i, d);
|
||||
}
|
||||
}
|
||||
@@ -478,7 +504,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) {
|
||||
Slot slot = getSlotUnderMouse(i, i1);
|
||||
if(slot != null && slot.getSlotIndex() == 0){
|
||||
if (slot != null && slot.getSlotIndex() == 0) {
|
||||
ItemStack buffer = itemStack.copy();
|
||||
buffer.stackSize = 1;
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
@@ -487,9 +513,10 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mode = EnumMode.INPUT;
|
||||
refreshRecipe();
|
||||
updateLayout();
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(),
|
||||
textFieldAmount.getText());
|
||||
}
|
||||
itemStack.stackSize=0;
|
||||
itemStack.stackSize = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack;
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class InventoryCalculator extends InventoryBasic{
|
||||
public class InventoryCalculator extends InventoryBasic {
|
||||
|
||||
public InventoryCalculator(ItemStack itemStack) {
|
||||
super("Calculator", false, 37);
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package me.towdium.jecalculation.gui.guis.recipeEditor;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
|
||||
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipeEditor extends GuiRecipe{
|
||||
public class GuiRecipeEditor extends GuiRecipe {
|
||||
int index = -1;
|
||||
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index){
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index) {
|
||||
super(containerRecipeEditor, parent);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent){
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent) {
|
||||
super(containerRecipeEditor, parent);
|
||||
}
|
||||
|
||||
@@ -33,34 +33,36 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.add(new GuiButton(16, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.save")));
|
||||
buttonList.add(new GuiButton(17, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.clear")));
|
||||
if(index != -1){
|
||||
buttonList.add(new GuiButton(16, guiLeft + 125, guiTop + 7, 44, 20,
|
||||
StatCollector.translateToLocal("gui.recipeEditor.save")));
|
||||
buttonList.add(new GuiButton(17, guiLeft + 125, guiTop + 31, 44, 20,
|
||||
StatCollector.translateToLocal("gui.recipeEditor.clear")));
|
||||
if (index != -1) {
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(index, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
int buttonId = button.id;
|
||||
if(buttonId == 16) {
|
||||
Recipe recipe = ((ContainerRecipe)inventorySlots).buildRecipe();
|
||||
if(recipe == null){
|
||||
if (buttonId == 16) {
|
||||
Recipe recipe = ((ContainerRecipe) inventorySlots).buildRecipe();
|
||||
if (recipe == null) {
|
||||
mc.displayGuiScreen(parent);
|
||||
return;
|
||||
}
|
||||
if(index == -1){
|
||||
if (index == -1) {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().addRecipe(recipe, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, -1));
|
||||
mc.displayGuiScreen(parent);
|
||||
}else {
|
||||
} else {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().setRecipe(recipe, index, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, index));
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}else if(buttonId == 17) {
|
||||
for(Object slot : inventorySlots.inventorySlots){
|
||||
} else if (buttonId == 17) {
|
||||
for (Object slot : inventorySlots.inventorySlots) {
|
||||
((Slot) slot).inventory.setInventorySlotContents(((Slot) slot).getSlotIndex(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package me.towdium.jecalculation.gui.guis.recipePicker;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipePicker extends GuiRecipe{
|
||||
public class GuiRecipePicker extends GuiRecipe {
|
||||
protected List<Integer> recipes;
|
||||
protected int index;
|
||||
protected GuiButton buttonLeft;
|
||||
protected GuiButton buttonRight;
|
||||
|
||||
public GuiRecipePicker(ContainerRecipe containerRecipe, GuiScreen parent, List<Integer> recipes){
|
||||
public GuiRecipePicker(ContainerRecipe containerRecipe, GuiScreen parent, List<Integer> recipes) {
|
||||
super(containerRecipe, parent);
|
||||
this.recipes = recipes;
|
||||
}
|
||||
@@ -29,34 +29,36 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonLeft = new GuiButton(16, guiLeft+125, guiTop+7, 20, 20, "<");
|
||||
buttonRight = new GuiButton(17, guiLeft+149, guiTop+7, 20, 20, ">");
|
||||
buttonLeft = new GuiButton(16, guiLeft + 125, guiTop + 7, 20, 20, "<");
|
||||
buttonRight = new GuiButton(17, guiLeft + 149, guiTop + 7, 20, 20, ">");
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
buttonList.add(new GuiButton(18, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipePicker.delete")));
|
||||
buttonList.add(new GuiButton(18, guiLeft + 125, guiTop + 31, 44, 20,
|
||||
StatCollector.translateToLocal("gui.recipePicker.delete")));
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
int buttonId = button.id;
|
||||
if(buttonId>=0 && buttonId<=15){
|
||||
if (buttonId >= 0 && buttonId <= 15) {
|
||||
GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index));
|
||||
mc.displayGuiScreen(recipeEditor);
|
||||
recipeEditor.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
|
||||
recipeEditor
|
||||
.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
|
||||
recipeEditor.click(buttonId);
|
||||
}else if(buttonId == 16) {
|
||||
if(index>0){
|
||||
} else if (buttonId == 16) {
|
||||
if (index > 0) {
|
||||
index--;
|
||||
updateLayout();
|
||||
}
|
||||
}else if(buttonId == 17) {
|
||||
if(index<recipes.size()-1){
|
||||
} else if (buttonId == 17) {
|
||||
if (index < recipes.size() - 1) {
|
||||
index++;
|
||||
updateLayout();
|
||||
}
|
||||
}else if(buttonId == 18) {
|
||||
} else if (buttonId == 18) {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get(index), null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get(index)));
|
||||
mc.displayGuiScreen(parent);
|
||||
@@ -78,7 +80,7 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
}
|
||||
}*/
|
||||
|
||||
public void updateLayout(){
|
||||
public void updateLayout() {
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
|
||||
buttonRight.enabled = index != recipes.size() - 1;
|
||||
buttonLeft.enabled = index != 0;
|
||||
|
||||
+8
-6
@@ -12,12 +12,14 @@ import net.minecraft.item.ItemStack;
|
||||
public class ContainerRecipeViewer extends Container {
|
||||
InventoryBasic inventory = new InventoryBasic("RecipeViewer", false, 24);
|
||||
|
||||
public ContainerRecipeViewer(){
|
||||
public ContainerRecipeViewer() {
|
||||
int i, left, top;
|
||||
i = 0; left = 8; top = 8;
|
||||
for(int a = 0; a < 6; a++){
|
||||
for(int b =0; b < 4; b++){
|
||||
addSlotToContainer(new Slot(inventory,i+4*a+b,left+b*18,top+a*22));
|
||||
i = 0;
|
||||
left = 8;
|
||||
top = 8;
|
||||
for (int a = 0; a < 6; a++) {
|
||||
for (int b = 0; b < 4; b++) {
|
||||
addSlotToContainer(new Slot(inventory, i + 4 * a + b, left + b * 18, top + a * 22));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +41,7 @@ public class ContainerRecipeViewer extends Container {
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 23)
|
||||
if (p_75139_1_ <= 23)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -2,6 +2,9 @@ package me.towdium.jecalculation.gui.guis.recipeViewer;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import me.towdium.jecalculation.gui.commom.GuiJustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
|
||||
@@ -10,9 +13,6 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import me.towdium.jecalculation.core.ItemStackWrapper;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import me.towdium.jecalculation.gui.commom.GuiJustEnoughCalculation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -28,20 +28,22 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
int page = 1;
|
||||
int total;
|
||||
|
||||
public GuiRecipeViewer (@Nonnull ContainerRecipeViewer container, @Nullable GuiScreen parent){
|
||||
public GuiRecipeViewer(@Nonnull ContainerRecipeViewer container, @Nullable GuiScreen parent) {
|
||||
super(container, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonLeft = new GuiButton(0, guiLeft+7, guiTop+139, 20, 20, "<");
|
||||
buttonRight = new GuiButton(1, guiLeft+149, guiTop+139, 20, 20, ">");
|
||||
buttonLeft = new GuiButton(0, guiLeft + 7, guiTop + 139, 20, 20, "<");
|
||||
buttonRight = new GuiButton(1, guiLeft + 149, guiTop + 139, 20, 20, ">");
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
for(int i=0; i<6; i++){
|
||||
buttonList.add(new GuiButtonExt(2+2*i, guiLeft+83, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.edit")));
|
||||
buttonList.add(new GuiButtonExt(3+2*i, guiLeft+128, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.delete")));
|
||||
for (int i = 0; i < 6; i++) {
|
||||
buttonList.add(new GuiButtonExt(2 + 2 * i, guiLeft + 83, guiTop + 7 + 22 * i, 41, 18,
|
||||
StatCollector.translateToLocal("gui.recipeViewer.edit")));
|
||||
buttonList.add(new GuiButtonExt(3 + 2 * i, guiLeft + 128, guiTop + 7 + 22 * i, 41, 18,
|
||||
StatCollector.translateToLocal("gui.recipeViewer.delete")));
|
||||
}
|
||||
updateLayout();
|
||||
}
|
||||
@@ -49,7 +51,8 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipeViewer.png"));
|
||||
mc.getTextureManager()
|
||||
.bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipeViewer.png"));
|
||||
drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
@@ -61,13 +64,13 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
@Override
|
||||
public void updateLayout() {
|
||||
recipes = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null);
|
||||
total = recipes == null ? 0 : (recipes.size()+5)/6;
|
||||
if(page>total && page != 1){
|
||||
total = recipes == null ? 0 : (recipes.size() + 5) / 6;
|
||||
if (page > total && page != 1) {
|
||||
page = total;
|
||||
}
|
||||
displayRecipes();
|
||||
for(int i=0; i<6; i++){
|
||||
boolean flag = recipes.size() > (page-1)*6+i;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
boolean flag = recipes.size() > (page - 1) * 6 + i;
|
||||
((GuiButton) buttonList.get(2 + 2 * i)).enabled = flag;
|
||||
((GuiButton) buttonList.get(3 + 2 * i)).enabled = flag;
|
||||
}
|
||||
@@ -76,9 +79,9 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
int i = button.id;
|
||||
switch (i){
|
||||
switch (i) {
|
||||
case 0:
|
||||
page--;
|
||||
updateLayout();
|
||||
@@ -88,11 +91,14 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
updateLayout();
|
||||
break;
|
||||
default:
|
||||
if(i%2 == 0){
|
||||
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this, recipes.get((page-1)*6+i/2-1)));
|
||||
}else{
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get((page-1)*6+i/2-1), null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get((page-1)*6+i/2-1)));
|
||||
if (i % 2 == 0) {
|
||||
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this,
|
||||
recipes.get((page - 1) * 6 + i / 2 - 1)));
|
||||
} else {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler()
|
||||
.removeRecipe(recipes.get((page - 1) * 6 + i / 2 - 1), null);
|
||||
JustEnoughCalculation.networkWrapper
|
||||
.sendToServer(new PacketRecipeUpdate(null, recipes.get((page - 1) * 6 + i / 2 - 1)));
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
@@ -100,39 +106,41 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
|
||||
/**
|
||||
* display the recipe at the position
|
||||
*
|
||||
* @param position range 1-6
|
||||
*/
|
||||
public void displayRecipe(@Nullable Recipe recipe, int position){
|
||||
if(recipe != null){
|
||||
public void displayRecipe(@Nullable Recipe recipe, int position) {
|
||||
if (recipe != null) {
|
||||
List<ItemStack> items = recipe.getOutput();
|
||||
for(int i=0; i<4; i++){
|
||||
if(i<items.size()){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < items.size()) {
|
||||
ItemStack buffer = items.get(i);
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(buffer);
|
||||
}else {
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(null);
|
||||
inventorySlots.getSlot((position - 1) * 4 + i).putStack(buffer);
|
||||
} else {
|
||||
inventorySlots.getSlot((position - 1) * 4 + i).putStack(null);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(int i=0; i<4; i++){
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(null);
|
||||
} else {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
inventorySlots.getSlot((position - 1) * 4 + i).putStack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void displayRecipes(){
|
||||
if(recipes != null){
|
||||
for(int i=1; i<=6; i++){
|
||||
int index = i-1+6*(page-1);
|
||||
if(index<recipes.size()){
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null), i);
|
||||
}else {
|
||||
public void displayRecipes() {
|
||||
if (recipes != null) {
|
||||
for (int i = 1; i <= 6; i++) {
|
||||
int index = i - 1 + 6 * (page - 1);
|
||||
if (index < recipes.size()) {
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null),
|
||||
i);
|
||||
} else {
|
||||
displayRecipe(null, i);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(int i=1; i<=6; i++){
|
||||
} else {
|
||||
for (int i = 1; i <= 6; i++) {
|
||||
displayRecipe(null, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,30 +22,30 @@ import java.util.UUID;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerClient implements IPlayerHandler {
|
||||
public List<Recipe> recipes = new ArrayList();
|
||||
public List<Recipe> recipes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(Recipe recipe, UUID uuid) {
|
||||
for (Recipe oneRecipe : recipes){
|
||||
if(oneRecipe.equals(recipe)){
|
||||
for (Recipe oneRecipe : recipes) {
|
||||
if (oneRecipe.equals(recipe)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(recipe != null){
|
||||
if (recipe != null) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipe(UUID uuid) {
|
||||
return recipes.size()!=0;
|
||||
return recipes.size() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndex(UUID uuid) {
|
||||
int a = recipes.size();
|
||||
ImmutableList.Builder<Integer> builder = new ImmutableList.Builder();
|
||||
for (int i = 0; i<a; i++){
|
||||
ImmutableList.Builder<Integer> builder = new ImmutableList.Builder<>();
|
||||
for (int i = 0; i < a; i++) {
|
||||
builder.add(i);
|
||||
}
|
||||
return builder.build();
|
||||
@@ -53,11 +53,11 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
if(itemStack == null){
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
for (Recipe recipe : recipes){
|
||||
if(recipe.getHasOutput(itemStack)){
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.getHasOutput(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -67,17 +67,17 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
@Override
|
||||
public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
int i = getRecipeIndexOf(itemStack, null);
|
||||
if(i == -1){
|
||||
if (i == -1) {
|
||||
return null;
|
||||
}else {
|
||||
} else {
|
||||
return recipes.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder();
|
||||
for(Integer index : getAllRecipeIndexOf(itemStack, null)){
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder<>();
|
||||
for (Integer index : getAllRecipeIndexOf(itemStack, null)) {
|
||||
recipeBuilder.add(recipes.get(index));
|
||||
}
|
||||
return recipeBuilder.build();
|
||||
@@ -86,7 +86,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
@Override
|
||||
public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
int[] result = new int[]{-1, -1, -1, -1};
|
||||
for(int[] record : getAllUnsortedRecipeIndexOf(itemStack)){
|
||||
for (int[] record : getAllUnsortedRecipeIndexOf(itemStack)) {
|
||||
result[record[1]] = record[0];
|
||||
}
|
||||
for (int index : result) {
|
||||
@@ -100,15 +100,15 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
ImmutableList.Builder<ImmutableList.Builder<Integer>> builder1 = new ImmutableList.Builder<>();
|
||||
for(int i=0; i<4; i++){
|
||||
builder1.add(new ImmutableList.Builder<Integer>());
|
||||
for (int i = 0; i < 4; i++) {
|
||||
builder1.add(new ImmutableList.Builder<>());
|
||||
}
|
||||
ImmutableList<ImmutableList.Builder<Integer>> resultBuffer = builder1.build();
|
||||
for(int[] result : getAllUnsortedRecipeIndexOf(itemStack)){
|
||||
for (int[] result : getAllUnsortedRecipeIndexOf(itemStack)) {
|
||||
resultBuffer.get(result[1]).add(result[0]);
|
||||
}
|
||||
ImmutableList.Builder<Integer> builder2 = new ImmutableList.Builder<>();
|
||||
for(ImmutableList.Builder<Integer> priority : resultBuffer){
|
||||
for (ImmutableList.Builder<Integer> priority : resultBuffer) {
|
||||
builder2.addAll(priority.build().reverse());
|
||||
}
|
||||
return builder2.build();
|
||||
@@ -126,13 +126,13 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index, UUID uuid) {
|
||||
return index<recipes.size() ? recipes.get(index) : null;
|
||||
return index < recipes.size() ? recipes.get(index) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncItemCalculator(ItemStack itemIn, String string) {
|
||||
ItemStack itemStack = Minecraft.getMinecraft().thePlayer.getHeldItem();
|
||||
ItemStackWrapper.NBT.setItem(itemStack, "dest",itemIn );
|
||||
ItemStackWrapper.NBT.setItem(itemStack, "dest", itemIn);
|
||||
ItemStackWrapper.NBT.setString(itemStack, "text", string);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketCalculatorUpdate(itemStack));
|
||||
}
|
||||
@@ -150,14 +150,14 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
|
||||
@Override
|
||||
public void handleSave(PlayerEvent.SaveToFile event) {
|
||||
try{
|
||||
try {
|
||||
File file = event.getPlayerFile("jeca");
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
writeToNBT(compound);
|
||||
FileOutputStream fileoutputstream = new FileOutputStream(file);
|
||||
CompressedStreamTools.writeCompressed(compound, fileoutputstream);
|
||||
}catch (Exception e){
|
||||
JustEnoughCalculation.log.warn("Fail to save records for"+event.entityPlayer.getDisplayName());
|
||||
} catch (Exception e) {
|
||||
JustEnoughCalculation.log.warn("Fail to save records for" + event.entityPlayer.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,35 +176,35 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
return ImmutableList.copyOf(recipes);
|
||||
}
|
||||
|
||||
ImmutableList<int[]> getAllUnsortedRecipeIndexOf(ItemStack itemStack){
|
||||
ImmutableList<int[]> getAllUnsortedRecipeIndexOf(ItemStack itemStack) {
|
||||
ImmutableList.Builder<int[]> builder = new ImmutableList.Builder<>();
|
||||
int size = recipes.size();
|
||||
int buffer;
|
||||
for(int i = 0; i<size; i++){
|
||||
for (int i = 0; i < size; i++) {
|
||||
buffer = recipes.get(i).getOutputIndex(itemStack);
|
||||
if(buffer != -1){
|
||||
if (buffer != -1) {
|
||||
builder.add(new int[]{i, buffer});
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
int amount = tagCompound.getInteger("amount");
|
||||
List<Recipe> recipes = new ArrayList<>(amount);
|
||||
for(int i=0; i<amount; i++){
|
||||
Recipe buffer = Recipe.NBTUtl.fromNBT((NBTTagCompound)tagCompound.getTag(String.valueOf(i)));
|
||||
if(buffer!=null){
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Recipe buffer = Recipe.NBTUtl.fromNBT((NBTTagCompound) tagCompound.getTag(String.valueOf(i)));
|
||||
if (buffer != null) {
|
||||
recipes.add(buffer);
|
||||
}
|
||||
}
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tagCompound){
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
tagCompound.setInteger("amount", recipes.size());
|
||||
int index = 0;
|
||||
for(Recipe recipe : recipes){
|
||||
for (Recipe recipe : recipes) {
|
||||
tagCompound.setTag(String.valueOf(index++), Recipe.NBTUtl.toNBT(recipe));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.network;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import me.towdium.jecalculation.core.Recipe;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerServer implements IPlayerHandler {
|
||||
private HashMap<UUID,PlayerHandlerClient> players = new HashMap<>();
|
||||
private HashMap<UUID, PlayerHandlerClient> players = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
@@ -102,7 +102,7 @@ public class PlayerHandlerServer implements IPlayerHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public PlayerHandlerClient getClient(UUID uuid){
|
||||
public PlayerHandlerClient getClient(UUID uuid) {
|
||||
return players.get(uuid);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.network;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import me.towdium.jecalculation.event.PlayerEventHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
|
||||
@@ -5,9 +5,8 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -15,7 +14,8 @@ import me.towdium.jecalculation.item.ItemCalculator;
|
||||
public class PacketCalculatorUpdate implements IMessage, IMessageHandler<PacketCalculatorUpdate, IMessage> {
|
||||
ItemStack itemStack;
|
||||
|
||||
public PacketCalculatorUpdate(){}
|
||||
public PacketCalculatorUpdate() {
|
||||
}
|
||||
|
||||
public PacketCalculatorUpdate(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
@@ -33,9 +33,10 @@ public class PacketCalculatorUpdate implements IMessage, IMessageHandler<PacketC
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCalculatorUpdate message, MessageContext ctx) {
|
||||
if(ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof ItemCalculator){
|
||||
ctx.getServerHandler().playerEntity.inventory.setInventorySlotContents(
|
||||
ctx.getServerHandler().playerEntity.inventory.currentItem, message.itemStack);
|
||||
if (ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof ItemCalculator) {
|
||||
ctx.getServerHandler().playerEntity.inventory
|
||||
.setInventorySlotContents(ctx.getServerHandler().playerEntity.inventory.currentItem,
|
||||
message.itemStack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ public class PacketRecipeUpdate implements IMessage, IMessageHandler<PacketRecip
|
||||
Recipe recipe;
|
||||
int index;
|
||||
|
||||
public PacketRecipeUpdate(){}
|
||||
public PacketRecipeUpdate() {
|
||||
}
|
||||
|
||||
public PacketRecipeUpdate(Recipe recipe, int index){
|
||||
public PacketRecipeUpdate(Recipe recipe, int index) {
|
||||
this.recipe = recipe;
|
||||
this.index = index;
|
||||
}
|
||||
@@ -40,13 +41,13 @@ public class PacketRecipeUpdate implements IMessage, IMessageHandler<PacketRecip
|
||||
@Override
|
||||
public IMessage onMessage(PacketRecipeUpdate message, MessageContext context) {
|
||||
IPlayerHandler playerHandler = JustEnoughCalculation.proxy.getPlayerHandler();
|
||||
if(playerHandler instanceof PlayerHandlerServer){
|
||||
if (playerHandler instanceof PlayerHandlerServer) {
|
||||
UUID uuid = context.getServerHandler().playerEntity.getUniqueID();
|
||||
if(message.index == -1){
|
||||
if (message.index == -1) {
|
||||
playerHandler.addRecipe(message.recipe, uuid);
|
||||
}else if (message.recipe != null){
|
||||
} else if (message.recipe != null) {
|
||||
playerHandler.setRecipe(message.recipe, message.index, uuid);
|
||||
}else {
|
||||
} else {
|
||||
playerHandler.removeRecipe(index, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.network.PlayerHandlerClient;
|
||||
import me.towdium.jecalculation.network.PlayerHandlerServer;
|
||||
import me.towdium.jecalculation.network.ProxyClient;
|
||||
import me.towdium.jecalculation.network.ProxyServer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -20,15 +20,16 @@ import java.util.UUID;
|
||||
public class PacketSyncRecord implements IMessage, IMessageHandler<PacketSyncRecord, IMessage> {
|
||||
PlayerHandlerClient client;
|
||||
|
||||
public PacketSyncRecord(){}
|
||||
public PacketSyncRecord() {
|
||||
}
|
||||
|
||||
public PacketSyncRecord(PlayerHandlerClient client){
|
||||
public PacketSyncRecord(PlayerHandlerClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
if (client == null){
|
||||
if (client == null) {
|
||||
buf.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
@@ -41,7 +42,7 @@ public class PacketSyncRecord implements IMessage, IMessageHandler<PacketSyncRec
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
short s = buf.readShort();
|
||||
if(s == -1){
|
||||
if (s == -1) {
|
||||
return;
|
||||
}
|
||||
this.client = new PlayerHandlerClient();
|
||||
@@ -51,12 +52,14 @@ public class PacketSyncRecord implements IMessage, IMessageHandler<PacketSyncRec
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSyncRecord message, MessageContext ctx) {
|
||||
if(message.client == null && JustEnoughCalculation.proxy instanceof ProxyServer){
|
||||
if (message.client == null && JustEnoughCalculation.proxy instanceof ProxyServer) {
|
||||
//JustEnoughCalculation.proxy.getPlayerHandler().handleLogin(ctx.getServerHandler().playerEntity.getDisplayNameString());
|
||||
UUID uuida = ctx.getServerHandler().playerEntity.getUniqueID();
|
||||
UUID uuidb = ctx.getServerHandler().playerEntity.getPersistentID();
|
||||
return new PacketSyncRecord(((PlayerHandlerServer) JustEnoughCalculation.proxy.getPlayerHandler()).getClient(uuida));
|
||||
}if(message.client == null && JustEnoughCalculation.proxy instanceof ProxyClient){
|
||||
return new PacketSyncRecord(
|
||||
((PlayerHandlerServer) JustEnoughCalculation.proxy.getPlayerHandler()).getClient(uuida));
|
||||
}
|
||||
if (message.client == null && JustEnoughCalculation.proxy instanceof ProxyClient) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,17 @@ public class MyOverlayHandler implements IOverlayHandler {
|
||||
guiContainer.inventorySlots.getSlot(0).putStack(buffer);
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
LOOP:
|
||||
for(PositionedStack item : iRecipeHandler.getIngredientStacks(i)){
|
||||
for(ItemStack current : itemStacks){
|
||||
if(ItemStackWrapper.isTypeEqual(current, item.items[0])){
|
||||
for (PositionedStack item : iRecipeHandler.getIngredientStacks(i)) {
|
||||
for (ItemStack current : itemStacks) {
|
||||
if (ItemStackWrapper.isTypeEqual(current, item.items[0])) {
|
||||
current.stackSize++;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
itemStacks.add(item.items[0].copy());
|
||||
}
|
||||
int index=4;
|
||||
for(ItemStack itemStack : itemStacks){
|
||||
int index = 4;
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
guiContainer.inventorySlots.getSlot(index++).putStack(itemStack);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@ public class NEICalculatorConfig implements IConfigureNEI {
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
LOOP:
|
||||
for(String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()){
|
||||
for(String b : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty().getStringList()){
|
||||
if(s.equals(b)){
|
||||
for (String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()) {
|
||||
for (String b : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty()
|
||||
.getStringList()) {
|
||||
if (s.equals(b)) {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user