mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 03:39:05 +00:00
1.7.10 version
This commit is contained in:
1 parent
491e1b78b9
commit
2d9b43afc3
32 files changed
+493
-389
No files matched your search
@@ -1,24 +1,27 @@
|
||||
package pers.towdium.justEnoughCalculation;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
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;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
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.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
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;
|
||||
@@ -31,10 +34,9 @@ import java.io.File;
|
||||
* @author Towdium
|
||||
*/
|
||||
|
||||
@Mod(modid = JustEnoughCalculation.Reference.MODID, name = JustEnoughCalculation.Reference.MODNAME, version = JustEnoughCalculation.Reference.VERSION,
|
||||
dependencies = "required-after:JEI@[1.8.9-2.28.2.166,)")
|
||||
public class JustEnoughCalculation {
|
||||
public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator");
|
||||
@Mod(modid = JustEnoughCalculation.Reference.MODID, name = JustEnoughCalculation.Reference.MODNAME, version = JustEnoughCalculation.Reference.VERSION)
|
||||
public class JustEnoughCalculation{
|
||||
public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator").setTextureName(Reference.MODID + ":" + "itemCalculator");
|
||||
public static SimpleNetworkWrapper networkWrapper;
|
||||
public static Logger log = LogManager.getLogger(Reference.MODID);
|
||||
|
||||
@@ -47,7 +49,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 = "1.1.0";
|
||||
public static final String VERSION = "0.1.0";
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -63,15 +65,18 @@ public class JustEnoughCalculation {
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event){
|
||||
if(event.getSide().isClient()){
|
||||
/*if(event.getSide().isClient()){
|
||||
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, EnumDyeColor.BLACK.getDyeDamage()), 'R', Items.redstone);
|
||||
}*/
|
||||
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);
|
||||
proxy.init();
|
||||
|
||||
//DefaultOverlayHandler
|
||||
}
|
||||
|
||||
public static class JECConfig{
|
||||
public static boolean initialized = false;
|
||||
public static Configuration config;
|
||||
public enum EnumItems {
|
||||
EnableInventoryCheck,
|
||||
@@ -134,7 +139,7 @@ public class JustEnoughCalculation {
|
||||
case ListRecipeBlackList:
|
||||
return new String[0];
|
||||
case ListRecipeCategory:
|
||||
return new String[]{ "minecraft.crafting", "minecraft.smelting"};
|
||||
return new String[]{"crafting", "smelting"};
|
||||
}
|
||||
return JECConfig.empty;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,15 @@ public class Calculator {
|
||||
List<CostRecord> costRecords;
|
||||
|
||||
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){
|
||||
if (count > 100) {
|
||||
return;
|
||||
}
|
||||
// all the items possible tp cancel
|
||||
for(ItemRecord itemRecord : cancellableItems){
|
||||
// all the recipes for one item
|
||||
@@ -33,6 +37,7 @@ public class Calculator {
|
||||
continue LOOP1;
|
||||
}
|
||||
costRecords.add(record);
|
||||
count++;
|
||||
cancellableItems = record.getCancellableItems();
|
||||
continue LOOP2;
|
||||
}
|
||||
|
||||
@@ -173,33 +173,57 @@ public class CostRecord{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CostRecord) {
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : output) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).output) {
|
||||
if (itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
return false;
|
||||
}else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : input) {
|
||||
for (ItemRecord itemRecordExt : ((CostRecord) obj).input) {
|
||||
if (itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
return false;
|
||||
}else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).output) {
|
||||
for (ItemRecord itemRecordExt : output) {
|
||||
if (itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
return false;
|
||||
}else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LOOP:
|
||||
for (ItemRecord itemRecordIn : ((CostRecord) obj).input) {
|
||||
for (ItemRecord itemRecordExt : input) {
|
||||
if (itemRecordExt.isSameType(itemRecordIn) && itemRecordExt.amount != itemRecordIn.amount) {
|
||||
return false;
|
||||
if(itemRecordExt.isSameType(itemRecordIn)){
|
||||
if(itemRecordExt.amount != itemRecordIn.amount){
|
||||
return false;
|
||||
}else {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ItemRecord{
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long multiplier){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
meta = itemStack.getItemDamage();
|
||||
amount = ItemStackWrapper.getUnifiedAmount(itemStack) * multiplier;
|
||||
approx = itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("percentage");
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class ItemRecord{
|
||||
*/
|
||||
public ItemRecord(ItemStack itemStack, long amount, boolean approx){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
meta = itemStack.getItemDamage();
|
||||
this.amount = amount;
|
||||
this.approx = approx;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class ItemRecord{
|
||||
|
||||
protected int getOutputAmount(Recipe recipe){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(recipe.output[i].getItem() == item && recipe.output[i].getMetadata() == meta){
|
||||
if(recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta){
|
||||
return ItemStackWrapper.getUnifiedAmount(recipe.output[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package pers.towdium.justEnoughCalculation.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -9,7 +10,7 @@ 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.getMetadata() == two.getMetadata();
|
||||
return one != null && two != null && one.getItem() == two.getItem() && one.getItemDamage() == two.getItemDamage();
|
||||
}
|
||||
|
||||
public static boolean isStackEqual(ItemStack one, ItemStack two){
|
||||
@@ -17,7 +18,7 @@ public class ItemStackWrapper {
|
||||
}
|
||||
|
||||
public static int getUnifiedAmount(ItemStack itemStack){
|
||||
if(itemStack.hasTagCompound()){
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
return itemStack.getTagCompound().getInteger("percentage");
|
||||
}else {
|
||||
return itemStack.stackSize*100;
|
||||
@@ -30,7 +31,7 @@ public class ItemStackWrapper {
|
||||
if(itemStack.getTagCompound().getBoolean("mark")){
|
||||
return "";
|
||||
}
|
||||
long l = itemStack.getTagCompound().getLong("amount");
|
||||
long l = itemStack.getTagCompound().hasKey("amount") ? itemStack.getTagCompound().getLong("amount") : -1;
|
||||
if(l == 0 && itemStack.stackSize == 0){
|
||||
return "";
|
||||
}
|
||||
@@ -38,6 +39,9 @@ public class ItemStackWrapper {
|
||||
if(i != 0){
|
||||
return i + "%";
|
||||
}else{
|
||||
if(l==-1){
|
||||
return String.valueOf(itemStack.stackSize);
|
||||
}
|
||||
return getSimplifiedString((l+99)/100, itemStack.getTagCompound().getBoolean("approx"));
|
||||
}
|
||||
}else {
|
||||
@@ -62,6 +66,7 @@ public class ItemStackWrapper {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
itemStack.setTagCompound(null);
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -188,6 +193,16 @@ public class ItemStackWrapper {
|
||||
dest.getTagCompound().setInteger(key, 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){
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setLong(key, value);
|
||||
}
|
||||
|
||||
public static String getString(ItemStack dest, String key){
|
||||
if(dest.getTagCompound() != null){
|
||||
return dest.getTagCompound().getString(key);
|
||||
@@ -195,6 +210,10 @@ public class ItemStackWrapper {
|
||||
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){
|
||||
return dest.getTagCompound().getInteger(key);
|
||||
@@ -216,7 +235,7 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()){
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
itemStack.getTagCompound().setInteger("percentage", itemStack.getTagCompound().getInteger("percentage")+1);
|
||||
}else {
|
||||
itemStack.stackSize += 1;
|
||||
@@ -231,7 +250,7 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i+10);
|
||||
}else {
|
||||
@@ -253,7 +272,7 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i == 1 || i == 0){
|
||||
itemStack.stackSize = 0;
|
||||
@@ -273,7 +292,7 @@ public class ItemStackWrapper {
|
||||
return false;
|
||||
}else {
|
||||
if(doChange){
|
||||
if(itemStack.hasTagCompound()){
|
||||
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
|
||||
int i = itemStack.getTagCompound().getInteger("percentage");
|
||||
if(i == 0 || i == 1){
|
||||
itemStack.stackSize = 0;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package pers.towdium.justEnoughCalculation.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -62,6 +62,11 @@ public class Recipe {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
package pers.towdium.justEnoughCalculation.event;
|
||||
|
||||
|
||||
import mezz.jei.gui.ItemListOverlay;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
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;
|
||||
import pers.towdium.justEnoughCalculation.plugin.JEIPlugin;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -24,13 +16,13 @@ public class GuiEventHandler {
|
||||
long time = new Date().getTime();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onMouseClick(GuiScreenEvent.MouseInputEvent.Pre event){
|
||||
if(event.gui instanceof GuiRecipeEditor){
|
||||
public void onMouseClick(InputEvent.MouseInputEvent event){
|
||||
/*if(event.gui instanceof GuiRecipeEditor){
|
||||
if(new Date().getTime() - time < 200){
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
if (((GuiRecipeEditor) event.gui).getActiveSlot() != -1){
|
||||
if (((GuiRecipeEditor) Minecraft.getMinecraft().currentScreen).getActiveSlot() != -1){
|
||||
GuiRecipeEditor guiContainer = (GuiRecipeEditor) event.gui;
|
||||
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
|
||||
Slot slot = ((GuiRecipeEditor) event.gui).inventorySlots.getSlot(((GuiRecipeEditor) event.gui).getActiveSlot());
|
||||
@@ -53,7 +45,8 @@ public class GuiEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(event.gui instanceof GuiCalculator){
|
||||
}else
|
||||
if(event.gui instanceof GuiCalculator){
|
||||
if(new Date().getTime() - time < 200){
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
@@ -92,7 +85,7 @@ public class GuiEventHandler {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package pers.towdium.justEnoughCalculation.event;
|
||||
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.*;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.ContainerCalculator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
@@ -18,6 +24,30 @@ public class PlayerEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onSave(SaveToFile event){
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().handleSave(event);
|
||||
if(!JustEnoughCalculation.JECConfig.initialized){
|
||||
ArrayList<String> idents = new ArrayList<>();
|
||||
LOOP:
|
||||
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) ){
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
idents.add(((TemplateRecipeHandler) handler).getOverlayIdentifier());
|
||||
}
|
||||
}
|
||||
String[] strings = new String[idents.size()];
|
||||
for(int i=0; i<idents.size(); i++){
|
||||
strings[i] = idents.get(i);
|
||||
}
|
||||
JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().set(strings);
|
||||
JustEnoughCalculation.JECConfig.save();
|
||||
JustEnoughCalculation.JECConfig.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package pers.towdium.justEnoughCalculation.gui;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.ContainerCalculator;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.GuiCalculator;
|
||||
|
||||
+49
-37
@@ -1,28 +1,44 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
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.entity.RenderItem;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
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.gui.guis.calculator.ContainerCalculator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
protected GuiScreen parent;
|
||||
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("je_calculation")){
|
||||
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_));
|
||||
p_77021_1_.setUnicodeFlag(b);
|
||||
}else {
|
||||
super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public GuiJustEnoughCalculation(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
|
||||
super(inventorySlotsIn);
|
||||
@@ -38,17 +54,13 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int mouseButton){
|
||||
try {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
} catch (IOException ignored) {}
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
public void click(int index){
|
||||
for(GuiButton button : buttonList){
|
||||
if(button.id == index){
|
||||
try {
|
||||
actionPerformed(button);
|
||||
} catch (IOException ignored) {}
|
||||
for(Object button : buttonList){
|
||||
if(((GuiButton) button).id == index){
|
||||
actionPerformed(((GuiButton) button));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,38 +72,38 @@ public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
public void updateLayout(){}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
protected void keyTyped(char typedChar, int keyCode){
|
||||
if(keyCode == 1){
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
|
||||
RenderItem buffer1 = itemRender;
|
||||
RenderItem buffer2 = GuiContainerManager.drawItems;
|
||||
itemRender = renderItem;
|
||||
GuiContainerManager.drawItems = renderItem;
|
||||
super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
|
||||
itemRender = buffer1;
|
||||
GuiContainerManager.drawItems = buffer2;
|
||||
}
|
||||
|
||||
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_) {}
|
||||
}
|
||||
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);
|
||||
}
|
||||
};
|
||||
try {
|
||||
getSlot.setAccessible(true);
|
||||
return (Slot) getSlot.invoke(this, x, y);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
//getSlotAtPosition(int p_146975_1_, int p_146975_2_)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,14 @@ package pers.towdium.justEnoughCalculation.gui.commom;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
@@ -22,7 +28,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
* 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
|
||||
public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler
|
||||
{
|
||||
/** Show a white "?" in the top right part of any button with a tooltip assigned to it */
|
||||
public static boolean ShowTooltipButtonEffect = true;
|
||||
@@ -72,11 +78,17 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
if (inventoryplayer.getItemStack() == null && theSlot != null && theSlot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = theSlot.getStack();
|
||||
this.renderToolTip(itemstack1, mouseX, mouseY);
|
||||
//GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true);
|
||||
drawHoveringText(GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true), mouseX, mouseY, fontRendererObj);
|
||||
}
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -97,12 +109,12 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
int mousedOverButtonId = -1;
|
||||
|
||||
//find out which button is being mouseovered
|
||||
for (GuiButton button : buttonList) {
|
||||
if (IsButtonMouseovered(mouseX, mouseY, button)) {
|
||||
mousedOverButtonId = button.id;
|
||||
for (Object button : buttonList) {
|
||||
if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) {
|
||||
mousedOverButtonId = ((GuiButton) button).id;
|
||||
|
||||
if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
|
||||
RenderTooltipButtonMouseoverEffect(button);
|
||||
RenderTooltipButtonMouseoverEffect(((GuiButton) button));
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -138,7 +150,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
* Determines if a GuiButton is being mouseovered.
|
||||
* @return true if this button is mouseovered
|
||||
*/
|
||||
protected boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button)
|
||||
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;
|
||||
@@ -147,14 +159,16 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
/**
|
||||
* Render anything special onto all buttons that have tooltips assigned to them.
|
||||
*/
|
||||
protected void RenderTooltipButtonEffect()
|
||||
private void RenderTooltipButtonEffect()
|
||||
{
|
||||
for (GuiButton button : buttonList) {
|
||||
for (Object buttonObj : buttonList) {
|
||||
GuiButton button = ((GuiButton) buttonObj);
|
||||
if (GetButtonTooltip(button.id) != null) {
|
||||
boolean flag = mc.fontRendererObj.getUnicodeFlag();
|
||||
mc.fontRendererObj.setUnicodeFlag(true);
|
||||
mc.fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7, button.yPosition + 1, 14737632);
|
||||
mc.fontRendererObj.setUnicodeFlag(flag);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,18 +176,18 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
/**
|
||||
* Render anything special onto buttons that have tooltips assigned to them when they are mousevered.
|
||||
*/
|
||||
protected void RenderTooltipButtonMouseoverEffect(GuiButton button)
|
||||
private void RenderTooltipButtonMouseoverEffect(GuiButton button)
|
||||
{
|
||||
boolean flag = mc.fontRendererObj.getUnicodeFlag();
|
||||
mc.fontRendererObj.setUnicodeFlag(true);
|
||||
mc.fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7, button.yPosition+1, 14737632);
|
||||
mc.fontRendererObj.setUnicodeFlag(flag);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a tooltip at (x,y).
|
||||
*/
|
||||
protected 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);
|
||||
@@ -184,11 +198,11 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
* @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
|
||||
*/
|
||||
protected String[] ParseTooltipArrayFromString(String s)
|
||||
private String[] ParseTooltipArrayFromString(String s)
|
||||
{
|
||||
s = DecodeStringCodes(s);
|
||||
String[] tooltipSections = s.split(tooltipNewlineDelimeter);
|
||||
ArrayList<String> tooltipArrayList = new ArrayList<>();
|
||||
ArrayList<String> tooltipArrayList = new ArrayList();
|
||||
|
||||
for(String section : tooltipSections)
|
||||
{
|
||||
@@ -196,7 +210,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
String[] tooltipWords = section.split(" ");
|
||||
|
||||
for (String tooltipWord : tooltipWords) {
|
||||
int lineWidthWithNextWord = mc.fontRendererObj.getStringWidth(tooltip + tooltipWord);
|
||||
int lineWidthWithNextWord = mc.fontRenderer.getStringWidth(tooltip + tooltipWord);
|
||||
if (lineWidthWithNextWord > tooltipMaxWidth) {
|
||||
tooltipArrayList.add(tooltip.trim());
|
||||
tooltip = tooltipWord + " ";
|
||||
@@ -253,7 +267,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
int longestWidth = 0;
|
||||
for(String s : tooltipArray)
|
||||
{
|
||||
int width = mc.fontRendererObj.getStringWidth(s);
|
||||
int width = mc.fontRenderer.getStringWidth(s);
|
||||
if(width > longestWidth)
|
||||
longestWidth = width;
|
||||
}
|
||||
@@ -265,7 +279,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
*/
|
||||
private int GetTooltipHeight(String[] tooltipArray)
|
||||
{
|
||||
int tooltipHeight = mc.fontRendererObj.FONT_HEIGHT - 2;
|
||||
int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2;
|
||||
if (tooltipArray.length > 1)
|
||||
{
|
||||
tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
|
||||
@@ -273,6 +287,32 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
return tooltipHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisiblityData modifyVisiblity(GuiContainer guiContainer, VisiblityData visiblityData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Integer> getItemSpawnSlots(GuiContainer guiContainer, ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer guiContainer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) {
|
||||
itemStack.stackSize=0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hideItemPanelSlot(GuiContainer guiContainer, int i, int i1, int i2, int i3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public class FontCodes
|
||||
{
|
||||
@@ -303,4 +343,6 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
|
||||
public static final String RESET = "\247r";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+19
-5
@@ -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.ItemRecord;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
|
||||
@@ -13,10 +15,8 @@ import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
*/
|
||||
public class ContainerRecipe extends Container {
|
||||
|
||||
InventoryRecipe inventoryRecipe;
|
||||
|
||||
public ContainerRecipe(){
|
||||
inventoryRecipe = new InventoryRecipe();
|
||||
InventoryRecipe inventoryRecipe = new InventoryRecipe();
|
||||
int i, left, top;
|
||||
i = 0; left = 9; top = 9;
|
||||
for(int a = 0; a < 2; a++){
|
||||
@@ -70,14 +70,28 @@ public class ContainerRecipe extends Container {
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
boolean flag1 = false, flag2 = false;
|
||||
for(int i=0; i<4; i++){
|
||||
output[i] = getSlot(i).getStack();
|
||||
ItemStack buffer = getSlot(i).getStack();
|
||||
if(buffer != null && buffer.hasTagCompound()){
|
||||
buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
if(buffer.getTagCompound().hasNoTags()){
|
||||
buffer.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
output[i] = buffer;
|
||||
if(output[i] != null){
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=4; i<16; i++){
|
||||
input[i-4] = getSlot(i).getStack();
|
||||
ItemStack buffer = getSlot(i).getStack();
|
||||
if(buffer != null && buffer.hasTagCompound()){
|
||||
buffer.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
|
||||
if(buffer.getTagCompound().hasNoTags()){
|
||||
buffer.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
input[i-4] = buffer;
|
||||
if(input[i-4] != null){
|
||||
flag2 = true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom.recipe;
|
||||
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -16,13 +19,14 @@ import pers.towdium.justEnoughCalculation.gui.commom.GuiTooltipScreen;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipe extends GuiTooltipScreen{
|
||||
protected int activeSlot = -1;
|
||||
public class GuiRecipe extends GuiTooltipScreen {
|
||||
private int activeSlot = -1;
|
||||
|
||||
public GuiRecipe(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
|
||||
super(inventorySlotsIn, parent);
|
||||
@@ -48,7 +52,6 @@ public class GuiRecipe 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/guiRecipe.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
if(activeSlot != -1){
|
||||
@@ -58,7 +61,7 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
protected void actionPerformed(GuiButton button){
|
||||
int buttonId = button.id;
|
||||
if(buttonId <= 15){
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
@@ -72,18 +75,26 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
/*@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
Slot slot = null;
|
||||
try {
|
||||
Field slotField = this.getClass().getDeclaredField("field_146998_K");
|
||||
slotField.setAccessible(true);
|
||||
slot = (Slot) slotField.get(this);
|
||||
}
|
||||
catch (NoSuchFieldException ignored) {}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
|
||||
if(slot != null && mouseButton == 0 && slot.getStack() == null){
|
||||
setActiveSlot(slot.getSlotIndex());
|
||||
mc.thePlayer.playSound("random.click", 1f, 1f );
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (keyCode == 1) {
|
||||
if(activeSlot != -1){
|
||||
setActiveSlot(-1);
|
||||
@@ -101,7 +112,7 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
}
|
||||
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
|
||||
if(slotIn != null && b && !slotIn.getHasStack()){
|
||||
buttonList.get(slotIn.getSlotIndex()).displayString = "#";
|
||||
((GuiButton) buttonList.get(slotIn.getSlotIndex())).displayString = "#";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +131,9 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
if(i<output.size()){
|
||||
ItemStack itemStack = output.get(i);
|
||||
this.inventorySlots.getSlot(i).putStack(itemStack);
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
buttonList.get(i).displayString = "%";
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
if(itemStack.getTagCompound().hasKey("percentage")){
|
||||
((GuiButton) buttonList.get(i)).displayString = "%";
|
||||
}
|
||||
}else {
|
||||
this.inventorySlots.getSlot(i).putStack(null);
|
||||
@@ -131,8 +143,9 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
if(i<input.size()){
|
||||
ItemStack itemStack = input.get(i);
|
||||
this.inventorySlots.getSlot(i+4).putStack(itemStack);
|
||||
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
|
||||
buttonList.get(i+4).displayString = "%";
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
if(itemStack.getTagCompound().hasKey("percentage")){
|
||||
((GuiButton) buttonList.get(i + 4)).displayString = "%";
|
||||
}
|
||||
}else {
|
||||
this.inventorySlots.getSlot(i+4).putStack(null);
|
||||
@@ -148,4 +161,18 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer guiContainer, int i, int i1, ItemStack itemStack, int i2) {
|
||||
JustEnoughCalculation.log.info(itemStack.toString());
|
||||
ItemStack buffer = itemStack.copy();
|
||||
ItemStackWrapper.NBT.setBool(buffer, "je_calculation", true);
|
||||
buffer.stackSize=1;
|
||||
Slot slot = getSlotUnderMouse(i, i1);
|
||||
if(slot!=null){
|
||||
slot.putStack(buffer);
|
||||
itemStack.stackSize=0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+30
-11
@@ -1,8 +1,11 @@
|
||||
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.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -20,7 +23,6 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.ContainerRecipeV
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -66,7 +68,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
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);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 45, 18);
|
||||
Slot dest = inventorySlots.getSlot(0);
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
|
||||
@@ -76,7 +78,7 @@ 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);
|
||||
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
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){
|
||||
@@ -107,7 +109,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
protected void actionPerformed(GuiButton button){
|
||||
switch (button.id){
|
||||
case 1:
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
@@ -160,21 +162,21 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
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);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
if(slot != null && slot.getSlotIndex() == 0 && mouseButton == 0){
|
||||
//Slot slot = getSlotUnderMouse(mouseX, mouseY);
|
||||
/*if(slot != null && slot.getSlotIndex() == 0 && mouseButton == 0){
|
||||
setActiveSlot(slot.getSlotIndex());
|
||||
((ContainerCalculator)inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
updateLayout();
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
protected void keyTyped(char typedChar, int keyCode){
|
||||
if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)){
|
||||
if(keyCode == 1){
|
||||
if(activeSlot != -1){
|
||||
@@ -257,7 +259,9 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
int pos = 1;
|
||||
for(int i=start; i<start+36; i++){
|
||||
if(i<=itemStacks.size()-1){
|
||||
inventorySlots.getSlot(pos++).putStack(itemStacks.get(i));
|
||||
ItemStack buffer = itemStacks.get(i);
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
inventorySlots.getSlot(pos++).putStack(buffer);
|
||||
}else {
|
||||
inventorySlots.putStackInSlot(pos++, null);
|
||||
}
|
||||
@@ -317,4 +321,19 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
items.put(i, d);
|
||||
}
|
||||
}
|
||||
|
||||
@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){
|
||||
ItemStack buffer = itemStack.copy();
|
||||
buffer.stackSize = 1;
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
ItemStackWrapper.NBT.setBool(buffer, "mark", true);
|
||||
slot.putStack(buffer);
|
||||
updateLayout();
|
||||
}
|
||||
itemStack.stackSize=0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -43,7 +43,7 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
protected void actionPerformed(GuiButton button){
|
||||
super.actionPerformed(button);
|
||||
int buttonId = button.id;
|
||||
if(buttonId == 16) {
|
||||
@@ -62,8 +62,8 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}else if(buttonId == 17) {
|
||||
for(Slot slot : inventorySlots.inventorySlots){
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), null);
|
||||
for(Object slot : inventorySlots.inventorySlots){
|
||||
((Slot) slot).inventory.setInventorySlotContents(((Slot) slot).getSlotIndex(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -40,7 +40,7 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
protected void actionPerformed(GuiButton button){
|
||||
super.actionPerformed(button);
|
||||
int buttonId = button.id;
|
||||
if(buttonId>=0 && buttonId<=15){
|
||||
@@ -65,10 +65,10 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
/*@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
Slot slot = getSlotUnderMouse(mouseX, mouseY);
|
||||
if(slot != null){
|
||||
GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index));
|
||||
mc.displayGuiScreen(recipeEditor);
|
||||
@@ -78,7 +78,7 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
recipeEditor.setActiveSlot(slot.getSlotIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public void updateLayout(){
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
|
||||
|
||||
+10
-5
@@ -1,13 +1,13 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.guis.recipeViewer;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.fml.client.config.GuiButtonExt;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiJustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
@@ -49,7 +49,7 @@ 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);
|
||||
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipeViewer.png"));
|
||||
drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
@@ -66,13 +66,16 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
if(page>total){
|
||||
page = total;
|
||||
}
|
||||
if(page==0){
|
||||
page=1;
|
||||
}
|
||||
displayRecipes();
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
protected void actionPerformed(GuiButton button){
|
||||
int i = button.id;
|
||||
switch (i){
|
||||
case 0:
|
||||
@@ -103,7 +106,9 @@ public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
List<ItemStack> items = recipe.getOutput();
|
||||
for(int i=0; i<4; i++){
|
||||
if(i<items.size()){
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(items.get(i));
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public class ItemCalculator extends Item {
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
|
||||
playerIn.openGui(JustEnoughCalculation.instance, GuiHandler.GuiId.CALCULATOR, worldIn, 0, 0, 0);
|
||||
ItemStack stack = playerIn.inventory.getStackInSlot(0);
|
||||
JustEnoughCalculation.log.info(stack==null ? "" : stack.getItem().getUnlocalizedName() + "-" + stack.getItemDamage());
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ 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) {
|
||||
@@ -44,7 +44,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndex(UUID uuid) {
|
||||
int a = recipes.size();
|
||||
ImmutableList.Builder<Integer> builder = new ImmutableList.Builder<>();
|
||||
ImmutableList.Builder<Integer> builder = new ImmutableList.Builder();
|
||||
for (int i = 0; i<a; i++){
|
||||
builder.add(i);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder<>();
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder();
|
||||
for(Integer index : getAllRecipeIndexOf(itemStack, null)){
|
||||
recipeBuilder.add(recipes.get(index));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerServer implements IPlayerHandler {
|
||||
HashMap<UUID, PlayerHandlerClient> players = new HashMap<>();
|
||||
private HashMap<UUID,PlayerHandlerClient> players = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pers.towdium.justEnoughCalculation.network;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.event.GuiEventHandler;
|
||||
import pers.towdium.justEnoughCalculation.event.PlayerEventHandler;
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
package pers.towdium.justEnoughCalculation.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
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 net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import pers.towdium.justEnoughCalculation.item.ItemCalculator;
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package pers.towdium.justEnoughCalculation.network.packets;
|
||||
|
||||
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.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.network.IPlayerHandler;
|
||||
|
||||
+4
-5
@@ -1,12 +1,11 @@
|
||||
package pers.towdium.justEnoughCalculation.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
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 net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.network.PlayerHandlerClient;
|
||||
import pers.towdium.justEnoughCalculation.network.PlayerHandlerServer;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package pers.towdium.justEnoughCalculation.plugin;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import mezz.jei.api.*;
|
||||
import mezz.jei.api.recipe.IRecipeCategory;
|
||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
@mezz.jei.api.JEIPlugin
|
||||
public class JEIPlugin implements IModPlugin{
|
||||
public static IJeiRuntime runtime;
|
||||
public static IRecipeRegistry recipeRegistry;
|
||||
|
||||
|
||||
@Override
|
||||
public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRegistryAvailable(IItemRegistry itemRegistry) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(@Nonnull IModRegistry registry) {
|
||||
String[] blackList = JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty().getStringList();
|
||||
LOOP:
|
||||
for(String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()){
|
||||
for(String black : blackList){
|
||||
if(black.equals(s)){
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new NormalRecipeTransferHandler(s));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecipeRegistryAvailable(@Nonnull IRecipeRegistry recipeRegistry) {
|
||||
JEIPlugin.recipeRegistry = recipeRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(@Nonnull IJeiRuntime jeiRuntime) {
|
||||
Set<String> identifiers = new HashSet<>();
|
||||
runtime = jeiRuntime;
|
||||
identifiers.addAll(ImmutableList.copyOf(JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()));
|
||||
for(IRecipeCategory category : recipeRegistry.getRecipeCategories()){
|
||||
identifiers.add(category.getUid());
|
||||
}
|
||||
int size = identifiers.size();
|
||||
String[] buffer = new String[size];
|
||||
for (String s : identifiers){
|
||||
buffer[--size] = s;
|
||||
}
|
||||
JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().set(buffer);
|
||||
JustEnoughCalculation.JECConfig.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package pers.towdium.justEnoughCalculation.plugin;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Towdium on 2016/3/21.
|
||||
*/
|
||||
public class MyOverlayHandler implements IOverlayHandler {
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer guiContainer, IRecipeHandler iRecipeHandler, int i, boolean b) {
|
||||
ItemStack buffer = iRecipeHandler.getResultStack(i).item.copy();
|
||||
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
|
||||
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.item)){
|
||||
current.stackSize++;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
itemStacks.add(item.item.copy());
|
||||
}
|
||||
int index=4;
|
||||
for(ItemStack itemStack : itemStacks){
|
||||
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
|
||||
guiContainer.inventorySlots.getSlot(index++).putStack(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package pers.towdium.justEnoughCalculation.plugin;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import codechicken.nei.recipe.DefaultOverlayHandler;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
|
||||
|
||||
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)){
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
API.registerGuiOverlay(GuiRecipeEditor.class, s);
|
||||
API.registerGuiOverlayHandler(GuiRecipeEditor.class, new MyOverlayHandler(), s);
|
||||
}
|
||||
//API.registerGuiOverlay(GuiRecipeEditor.class, "crafting");
|
||||
//API.registerGuiOverlayHandler(GuiRecipeEditor.class, new MyOverlayHandler(), "crafting");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return JustEnoughCalculation.Reference.MODNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return JustEnoughCalculation.Reference.VERSION;
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package pers.towdium.justEnoughCalculation.plugin;
|
||||
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import mezz.jei.gui.ingredients.IGuiIngredient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class NormalRecipeTransferHandler implements IRecipeTransferHandler {
|
||||
String recipeUID;
|
||||
|
||||
public NormalRecipeTransferHandler(String recipeUID ) {
|
||||
this.recipeUID = recipeUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Container> getContainerClass() {
|
||||
return ContainerRecipeEditor.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeCategoryUid() {
|
||||
return recipeUID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(@Nonnull Container container, @Nonnull IRecipeLayout iRecipeLayout, @Nonnull EntityPlayer entityPlayer, boolean maxTransfer, boolean doTransfer) {
|
||||
if(doTransfer){
|
||||
List<ItemStack> outputStacks = new ArrayList<>();
|
||||
List<ItemStack> inputStacks = new ArrayList<>();
|
||||
LOOP:
|
||||
for(IGuiIngredient<ItemStack> ingredient : iRecipeLayout.getItemStacks().getGuiIngredients().values()){
|
||||
if(ingredient.getAllIngredients().size()==0){
|
||||
continue;
|
||||
}
|
||||
if(ingredient.isInput()){
|
||||
ItemStack itemStack = ingredient.getAllIngredients().get(0);
|
||||
for (ItemStack exist : inputStacks){
|
||||
if(ItemStackWrapper.isTypeEqual(exist, itemStack)){
|
||||
exist.stackSize += itemStack.stackSize;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
inputStacks.add(itemStack.copy());
|
||||
}else {
|
||||
ItemStack itemStack = ingredient.getAllIngredients().get(0);
|
||||
for (ItemStack exist : outputStacks){
|
||||
if(ItemStackWrapper.isTypeEqual(exist, itemStack)){
|
||||
exist.stackSize += itemStack.stackSize;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
outputStacks.add(itemStack.copy());
|
||||
}
|
||||
}
|
||||
for(int i=0; i<=outputStacks.size()-1 && i<=3; i++){
|
||||
container.getSlot(i).putStack(outputStacks.get(i));
|
||||
}
|
||||
for(int i=4; i<=4+inputStacks.size()-1 && i<=15; i++){
|
||||
container.getSlot(i).putStack(inputStacks.get(i-4));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user