mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
Now check player's inventory for items
This commit is contained in:
1 parent
1facc192c7
commit
1555a7cffa
6 files changed
+55
-11
No files matched your search
@@ -43,7 +43,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.2";
|
||||
public static final String VERSION = "0.2.0";
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
||||
@@ -137,6 +137,16 @@ public class ItemStackWrapper {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static long getGhostItemAmount(ItemStack itemStack){
|
||||
if (itemStack.hasTagCompound()){
|
||||
long l = itemStack.getTagCompound().getLong("amount");
|
||||
return (l+99)/100;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NBT {
|
||||
public static void initNBT(ItemStack itemStack){
|
||||
if(!itemStack.hasTagCompound()){
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
+37
-6
@@ -21,10 +21,7 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -38,6 +35,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
GuiButton buttonCalculate;
|
||||
GuiButton buttonView;
|
||||
CostRecord costRecord;
|
||||
Map<Integer, Integer> items;
|
||||
int activeSlot = -1;
|
||||
int page = 1;
|
||||
int total = 0;
|
||||
@@ -49,6 +47,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
public GuiCalculator(ContainerCalculator containerCalculator){
|
||||
super(containerCalculator, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord());
|
||||
items = new HashMap<>(36);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +87,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-1, this.guiTop+slot.yDisplayPosition-1, 196, 0, 18, 18);
|
||||
}
|
||||
textFieldAmount.drawTextBox();
|
||||
drawMissingTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,6 +227,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
checkItem();
|
||||
}
|
||||
|
||||
public int getActiveSlot() {
|
||||
@@ -250,7 +251,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSlotsWith(List<ItemStack> itemStacks, int start){
|
||||
protected void fillSlotsWith(List<ItemStack> itemStacks, int start){
|
||||
int pos = 1;
|
||||
for(int i=start; i<start+36; i++){
|
||||
if(i<=itemStacks.size()-1){
|
||||
@@ -261,7 +262,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshRecipe(){
|
||||
protected void refreshRecipe(){
|
||||
try {
|
||||
int i = Integer.valueOf(textFieldAmount.getText());
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), i*100);
|
||||
@@ -278,4 +279,34 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
t.schedule(r, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawMissingTexture(){
|
||||
for(int i=0; i<36; 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkItem(){
|
||||
for(int i=0; i<36; 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)){
|
||||
amount += itemStackPlayer.stackSize;
|
||||
}
|
||||
}
|
||||
int d = (int)(amount/(double)ItemStackWrapper.getGhostItemAmount(itemStack)*15);
|
||||
d = d>15 ? 0 : 15-d;
|
||||
items.put(i, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,5 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.guis.recipeViewer;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -15,6 +14,7 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeE
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketRecipeUpdate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -29,7 +29,7 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
int page = 1;
|
||||
int total;
|
||||
|
||||
public GuiRecipeViewer (@NotNull ContainerRecipeViewer container, @Nullable GuiScreen parent){
|
||||
public GuiRecipeViewer (@Nonnull ContainerRecipeViewer container, @Nullable GuiScreen parent){
|
||||
super(container, parent);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user