mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 03:39:05 +00:00
add recent record & procedure mode with crash fix
This commit is contained in:
1 parent
c17fc4fed2
commit
06ba6fd933
15 files changed
+249
-67
No files matched your search
@@ -1,8 +1,5 @@
|
||||
package pers.towdium.justEnoughCalculation;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import codechicken.nei.recipe.DefaultOverlayHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
@@ -11,17 +8,14 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.recipe.GuiRecipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.item.ItemCalculator;
|
||||
import pers.towdium.justEnoughCalculation.network.IProxy;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketCalculatorUpdate;
|
||||
@@ -29,6 +23,8 @@ import pers.towdium.justEnoughCalculation.network.packets.PacketRecipeUpdate;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -50,7 +46,7 @@ public class JustEnoughCalculation{
|
||||
public static class Reference {
|
||||
public static final String MODID = "je_calculation";
|
||||
public static final String MODNAME = "Just Enough Calculation";
|
||||
public static final String VERSION = "0.1.3";
|
||||
public static final String VERSION = "0.3.0";
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -70,7 +66,23 @@ public class JustEnoughCalculation{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().
|
||||
register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory"));
|
||||
}*/
|
||||
GameRegistry.addRecipe(new ItemStack(itemCalculator), "SIS", "SRS", "SRS", 'S', new ItemStack(Blocks.stone, 1, 0), 'I', new ItemStack(Items.dye, 1, 0), 'R', Items.redstone);
|
||||
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");
|
||||
f.setAccessible(true);
|
||||
Object[] o = (Object[]) f.get(this);
|
||||
if(o[1] instanceof ArrayList){
|
||||
ArrayList<ItemStack> buffer = (ArrayList<ItemStack>) o[1];
|
||||
ArrayList<ItemStack> a = new ArrayList<ItemStack>(buffer);
|
||||
Item i = GameRegistry.findItem("Botania", "dye");
|
||||
a.add(new ItemStack(i,1,15));
|
||||
o[1] = a;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
};
|
||||
GameRegistry.addRecipe(recipe);
|
||||
proxy.init();
|
||||
|
||||
//DefaultOverlayHandler
|
||||
|
||||
@@ -31,7 +31,10 @@ public class Calculator {
|
||||
// all the recipes for one item
|
||||
LOOP1:
|
||||
for(Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(itemRecord.toItemStack(), null)){
|
||||
CostRecord record = new CostRecord(costRecords.get(costRecords.size()-1), new CostRecord(recipe, getCount(itemRecord, recipe), itemRecord.approx));
|
||||
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)){
|
||||
continue LOOP1;
|
||||
|
||||
@@ -11,21 +11,24 @@ import java.util.List;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class CostRecord{
|
||||
List<ItemRecord> output;
|
||||
List<ItemRecord> input;
|
||||
List<ItemRecord> catalyst;
|
||||
private List<ItemRecord> output;
|
||||
private List<ItemRecord> input;
|
||||
private List<ItemRecord> catalyst;
|
||||
private List<ItemRecord> procedure;
|
||||
|
||||
public CostRecord(ItemRecord itemRecord){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new LinkedList<>();
|
||||
procedure = new ArrayList<>();
|
||||
input.add(itemRecord);
|
||||
}
|
||||
|
||||
public CostRecord(Recipe recipe, long count, boolean approx){
|
||||
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){
|
||||
@@ -44,6 +47,7 @@ public class CostRecord{
|
||||
catalyst.add(record);
|
||||
}
|
||||
}
|
||||
procedure.add(dest);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,6 +67,13 @@ public class CostRecord{
|
||||
for (ItemRecord record : costRecord1.catalyst){
|
||||
catalyst.add(record.copy());
|
||||
}
|
||||
procedure = new ArrayList<>();
|
||||
for (ItemRecord record : costRecord1.procedure){
|
||||
procedure.add(record.copy());
|
||||
}
|
||||
for (ItemRecord record : costRecord2.procedure){
|
||||
procedure.add(record.copy());
|
||||
}
|
||||
// merge output
|
||||
LOOP:
|
||||
for(ItemRecord itemRecordAdd : costRecord2.output){
|
||||
@@ -120,7 +131,7 @@ public class CostRecord{
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableList<ItemRecord> getCancellableItems(){
|
||||
ImmutableList<ItemRecord> getCancellableItems(){
|
||||
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
if(!itemRecord.isLocked() && itemRecord.amount != 0){
|
||||
@@ -140,6 +151,17 @@ public class CostRecord{
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getProcedureStack(){
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for (int i = procedure.size()-1; i >=0; i--) {
|
||||
ItemRecord itemRecord = procedure.get(i);
|
||||
if (itemRecord.amount != 0) {
|
||||
builder.add(itemRecord.toItemStack());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public ImmutableList<ItemStack> getInputStack(){
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord itemRecord : input){
|
||||
|
||||
@@ -30,6 +30,8 @@ import javax.annotation.concurrent.Immutable;
|
||||
*/
|
||||
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 */
|
||||
public static boolean ShowTooltipButtonEffect = true;
|
||||
|
||||
@@ -57,12 +59,33 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
super(inventorySlotsIn, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
|
||||
if(ShowTooltipButtonEffect)
|
||||
RenderTooltipButtonEffect();
|
||||
if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
|
||||
for(Object button : buttonList){
|
||||
if(((GuiButton) button).id == mousedOverButtonId){
|
||||
RenderTooltipButtonMouseoverEffect(((GuiButton) button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float f)
|
||||
{
|
||||
for (Object button : buttonList) {
|
||||
if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) {
|
||||
mousedOverButtonId = ((GuiButton) button).id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
DrawTooltipScreen(mouseX, mouseY);
|
||||
InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
|
||||
/*InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
|
||||
Field field;
|
||||
Slot theSlot = null;
|
||||
try {
|
||||
@@ -81,7 +104,8 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
//GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true);
|
||||
drawHoveringText(GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true), mouseX, mouseY, fontRendererObj);
|
||||
}
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
RenderHelper.enableStandardItemLighting();*/
|
||||
mousedOverButtonId = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,22 +127,12 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
*/
|
||||
protected void DrawTooltipScreen(int mouseX, int mouseY)
|
||||
{
|
||||
if(ShowTooltipButtonEffect)
|
||||
RenderTooltipButtonEffect();
|
||||
|
||||
int mousedOverButtonId = -1;
|
||||
|
||||
|
||||
|
||||
//find out which button is being mouseovered
|
||||
for (Object button : buttonList) {
|
||||
if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) {
|
||||
mousedOverButtonId = ((GuiButton) button).id;
|
||||
|
||||
if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
|
||||
RenderTooltipButtonMouseoverEffect(((GuiButton) button));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//calculate how long this button has been mouseovered for
|
||||
if(mousedOverButtonId > -1)
|
||||
@@ -165,10 +179,10 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
GuiButton button = ((GuiButton) buttonObj);
|
||||
if (GetButtonTooltip(button.id) != null) {
|
||||
|
||||
boolean flag = mc.fontRenderer.getUnicodeFlag();
|
||||
mc.fontRenderer.setUnicodeFlag(true);
|
||||
mc.fontRenderer.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7, button.yPosition + 1, 14737632);
|
||||
mc.fontRenderer.setUnicodeFlag(flag);
|
||||
boolean flag = fontRendererObj.getUnicodeFlag();
|
||||
fontRendererObj.setUnicodeFlag(true);
|
||||
fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 -guiLeft, button.yPosition + 1 - guiTop, 14737632);
|
||||
fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,10 +192,10 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implemen
|
||||
*/
|
||||
private void RenderTooltipButtonMouseoverEffect(GuiButton button)
|
||||
{
|
||||
boolean flag = mc.fontRenderer.getUnicodeFlag();
|
||||
mc.fontRenderer.setUnicodeFlag(true);
|
||||
mc.fontRenderer.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7, button.yPosition+1, 14737632);
|
||||
mc.fontRenderer.setUnicodeFlag(flag);
|
||||
boolean flag = fontRendererObj.getUnicodeFlag();
|
||||
fontRendererObj.setUnicodeFlag(true);
|
||||
fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7 - guiLeft, button.yPosition+1 - guiTop, 14737632);
|
||||
fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+15
@@ -32,6 +32,21 @@ public class ContainerRecipe extends Container {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 15)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
|
||||
if(getSlot(p_75141_1_) != null){
|
||||
super.putStackInSlot(p_75141_1_, p_75141_2_);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
if(slotId<0 || slotId>=16){
|
||||
|
||||
@@ -75,6 +75,8 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
@@ -164,7 +166,7 @@ public class GuiRecipe extends GuiTooltipScreen {
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) {
|
||||
JustEnoughCalculation.log.info(itemStack.toString());
|
||||
//JustEnoughCalculation.log.info(itemStack.toString());
|
||||
ItemStack buffer = itemStack.copy();
|
||||
ItemStackWrapper.NBT.setBool(buffer, "je_calculation", true);
|
||||
buffer.stackSize=1;
|
||||
|
||||
+23
-2
@@ -18,12 +18,33 @@ public class ContainerCalculator extends Container {
|
||||
this.inventoryCalculator = new InventoryCalculator(itemCalculator);
|
||||
addSlotToContainer(new Slot(inventoryCalculator, 0,9,9));
|
||||
int i, left, top;
|
||||
i = 1; left = 8; top = 64;
|
||||
for(int a = 0; a < 4; a++){
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 33)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
|
||||
if(getSlot(p_75141_1_) != null){
|
||||
super.putStackInSlot(p_75141_1_, p_75141_2_);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+94
-20
@@ -3,6 +3,7 @@ package pers.towdium.justEnoughCalculation.gui.guis.calculator;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
@@ -22,6 +23,7 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketCalculatorUpdate;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.util.*;
|
||||
@@ -30,6 +32,7 @@ import java.util.*;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiCalculator extends GuiTooltipScreen{
|
||||
static int recentLen = 6;
|
||||
GuiTextField textFieldAmount;
|
||||
GuiButton buttonLeft;
|
||||
GuiButton buttonRight;
|
||||
@@ -45,12 +48,12 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
EnumMode mode = EnumMode.INPUT;
|
||||
ItemStack buffer;
|
||||
|
||||
public enum EnumMode {INPUT, OUTPUT, CATALYST}
|
||||
public enum EnumMode {INPUT, PROCEDURE, OUTPUT, CATALYST}
|
||||
|
||||
public GuiCalculator(ContainerCalculator containerCalculator){
|
||||
super(containerCalculator, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord());
|
||||
items = new HashMap<>(36);
|
||||
items = new HashMap<>(27);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,21 +61,25 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
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+89, guiTop+7, 38, 20, StatCollector.translateToLocal("gui.calculator.edit"));
|
||||
buttonCalculate = new GuiButton(1, guiLeft+7, guiTop+31, 78, 20, StatCollector.translateToLocal("gui.calculator.calculate"));
|
||||
buttonView = new GuiButton(7, guiLeft+131, guiTop+7, 38, 20, StatCollector.translateToLocal("gui.calculator.view"));
|
||||
buttonEdit = new GuiButton(3, guiLeft+59, guiTop+53, 48, 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+111, guiTop+53, 58, 20, StatCollector.translateToLocal("gui.calculator.view"));
|
||||
buttonList.add(buttonCalculate);
|
||||
buttonList.add(new GuiButton(2, guiLeft+89, guiTop+31, 80, 20, StatCollector.translateToLocal("gui.calculator.add")));
|
||||
buttonList.add(new GuiButton(2, guiLeft+7, guiTop+53, 48, 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"));
|
||||
buttonList.add(buttonMode);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 45, 18);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 67, 18);
|
||||
Slot dest = inventorySlots.getSlot(0);
|
||||
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));
|
||||
}
|
||||
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
|
||||
updateLayout();
|
||||
if(!JustEnoughCalculation.JECConfig.initialized){
|
||||
@@ -119,7 +126,9 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
@Override
|
||||
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, "Recent", 143, 36, 4210752);
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@@ -138,6 +147,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
switch (button.id){
|
||||
case 1:
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
mode = EnumMode.INPUT;
|
||||
refreshRecipe();
|
||||
}
|
||||
break;
|
||||
@@ -168,6 +178,9 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
case 6:
|
||||
switch (mode){
|
||||
case INPUT:
|
||||
mode = EnumMode.PROCEDURE;
|
||||
break;
|
||||
case PROCEDURE:
|
||||
mode = EnumMode.OUTPUT;
|
||||
break;
|
||||
case OUTPUT:
|
||||
@@ -188,9 +201,32 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
//+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){
|
||||
case INPUT:
|
||||
mode = EnumMode.CATALYST;
|
||||
break;
|
||||
case PROCEDURE:
|
||||
mode = EnumMode.INPUT;
|
||||
break;
|
||||
case OUTPUT:
|
||||
mode = EnumMode.PROCEDURE;
|
||||
break;
|
||||
case CATALYST:
|
||||
mode = EnumMode.OUTPUT;
|
||||
break;
|
||||
}
|
||||
mc.thePlayer.playSound("random.click", 0.8f, 0.8f );
|
||||
updateLayout();
|
||||
}
|
||||
Slot s = getSlotUnderMouse(mouseX,mouseY);
|
||||
if(s != null && s.getSlotIndex() > 27 && s.getStack() != null){
|
||||
inventorySlots.putStackInSlot(0, s.getStack());
|
||||
}
|
||||
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());
|
||||
@@ -211,7 +247,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
}
|
||||
}
|
||||
@@ -221,6 +257,9 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
case OUTPUT:
|
||||
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.output");
|
||||
break;
|
||||
case PROCEDURE:
|
||||
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.procedure");
|
||||
break;
|
||||
case INPUT:
|
||||
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.input");
|
||||
break;
|
||||
@@ -239,14 +278,17 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
if(costRecord != null){
|
||||
switch (mode){
|
||||
case OUTPUT:
|
||||
total = (costRecord.getOutputStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getOutputStack(), (page-1)*36);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;
|
||||
case INPUT:
|
||||
total = (costRecord.getInputStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page-1)*36);break;
|
||||
total = (costRecord.getInputStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page-1)*27);break;
|
||||
case CATALYST:
|
||||
total = (costRecord.getCatalystStack().size()+35)/36;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*36);break;
|
||||
total = (costRecord.getCatalystStack().size()+26)/27;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*27);break;
|
||||
}
|
||||
}else {
|
||||
fillSlotsWith(new ArrayList<ItemStack>(), 0);
|
||||
@@ -282,7 +324,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
protected void fillSlotsWith(List<ItemStack> itemStacks, int start){
|
||||
int pos = 1;
|
||||
for(int i=start; i<start+36; i++){
|
||||
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);
|
||||
@@ -294,10 +336,42 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
protected void refreshRecipe(){
|
||||
ItemStack dest = inventorySlots.getSlot(0).getStack();
|
||||
try {
|
||||
int i = Integer.valueOf(textFieldAmount.getText());
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), i*100);
|
||||
Calculator calculator = new Calculator(dest, i*100);
|
||||
costRecord = calculator.getCost();
|
||||
if(dest != null){
|
||||
dest = dest.copy();
|
||||
dest.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
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);
|
||||
}
|
||||
int duplicate = -1;
|
||||
for(int j=0; j<recentLen; j++){
|
||||
if(stack[j] != null && ItemStackWrapper.isTypeEqual(dest, stack[j])){
|
||||
duplicate = j;
|
||||
}
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}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]);
|
||||
}
|
||||
}
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(dest, textFieldAmount.getText());
|
||||
}
|
||||
} catch (NumberFormatException e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@@ -312,7 +386,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
protected void drawMissingTexture(){
|
||||
for(int i=0; i<36; i++){
|
||||
for(int i=0; i<27; i++){
|
||||
Slot slot = inventorySlots.getSlot(i+1);
|
||||
if(items.containsKey(i)){
|
||||
int store = items.get(i);
|
||||
@@ -324,12 +398,12 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
protected void checkItem(){
|
||||
if(mode != EnumMode.INPUT){
|
||||
for(int i=0; i<36; i++){
|
||||
for(int i=0; i<27; i++){
|
||||
items.put(i, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(int i=0; i<36; i++){
|
||||
for(int i=0; i<27; i++){
|
||||
ItemStack itemStack = inventorySlots.getSlot(i+1).getStack();
|
||||
if(itemStack == null){
|
||||
items.put(i, 0);
|
||||
|
||||
+15
@@ -37,4 +37,19 @@ public class ContainerRecipeViewer extends Container {
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int p_75139_1_) {
|
||||
if(p_75139_1_ <= 23)
|
||||
return super.getSlot(p_75139_1_);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
|
||||
if(getSlot(p_75141_1_) != null){
|
||||
super.putStackInSlot(p_75141_1_, p_75141_2_);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user