mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
Main functions obtained!
This commit is contained in:
1 parent
2e50583d36
commit
54448c77b8
10 files changed
+210
-145
No files matched your search
@@ -19,6 +19,8 @@ public class Calculator {
|
||||
ItemRecord itemRecord;
|
||||
|
||||
|
||||
public Calculator (){}
|
||||
|
||||
public Calculator (ItemStack itemStack, int amount){
|
||||
this(new ItemRecord(itemStack, amount), new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true);
|
||||
}
|
||||
@@ -27,7 +29,7 @@ public class Calculator {
|
||||
this.catalystBuffer = catalystBuffer;
|
||||
this.itemRecord = itemRecord;
|
||||
this.operateRecords = operateRecords;
|
||||
for (Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item, itemRecord.meta), null)){
|
||||
for (Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item,1, itemRecord.meta), null)){
|
||||
if(checkRecipeValid(recipe)){
|
||||
long count = getOperateCount(recipe, exceedMode);
|
||||
this.currentOperate = new OperateRecord(recipe, count);
|
||||
@@ -86,6 +88,10 @@ public class Calculator {
|
||||
return new Calculator.CostRecord(output, input);
|
||||
}
|
||||
|
||||
public CostRecord getEmptyCost(){
|
||||
return new CostRecord();
|
||||
}
|
||||
|
||||
protected boolean checkRecipeValid(Recipe recipe){
|
||||
for (OperateRecord record : operateRecords){
|
||||
if(record.recipe.equals(recipe) && record.count == getOperateCount(recipe)){
|
||||
@@ -117,6 +123,7 @@ public class Calculator {
|
||||
public CostRecord(){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
catalyst = new ArrayList<>();
|
||||
}
|
||||
|
||||
public CostRecord(List<ItemRecord> output, List<ItemRecord> input) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
public class ItemStackWrapper {
|
||||
|
||||
public static boolean isTypeEqual(ItemStack one, ItemStack two){
|
||||
return ItemStack.areItemsEqual(one, two);
|
||||
return one != null && two != null && one.getItem() == two.getItem() && one.getMetadata() == two.getMetadata();
|
||||
}
|
||||
|
||||
public static boolean isStackEqual(ItemStack one, ItemStack two){
|
||||
@@ -29,25 +29,39 @@ public class ItemStackWrapper {
|
||||
}
|
||||
|
||||
public static String getDisplayAmount(ItemStack itemStack){
|
||||
if(itemStack != null && itemStack.getTagCompound() != null){
|
||||
long l = itemStack.getTagCompound().getLong("amount");
|
||||
if(l%100==0){
|
||||
return String.valueOf(l/100);
|
||||
if(itemStack != null){
|
||||
if(itemStack.getTagCompound() != null){
|
||||
if(itemStack.getTagCompound().getBoolean("mark")){
|
||||
return "";
|
||||
}
|
||||
long l = itemStack.getTagCompound().getLong("amount");
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i != 0){
|
||||
return i + "%";
|
||||
}else{
|
||||
return String.valueOf((l+99)/100);
|
||||
}
|
||||
}else {
|
||||
return String.valueOf(l/100 + 1);
|
||||
return String.valueOf(itemStack.stackSize);
|
||||
}
|
||||
}
|
||||
else return "";
|
||||
}
|
||||
|
||||
public static ItemStack toPercentage(ItemStack itemStack){
|
||||
NBT.setInt(itemStack, "percentage", 50);
|
||||
NBT.setInt(itemStack, "percentage", itemStack.stackSize*100);
|
||||
itemStack.stackSize = 1;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack toNormal(ItemStack itemStack){
|
||||
if(itemStack.hasTagCompound()){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.stackSize = (i+99)/100;
|
||||
}else {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
itemStack.setTagCompound(null);
|
||||
itemStack.stackSize = 1;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -120,7 +134,11 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
itemStack.stackSize += 1;
|
||||
if(itemStack.hasTagCompound()){
|
||||
itemStack.getTagCompound().setInteger("percentage", itemStack.getTagCompound().getInteger("percentage")+1);
|
||||
}else {
|
||||
itemStack.stackSize += 1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -131,12 +149,17 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.stackSize == 1){
|
||||
itemStack.stackSize = 10;
|
||||
}else if(itemStack.stackSize <= 54){
|
||||
itemStack.stackSize += 10;
|
||||
if(itemStack.hasTagCompound()){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i+10);
|
||||
}else {
|
||||
itemStack.stackSize = 64;
|
||||
if(itemStack.stackSize == 1){
|
||||
itemStack.stackSize = 10;
|
||||
}else if(itemStack.stackSize <= 54){
|
||||
itemStack.stackSize += 10;
|
||||
}else {
|
||||
itemStack.stackSize = 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -144,25 +167,45 @@ public class ItemStackWrapper {
|
||||
}
|
||||
|
||||
public static boolean rightClick(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null){
|
||||
if(itemStack == null || (itemStack.hasTagCompound() && (itemStack.getTagCompound().getInteger("percentage") == 1 || itemStack.getTagCompound().getInteger("percentage") == 0))){
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
itemStack.stackSize -= 1;
|
||||
if(itemStack.hasTagCompound()){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i == 1 || i == 0){
|
||||
itemStack.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
itemStack.getTagCompound().setInteger("percentage", --i);
|
||||
}else {
|
||||
itemStack.stackSize -= 1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean rightShift(ItemStack itemStack, boolean doChange){
|
||||
if(itemStack == null || itemStack.stackSize>=64){
|
||||
if(itemStack == null){
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.stackSize <= 10){
|
||||
itemStack.stackSize = 0;
|
||||
} else {
|
||||
itemStack.stackSize -= 10;
|
||||
if(itemStack.hasTagCompound()){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
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.stackSize = 0;
|
||||
}else if(itemStack.stackSize <= 10){
|
||||
itemStack.stackSize = 1;
|
||||
} else {
|
||||
itemStack.stackSize -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.ContainerCalculator;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.GuiCalculator;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
@@ -32,7 +33,7 @@ public class GuiEventHandler {
|
||||
GuiRecipeEditor guiContainer = (GuiRecipeEditor) event.gui;
|
||||
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
|
||||
Slot slot = ((GuiRecipeEditor) event.gui).inventorySlots.getSlot(((GuiRecipeEditor) event.gui).getActiveSlot());
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStack);
|
||||
slot.putStack(itemStack == null ? null : itemStack.copy());
|
||||
if(Mouse.isButtonDown(0)){
|
||||
time = new Date().getTime();
|
||||
if(guiContainer.getSlotUnderMouse() != null){
|
||||
@@ -59,7 +60,11 @@ public class GuiEventHandler {
|
||||
if (((GuiCalculator) event.gui).getActiveSlot() == 0){
|
||||
Slot slot = ((GuiCalculator) event.gui).inventorySlots.getSlot(0);
|
||||
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStack);
|
||||
if(itemStack != null){
|
||||
ItemStackWrapper.NBT.initNBT(itemStack);
|
||||
itemStack.getTagCompound().setBoolean("mark", true);
|
||||
}
|
||||
slot.putStack(itemStack == null ? null : itemStack.copy());
|
||||
if (Mouse.isButtonDown(0)){
|
||||
time = new Date().getTime();
|
||||
Slot slot1 = ((GuiCalculator) event.gui).getSlotUnderMouse();
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package pers.towdium.justEnoughCalculation.event;
|
||||
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.recipe.ContainerRecipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -17,4 +21,13 @@ public class PlayerEventHandler {
|
||||
public void onSave(net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile event){
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().handleSave(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTooptipRender(ItemTooltipEvent event){
|
||||
if(((EntityPlayerSP) event.entityPlayer).openContainer instanceof ContainerRecipe){
|
||||
if(event.itemStack.hasTagCompound()){
|
||||
event.toolTip.add(event.itemStack.getTagCompound().getInteger("percentage") + "%");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-15
@@ -4,6 +4,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
|
||||
|
||||
@@ -40,22 +42,16 @@ public class ContainerRecipe extends Container {
|
||||
if(slot != null){
|
||||
ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex());
|
||||
if(itemStack != null){
|
||||
if(clickedButton == 0){
|
||||
ItemStack itemStackBuffer = itemStack.copy();
|
||||
itemStackBuffer.stackSize += 1;
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStackBuffer);
|
||||
slot.onSlotChanged();
|
||||
}else if(clickedButton == 1){
|
||||
if(itemStack.stackSize == 1){
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(),null);
|
||||
slot.onSlotChanged();
|
||||
}else {
|
||||
ItemStack itemStackBuffer = itemStack.copy();
|
||||
itemStackBuffer.stackSize -= 1;
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStackBuffer);
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
if(clickedButton == 0 && mode == 0){
|
||||
ItemStackWrapper.Click.leftClick(slot.getStack(), true);
|
||||
}else if(clickedButton == 0 && mode == 1){
|
||||
ItemStackWrapper.Click.leftShift(slot.getStack(), true);
|
||||
}else if(clickedButton == 1 && mode == 0){
|
||||
ItemStackWrapper.Click.rightClick(slot.getStack(), true);
|
||||
}else if(clickedButton == 1 && mode == 1){
|
||||
ItemStackWrapper.Click.rightShift(slot.getStack(), true);
|
||||
}
|
||||
slot.putStack(itemStack.stackSize == 0 ? null : itemStack);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom.recipe;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiTooltipScreen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipe extends GuiContainer{
|
||||
public class GuiRecipe extends GuiTooltipScreen{
|
||||
protected GuiScreen parent;
|
||||
protected int activeSlot = -1;
|
||||
|
||||
@@ -63,7 +70,13 @@ public class GuiRecipe extends GuiContainer{
|
||||
int buttonId = button.id;
|
||||
if(buttonId <= 15){
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), null);
|
||||
if(button.displayString.equals("N")){
|
||||
slot.putStack(ItemStackWrapper.toPercentage(slot.getStack()));
|
||||
button.displayString = "P";
|
||||
}else {
|
||||
slot.putStack(ItemStackWrapper.toNormal(slot.getStack()));
|
||||
button.displayString = "N";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +113,35 @@ public class GuiRecipe extends GuiContainer{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
ModelManager modelManager = null;
|
||||
Field[] fields = mc.getClass().getDeclaredFields();
|
||||
for(Field field : fields){
|
||||
if(ModelManager.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
modelManager = (ModelManager) field.get(mc);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(modelManager != null){
|
||||
itemRender = new RenderItem(mc.renderEngine, modelManager){
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(fr, stack, xPosition, yPosition, ItemStackWrapper.getDisplayAmount(stack));
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int mouseButton){
|
||||
try {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
@@ -142,4 +184,13 @@ public class GuiRecipe extends GuiContainer{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String GetButtonTooltip(int buttonId) {
|
||||
if(buttonId == 0){
|
||||
return "Switch between_pN: normal mode_pP: percentage mode";
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
-25
@@ -2,6 +2,7 @@ package pers.towdium.justEnoughCalculation.gui.guis.calculator;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -14,7 +15,6 @@ import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.Calculator;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiTooltipScreen;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
@@ -33,6 +33,8 @@ import java.util.TimerTask;
|
||||
*/
|
||||
public class GuiCalculator extends GuiTooltipScreen{
|
||||
GuiTextField textFieldAmount;
|
||||
GuiButton buttonLeft;
|
||||
GuiButton buttonRight;
|
||||
GuiButton buttonEdit;
|
||||
GuiButton buttonMode;
|
||||
GuiButton buttonCalculate;
|
||||
@@ -54,6 +56,8 @@ 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+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"));
|
||||
@@ -61,8 +65,8 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
buttonList.add(new GuiButton(2, guiLeft+89, guiTop+31, 80, 20, StatCollector.translateToLocal("gui.calculator.add")));
|
||||
buttonList.add(buttonEdit);
|
||||
buttonList.add(buttonView);
|
||||
buttonList.add(new GuiButton(4, guiLeft+7, guiTop+139, 20, 20, "<"));
|
||||
buttonList.add(new GuiButton(5, guiLeft+65, guiTop+139, 20, 20, ">"));
|
||||
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(0, fontRendererObj, guiLeft+39, guiTop+8, 45, 18);
|
||||
@@ -70,7 +74,6 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
|
||||
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,24 +113,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
switch (button.id){
|
||||
case 1:
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
try{
|
||||
int i = Integer.valueOf(textFieldAmount.getText());
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), i*100);
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
updateLayout();
|
||||
}catch (Exception e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
textFieldAmount.setTextColor(14737632);
|
||||
}
|
||||
};
|
||||
Timer t = new Timer();
|
||||
t.schedule(r, 1000);
|
||||
}
|
||||
refreshRecipe();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -144,6 +130,16 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, list));
|
||||
break;
|
||||
case 4:
|
||||
if(page>1){
|
||||
page--;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if(page<total){
|
||||
page++;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
switch (mode){
|
||||
case INPUT:
|
||||
@@ -156,6 +152,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mode = EnumMode.INPUT;
|
||||
break;
|
||||
}
|
||||
page = 1;
|
||||
break;
|
||||
case 7:
|
||||
mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null)));
|
||||
@@ -170,7 +167,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
textFieldAmount.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
if(slot != null && mouseButton == 0){
|
||||
if(slot != null && slot.getSlotIndex() == 0 && mouseButton == 0){
|
||||
setActiveSlot(slot.getSlotIndex());
|
||||
((ContainerCalculator)inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
updateLayout();
|
||||
@@ -222,6 +219,8 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
};
|
||||
}
|
||||
costRecord = null;
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -256,13 +255,20 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
if(costRecord != null){
|
||||
switch (mode){
|
||||
case OUTPUT:
|
||||
total = (costRecord.getOutputStack().length+35)/36;
|
||||
fillSlotsWith(costRecord.getOutputStack(), (page-1)*36);break;
|
||||
case INPUT:
|
||||
total = (costRecord.getInputStack().length+35)/36;
|
||||
fillSlotsWith(costRecord.getInputStack(), (page-1)*36);break;
|
||||
case CATALYST:
|
||||
total = (costRecord.getCatalystStack().length+35)/36;
|
||||
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*36);break;
|
||||
}
|
||||
}else {
|
||||
fillSlotsWith(new ItemStack[0], 0);
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
}
|
||||
|
||||
public int getActiveSlot() {
|
||||
@@ -270,9 +276,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
public void setActiveSlot(int activeSlot) {
|
||||
|
||||
if(activeSlot == -1){
|
||||
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
}else {
|
||||
buffer = inventorySlots.getSlot(activeSlot).getStack();
|
||||
@@ -295,4 +299,24 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshRecipe(){
|
||||
try {
|
||||
int i = Integer.valueOf(textFieldAmount.getText());
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), i*100);
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
} catch (Exception e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
textFieldAmount.setTextColor(14737632);
|
||||
}
|
||||
};
|
||||
Timer t = new Timer();
|
||||
t.schedule(r, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
-73
@@ -36,11 +36,6 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
if(activeSlot != -1){
|
||||
RenderTooltip(mouseX, mouseY, new String[]{"haha"});
|
||||
}
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,72 +70,4 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//copied code start
|
||||
|
||||
protected int tooltipXOffset = 0;
|
||||
protected int tooltipYOffset = 10;
|
||||
|
||||
private final static int LINE_HEIGHT = 11;
|
||||
|
||||
protected void RenderTooltip(int x, int y, String[] tooltip)
|
||||
{
|
||||
|
||||
int tooltipWidth = GetTooltipWidth(tooltip);
|
||||
int tooltipHeight = GetTooltipHeight(tooltip);
|
||||
|
||||
int tooltipX = x + tooltipXOffset;
|
||||
int tooltipY = y + tooltipYOffset;
|
||||
|
||||
if(tooltipX > width - tooltipWidth - 7)
|
||||
tooltipX = width - tooltipWidth - 7;
|
||||
if(tooltipY > height - tooltipHeight - 8)
|
||||
tooltipY = height - tooltipHeight - 8;
|
||||
|
||||
//render the background inside box
|
||||
int innerAlpha = -0xFEFFFF0; //very very dark purple
|
||||
drawGradientRect(tooltipX, tooltipY - 1, tooltipX + tooltipWidth + 6, tooltipY, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 6, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 7, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX - 1, tooltipY, tooltipX, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 6, tooltipY, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
|
||||
//render the background outside box
|
||||
int outerAlpha1 = 0x505000FF;
|
||||
int outerAlpha2 = (outerAlpha1 & 0xFEFEFE) >> 1 | outerAlpha1 & -0x1000000;
|
||||
drawGradientRect(tooltipX, tooltipY + 1, tooltipX + 1, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 5, tooltipY + 1, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 3, tooltipY + 1, outerAlpha1, outerAlpha1);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 5, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, outerAlpha2, outerAlpha2);
|
||||
|
||||
//render the foreground text
|
||||
int lineCount = 0;
|
||||
for (String s : tooltip)
|
||||
{
|
||||
mc.fontRendererObj.drawStringWithShadow(s, tooltipX + 2, tooltipY + 2 + lineCount * LINE_HEIGHT, 0xFFFFFF);
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetTooltipWidth(String[] tooltipArray)
|
||||
{
|
||||
int longestWidth = 0;
|
||||
for(String s : tooltipArray)
|
||||
{
|
||||
int width = mc.fontRendererObj.getStringWidth(s);
|
||||
if(width > longestWidth)
|
||||
longestWidth = width;
|
||||
}
|
||||
return longestWidth;
|
||||
}
|
||||
|
||||
private int GetTooltipHeight(String[] tooltipArray)
|
||||
{
|
||||
int tooltipHeight = mc.fontRendererObj.FONT_HEIGHT - 2;
|
||||
if (tooltipArray.length > 1)
|
||||
{
|
||||
tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
|
||||
}
|
||||
return tooltipHeight;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ public class JEIPlugin implements IModPlugin{
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(@Nonnull IJeiRuntime jeiRuntime) {
|
||||
JustEnoughCalculation.log.info("载入了!");
|
||||
runtime = jeiRuntime;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user