Chore: rename package

This commit is contained in:
Discreater committed 2021-02-28 19:13:43 +08:00
1 parent 06f00d4800
commit 434c1498de
49 files changed
+257 -251

No files matched your search

@@ -0,0 +1,236 @@
package me.towdium.jecalculation;
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 me.towdium.jecalculation.item.ItemCalculator;
import me.towdium.jecalculation.network.IProxy;
import me.towdium.jecalculation.network.packets.PacketCalculatorUpdate;
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
import me.towdium.jecalculation.network.packets.PacketSyncRecord;
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.oredict.ShapedOreRecipe;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
/**
* @author Towdium
*/
@Mod(modid = JustEnoughCalculation.Reference.MODID,
name = JustEnoughCalculation.Reference.MODNAME,
version = JustEnoughCalculation.Reference.VERSION,
dependencies = "after:NotEnoughItems")
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);
@SidedProxy(clientSide = "me.towdium.jecalculation.network.ProxyClient",
serverSide = "me.towdium.jecalculation.network.ProxyServer")
public static IProxy proxy;
@Mod.Instance(JustEnoughCalculation.Reference.MODID)
public static JustEnoughCalculation instance;
@Mod.EventHandler
public static void preInit(FMLPreInitializationEvent event) {
JECConfig.preInit(event);
GameRegistry.registerItem(itemCalculator, itemCalculator.getUnlocalizedName().substring(5));
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);
networkWrapper
.registerMessage(PacketCalculatorUpdate.class, PacketCalculatorUpdate.class, 1,
Side.SERVER);
networkWrapper.registerMessage(PacketRecipeUpdate.class, PacketRecipeUpdate.class, 2,
Side.SERVER);
networkWrapper
.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 3, Side.CLIENT);
networkWrapper
.registerMessage(PacketSyncRecord.class, PacketSyncRecord.class, 4, Side.SERVER);
}
@Mod.EventHandler
public static void iniFt(FMLInitializationEvent event) {
/*if(event.getSide().isClient()){
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().
register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory"));
}*/
ShapedOreRecipe recipe = new ShapedOreRecipe(new ItemStack(itemCalculator), "SIS", "SRS",
"SOS", 'S', "stone", 'I', "dyeBlack", 'R',
"dustRedstone", 'O', "ingotIron") {
{
try {
Field f = ShapedOreRecipe.class.getDeclaredField("input");
f.setAccessible(true);
Object[] o = (Object[]) f.get(this);
if (o[1] instanceof ArrayList) {
ArrayList<ItemStack> buffer = (ArrayList<ItemStack>) o[1];
ArrayList<ItemStack> a = new ArrayList<ItemStack>(buffer);
Item i = GameRegistry.findItem("Botania", "dye");
if (i != null)
a.add(new ItemStack(i, 1, 15));
o[1] = a;
}
} catch (Exception ignored) {
}
}
};
GameRegistry.addRecipe(recipe);
proxy.init();
//DefaultOverlayHandler
}
public static class JECConfig {
public static boolean initialized = false;
public static Configuration config;
public enum EnumItems {
EnableInventoryCheck, ListRecipeBlackList, ListRecipeCategory;
public String getComment() {
switch (this) {
case EnableInventoryCheck:
return "Set to false to disable auto inventory check";
case ListRecipeBlackList:
return "Add string identifier here to disable quick transfer of this type recipe\n" +
"Names can be found in ListRecipeCategory";
case ListRecipeCategory:
return "List of categories, this is maintained by the mod automatically";
}
return "";
}
public String getName() {
switch (this) {
case EnableInventoryCheck:
return "EnableInventoryCheck";
case ListRecipeBlackList:
return "ListRecipeBlackList";
case ListRecipeCategory:
return "ListRecipeCategory";
}
return "";
}
public String getCategory() {
switch (this) {
case EnableInventoryCheck:
return EnumCategory.General.toString();
case ListRecipeBlackList:
return EnumCategory.General.toString();
case ListRecipeCategory:
return EnumCategory.General.toString();
}
return "";
}
public EnumType getType() {
switch (this) {
case EnableInventoryCheck:
return EnumType.Boolean;
case ListRecipeBlackList:
return EnumType.ListString;
case ListRecipeCategory:
return EnumType.ListString;
}
return EnumType.Error;
}
public Object getDefault() {
switch (this) {
case EnableInventoryCheck:
return true;
case ListRecipeBlackList:
return new String[0];
case ListRecipeCategory:
return new String[]{"crafting", "smelting"};
}
return JECConfig.empty;
}
public Property init() {
EnumType type = this.getType();
if (type != null) {
switch (this.getType()) {
case Boolean:
return config.get(this.getCategory(), this.getName(),
(Boolean) this.getDefault(), this.getComment());
case ListString:
return config.get(this.getCategory(), this.getName(),
(String[]) this.getDefault(), this.getComment());
}
config.getCategory(EnumCategory.General.toString()).get(this.getName());
}
return config.get(this.getCategory(), this.getName(), false, this.getComment());
}
public Property getProperty() {
return config.getCategory(EnumCategory.General.toString()).get(this.getName());
}
}
public enum EnumCategory {
General;
@Override
public String toString() {
switch (this) {
case General:
return "general";
default:
return "";
}
}
}
public enum EnumType {Boolean, ListString, Error}
public static Object empty;
public static void preInit(FMLPreInitializationEvent event) {
config = new Configuration(new File(event.getModConfigurationDirectory(),
"JustEnoughCalculation" + ".cfg"),
Reference.VERSION);
config.load();
handleFormerVersion();
handleInit();
config.save();
}
public static void handleFormerVersion() {
config.getCategory("general").remove("RecipeTypeSupport");
}
public static void handleInit() {
for (EnumItems item : EnumItems.values()) {
item.init();
}
}
public static void save() {
config.save();
}
}
public static class Reference {
public static final String MODID = "jecalculation";
public static final String MODNAME = "Just Enough Calculation";
public static final String VERSION = "@VERSION@";
}
}
@@ -0,0 +1,61 @@
package me.towdium.jecalculation.core;
import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
/**
* @author Towdium
* This is calculating core v3.0, I call it global coordinating calculation XD.
* The procudure might be more complex, but can avoid some unexpected results.
*/
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
LOOP1:
for(Recipe recipe : JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeOf(itemRecord.toItemStack(), null)){
long times = getCount(itemRecord, recipe);
ItemRecord buffer = itemRecord.copy();
buffer.amount = recipe.getOutputAmount(buffer.toItemStack())*times;
CostRecord record = new CostRecord(costRecords.get(costRecords.size()-1), new CostRecord(recipe, times, itemRecord.approx, buffer));
for(CostRecord costRecord : costRecords){
if(costRecord.equals(record)){
continue LOOP1;
}
costRecords.add(record);
count++;
cancellableItems = record.getCancellableItems();
continue LOOP2;
}
}
}
break;
}
}
public CostRecord getCost(){
return costRecords.get(costRecords.size()-1);
}
protected long getCount(ItemRecord itemRecord, Recipe recipe){
long a = recipe.getOutputAmount(itemRecord.toItemStack());
return (long)Math.ceil(itemRecord.amount/(double)a);
}
}
@@ -0,0 +1,255 @@
package me.towdium.jecalculation.core;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* @author Towdium
*/
public class CostRecord{
private List<ItemRecord> output;
private List<ItemRecord> input;
private List<ItemRecord> catalyst;
private List<ItemRecord> procedure;
public CostRecord(ItemRecord itemRecord){
output = new ArrayList<>();
input = new ArrayList<>();
catalyst = new LinkedList<>();
procedure = new ArrayList<>();
input.add(itemRecord);
}
public CostRecord(Recipe recipe, long count, boolean approx, ItemRecord dest){
output = new ArrayList<>();
input = new ArrayList<>();
catalyst = new LinkedList<>();
procedure = new ArrayList<>();
boolean b = recipe.isApprox() || approx;
for(ItemStack itemStack : recipe.output){
if(itemStack != null){
ItemRecord record = new ItemRecord(itemStack, count);
record.approx = b;
output.add(record);
}
}
for(ItemStack itemStack : recipe.input){
if(itemStack != null){
ItemRecord record = new ItemRecord(itemStack, count);
record.approx = b;
input.add(record);
record = new ItemRecord(itemStack);
record.approx = b;
catalyst.add(record);
}
}
procedure.add(dest);
}
/**
* Generate CostRecord merging two CostRecords
* ItemRecord with amount 0 may be left there
*/
public CostRecord(CostRecord costRecord1, CostRecord costRecord2){
output = new ArrayList<>();
for (ItemRecord record : costRecord1.output){
output.add(record.copy());
}
input = new ArrayList<>();
for (ItemRecord record : costRecord1.input){
input.add(record.copy());
}
catalyst = new LinkedList<>();
for (ItemRecord record : costRecord1.catalyst){
catalyst.add(record.copy());
}
procedure = new ArrayList<>();
for (ItemRecord record : costRecord1.procedure){
procedure.add(record.copy());
}
for (ItemRecord record : costRecord2.procedure){
procedure.add(record.copy());
}
// merge output
LOOP:
for(ItemRecord itemRecordAdd : costRecord2.output){
for(ItemRecord itemRecordExt : output){
if(itemRecordAdd.isSameType(itemRecordExt)){
itemRecordExt.add(itemRecordAdd);
continue LOOP;
}
}
output.add(itemRecordAdd.copy());
}
// merge input
LOOP:
for(ItemRecord itemRecordAdd : costRecord2.input){
for(ItemRecord itemRecordExt : input){
if(itemRecordAdd.isSameType(itemRecordExt)){
itemRecordExt.add(itemRecordAdd);
continue LOOP;
}
}
input.add(itemRecordAdd.copy());
}
// cancel catalyst by output
LOOP:
for(ItemRecord itemRecordAdd : costRecord2.output){
for (int i = 0; i < catalyst.size(); i++) {
ItemRecord itemRecordExt = catalyst.get(i);
if (itemRecordAdd.isSameType(itemRecordExt) && itemRecordExt.amount <= itemRecordAdd.amount) {
catalyst.remove(i);
continue LOOP;
}else if(itemRecordAdd.isSameType(itemRecordExt)) {
itemRecordExt.minus(itemRecordAdd);
continue LOOP;
}
}
}
// merge catalyst
LOOP:
for(ItemRecord itemRecordAdd : costRecord2.catalyst){
for (ItemRecord itemRecordExt : catalyst) {
if (itemRecordAdd.isSameType(itemRecordExt)) {
itemRecordExt.add(itemRecordAdd);
continue LOOP;
}
}
catalyst.add(itemRecordAdd.copy());
}
// cancel input and output
for(ItemRecord itemRecordIn : input){
for(ItemRecord itemRecordOut : output){
if(itemRecordIn.isSameType(itemRecordOut)){
itemRecordIn.cancel(itemRecordOut);
}
}
}
}
ImmutableList<ItemRecord> getCancellableItems(){
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
for(ItemRecord itemRecord : input){
if(!itemRecord.isLocked() && itemRecord.amount != 0){
builder.add(itemRecord);
}
}
return builder.build();
}
public ImmutableList<ItemStack> getOutputStack(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for(ItemRecord itemRecord : output){
if(itemRecord.amount != 0){
builder.add(itemRecord.toItemStack());
}
}
return builder.build();
}
public ImmutableList<ItemStack> getProcedureStack(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for (int i = procedure.size()-1; i >=0; i--) {
ItemRecord itemRecord = procedure.get(i);
if (itemRecord.amount != 0) {
builder.add(itemRecord.toItemStack());
}
}
return builder.build();
}
public ImmutableList<ItemStack> getInputStack(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for(ItemRecord itemRecord : input){
if(itemRecord.amount != 0){
builder.add(itemRecord.toItemStack());
}
}
return builder.build();
}
public ImmutableList<ItemStack> getCatalystStack(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
LOOP:
for(ItemRecord itemRecord : catalyst){
if(itemRecord.amount != 0){
for(ItemRecord record : input){
if(itemRecord.isSameType(record) && record.amount != 0){
continue LOOP;
}
}
ItemRecord buffer = itemRecord.copy();
//buffer.amount=0;
ItemStack itemStack = buffer.toItemStack();
//itemStack.getTagCompound().setBoolean("mark", true);
builder.add(itemStack);
}
}
return builder.build();
}
@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)){
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)){
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)){
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)){
if(itemRecordExt.amount != itemRecordIn.amount){
return false;
}else {
continue LOOP;
}
}
}
return false;
}
return true;
} else {
return false;
}
}
}
@@ -0,0 +1,132 @@
package me.towdium.jecalculation.core;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* @author Towdium
*/
public class ItemRecord{
Item item;
int meta;
long amount;
boolean approx;
boolean locked;
/**
* Generate ItemRecord based on the ItemStack and multiply the amount
*/
public ItemRecord(ItemStack itemStack, long multiplier){
item = itemStack.getItem();
meta = itemStack.getItemDamage();
amount = ItemStackWrapper.getUnifiedAmount(itemStack) * multiplier;
approx = itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("percentage");
}
public ItemRecord(ItemStack itemStack){
this(itemStack, 1);
}
/**
* Generate ItemRecord with customized amount
*/
public ItemRecord(ItemStack itemStack, long amount, boolean approx){
item = itemStack.getItem();
meta = itemStack.getItemDamage();
this.amount = amount;
this.approx = approx;
}
public ItemRecord(Item item, int meta, long amount, boolean approx) {
this.item = item;
this.meta = meta;
this.amount = amount;
this.approx = approx;
}
@Override
public String toString() {
return "itemRecord:" + item.getUnlocalizedName() + " x " + amount;
}
protected int getOutputAmount(Recipe recipe){
for(int i = 0; i<4; i++){
if(recipe.output[i].getItem() == item && recipe.output[i].getItemDamage() == meta){
return ItemStackWrapper.getUnifiedAmount(recipe.output[i]);
}
}
return 0;
}
public boolean isSameType(ItemRecord record){
return item == record.item && meta == record.meta;
}
public boolean add(ItemRecord record){
if (isSameType(record)){
amount += record.amount;
approx = approx || record.approx;
return true;
}else {
return false;
}
}
public boolean minus(ItemRecord record){
if (isSameType(record)){
amount -= record.amount;
return true;
}else {
return false;
}
}
public boolean cancel(ItemRecord record){
if (isSameType(record)){
long i = amount>record.amount ? record.amount : amount;
amount -= i;
record.amount -= i;
if(approx || record.approx){
approx = true;
record.approx = true;
}
return i!=0;
}else {
return false;
}
}
public ItemRecord copy(){
return new ItemRecord(item, meta, amount, approx);
}
public ItemStack toItemStack(){
ItemStack itemStack = new ItemStack(item, 1, meta);
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setLong("amount", amount);
if(approx){
tagCompound.setBoolean("approx", true);
}
itemStack.setTagCompound(tagCompound);
return itemStack;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof ItemRecord){
ItemRecord record = ((ItemRecord) obj);
return record.approx == approx && record.item == item && record.amount == amount && record.meta == meta;
}else {
return false;
}
}
}
@@ -0,0 +1,322 @@
package me.towdium.jecalculation.core;
import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* @author Towdium
*/
public class ItemStackWrapper {
public static boolean isTypeEqual(ItemStack one, ItemStack two){
return one != null && two != null && one.getItem() == two.getItem() && one.getItemDamage() == two.getItemDamage();
}
public static boolean isStackEqual(ItemStack one, ItemStack two){
return ItemStack.areItemStacksEqual(one, two);
}
public static int getUnifiedAmount(ItemStack itemStack){
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
return itemStack.getTagCompound().getInteger("percentage");
}else {
return itemStack.stackSize*100;
}
}
public static String getDisplayAmount(ItemStack itemStack){
if(itemStack != null){
if(itemStack.getTagCompound() != null){
if(itemStack.getTagCompound().getBoolean("mark")){
return "";
}
long l = itemStack.getTagCompound().hasKey("amount") ? itemStack.getTagCompound().getLong("amount") : -1;
if(l == 0 && itemStack.stackSize == 0){
return "";
}
int i = itemStack.getTagCompound().getInteger("percentage");
if(i != 0){
return i + "%";
}else{
if(l==-1){
return String.valueOf(itemStack.stackSize);
}
return getSimplifiedString((l+99)/100, itemStack.getTagCompound().getBoolean("approx"));
}
}else {
return String.valueOf(itemStack.stackSize);
}
}
else return "";
}
public static ItemStack toPercentage(ItemStack itemStack){
if(itemStack == null){
return null;
}
NBT.setInt(itemStack, "percentage", itemStack.stackSize*100);
itemStack.stackSize = 1;
return itemStack;
}
public static ItemStack toNormal(ItemStack itemStack){
if(itemStack == null){
return null;
}
if(itemStack.hasTagCompound()){
int i = itemStack.getTagCompound().getInteger("percentage");
itemStack.stackSize = (i+99)/100;
itemStack.setTagCompound(null);
}else {
itemStack.stackSize = 1;
}
itemStack.setTagCompound(null);
ItemStackWrapper.NBT.setBool(itemStack, JustEnoughCalculation.Reference.MODID, true);
return itemStack;
}
public static String getSimplifiedString(long l, boolean approx){
String s;
if(approx){
if(l<999){
s = String.valueOf(l);
}else if(l<9999){
s = String.format("≈%.1fK", (double)l/1000);
}else if(l<99999){
s = String.format("≈%.0fK", (double)l/1000);
}else if(l<999999){
s = String.format("≈%.1fM", (double)l/1000000);
}else if(l<9999999){
s = String.format("≈%.1fM", (double)l/1000000);
}else if(l<99999999){
s = String.format("≈%.0fM", (double)l/1000000);
}else if(l<999999999){
s = String.format("≈%.1fB", (double)l/1000000000);
}else if(l<9999999999L){
s = String.format("≈%.1fB", (double)l/1000000000);
}else if(l<99999999999L){
s = String.format("≈%.0fB", (double)l/1000000000);
}else if(l<999999999999L){
s = String.format("≈%.1fT", (double)l/1000000000000L);
}else if(l<9999999999999L){
s = String.format("≈%.1fT", (double)l/1000000000000L);
}else if(l<99999999999999L){
s = String.format("≈%.0fT", (double)l/1000000000000L);
}else if(l<999999999999999L){
s = String.format("≈%.1fG", (double)l/1000000000000000L);
}else if(l<9999999999999999L){
s = String.format("≈%.1fG", (double)l/1000000000000000L);
}else {
s = String.format("≈%.0fG", (double)l/1000000000000000L);
}
}else {
if(l<999){
s = String.valueOf(l);
}else if(l<9999){
s = String.format("%.2fK", (double)l/1000);
}else if(l<99999){
s = String.format("%.1fK", (double)l/1000);
}else if(l<999999){
s = String.format("%.0fK", (double)l/1000);
}else if(l<9999999){
s = String.format("%.2fM", (double)l/1000000);
}else if(l<99999999){
s = String.format("%.1fM", (double)l/1000000);
}else if(l<999999999){
s = String.format("%.0fB", (double)l/1000000);
}else if(l<9999999999L){
s = String.format("%.2fB", (double)l/1000000000);
}else if(l<99999999999L){
s = String.format("%.1fB", (double)l/1000000000);
}else if(l<999999999999L){
s = String.format("%.0fT", (double)l/1000000000);
}else if(l<9999999999999L){
s = String.format("%.2fT", (double)l/1000000000000L);
}else if(l<99999999999999L){
s = String.format("%.1fT", (double)l/1000000000000L);
}else if(l<999999999999999L){
s = String.format("%.0fG", (double)l/1000000000000L);
}else if(l<9999999999999999L){
s = String.format("%.2fG", (double)l/1000000000000000L);
}else if(l<99999999999990999L){
s = String.format("%.1fG", (double)l/1000000000000000L);
}else {
s = String.format("%.0fG", (double)l/1000000000000000L);
}
}
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()){
itemStack.setTagCompound(new NBTTagCompound());
}
}
public static void setItem(ItemStack dest, String key, ItemStack content){
initNBT(dest);
NBTTagCompound buffer = new NBTTagCompound();
if (content != null){
content.writeToNBT(buffer);
dest.getTagCompound().setTag(key, buffer);
}else {
dest.getTagCompound().removeTag(key);
}
}
public static ItemStack getItem(ItemStack itemStack, String key){
NBTTagCompound tagCompound = itemStack.getTagCompound();
if(tagCompound == null){
return null;
}
NBTTagCompound itemTagCompound = tagCompound.getCompoundTag(key);
if(itemTagCompound == null){
return null;
}
return ItemStack.loadItemStackFromNBT(itemTagCompound);
}
public static void setString(ItemStack dest, String key, String value){
initNBT(dest);
dest.getTagCompound().setString(key, value);
}
public static void setInt(ItemStack dest, String key, int value){
initNBT(dest);
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);
}
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);
}
else return 0;
}
public static long getLong(ItemStack dest, String key){
if(dest.getTagCompound() != null){
return dest.getTagCompound().getLong(key);
}
else return 0;
}
}
public static class Click {
public static boolean leftClick(ItemStack itemStack, boolean doChange){
if(itemStack == null || itemStack.stackSize>=64){
return false;
}else {
if(doChange){
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("percentage")){
itemStack.getTagCompound().setInteger("percentage", itemStack.getTagCompound().getInteger("percentage")+1);
}else {
itemStack.stackSize += 1;
}
}
return true;
}
}
public static boolean leftShift(ItemStack itemStack, boolean doChange){
if(itemStack == null || itemStack.stackSize>=64){
return false;
}else {
if(doChange){
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
int i = itemStack.getTagCompound().getInteger("percentage");
itemStack.getTagCompound().setInteger("percentage", i == 1 ? 10 : i+10);
}else {
if(itemStack.stackSize == 1){
itemStack.stackSize = 10;
}else if(itemStack.stackSize <= 54){
itemStack.stackSize += 10;
}else {
itemStack.stackSize = 64;
}
}
}
return true;
}
}
public static boolean rightClick(ItemStack itemStack, boolean doChange){
if(itemStack == null){
return false;
}else {
if(doChange){
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
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){
return false;
}else {
if(doChange){
if(itemStack.hasTagCompound()&& itemStack.getTagCompound().hasKey("percentage")){
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;
}
}
}
}
@@ -0,0 +1,284 @@
package me.towdium.jecalculation.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;
/**
* @author Towdium
*/
public class Recipe {
ItemStack[] output;
ItemStack[] input;
public Recipe(ItemStack[] output, ItemStack[] input) {
if(output.length != 4 || input.length != 12){
throw new IllegalArgumentException("Incorrect array size");
}
this.output = new ItemStack[4];
for (int i = 0; i < 4; i++) {
ItemStack itemstack = output[i];
if(itemstack != null){
boolean flag = false;
for (int j = 0; j < i; j++) {
if (this.output[j] != null && ItemStackWrapper.isTypeEqual(this.output[j], itemstack)) {
this.output[j].stackSize += itemstack.stackSize;
flag = true;
break;
}
}
if (!flag) {
this.output[i] = itemstack.copy();
}
}
}
this.input = new ItemStack[12];
for (ItemStack itemstack : input) {
if(itemstack != null){
for(int i=0; i<12; i++){
if(ItemStackWrapper.isTypeEqual(this.input[i], itemstack)){
this.input[i].stackSize += itemstack.stackSize;
break;
} else if (this.input[i] == null){
this.input[i] = itemstack.copy();
break;
}
}
}
}
}
public ItemStack getOutput(ItemStack itemStack){
for(int i = 0; i<4; i++){
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
return output[i];
}
}
return null;
}
public int getOutputIndex(ItemStack itemStack){
for(int i = 0; i<4; i++){
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
for(ItemStack buffer : input){
if(ItemStackWrapper.isTypeEqual(buffer, output[i]) && ItemStackWrapper.getUnifiedAmount(output[i])<ItemStackWrapper.getUnifiedAmount(buffer)){
return -1;
}
}
return i;
}
}
return -1;
}
public int getExactInputIndex(ItemStack itemStack){
for(int i = 0; i<12; i++){
if(ItemStackWrapper.isStackEqual(input[i], itemStack)){
return i;
}
}
return -1;
}
public int getInputIndex(ItemStack itemStack){
for(int i = 0; i<12; i++){
if(ItemStackWrapper.isTypeEqual(input[i], itemStack)){
return i;
}
}
return -1;
}
public boolean getHasExactInput(ItemStack itemStack){
return getExactInputIndex(itemStack) != -1;
}
public int getOutputAmount(ItemStack itemStack){
for(int i = 0; i<4; i++){
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
return ItemStackWrapper.getUnifiedAmount(output[i]);
}
}
return 0;
}
public int getInputAmount(ItemStack itemStack){
for(int i = 0; i<12; i++){
if(ItemStackWrapper.isTypeEqual(input[i], itemStack)){
return ItemStackWrapper.getUnifiedAmount(input[i]);
}
}
return 0;
}
public boolean getHasOutput(ItemStack itemStack){
return getOutputIndex(itemStack) != -1;
}
public boolean getHasInput(ItemStack itemStack){
return getInputIndex(itemStack) != -1;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Recipe){
for(int i=0; i<4; i++){
if(!ItemStackWrapper.isStackEqual(output[i], ((Recipe)obj).output[i])){
return false;
}
}
for(int i=0; i<12; i++){
if(!ItemStackWrapper.isStackEqual(input[i], ((Recipe)obj).input[i])){
return false;
}
}
return true;
}else {
return false;
}
}
public boolean isOutputEqual(Recipe recipe){
for(int i=0; i<4; i++){
if(!ItemStackWrapper.isStackEqual(output[i], recipe.output[i])){
return false;
}
}
return true;
}
public ImmutableList<ItemStack> getOutput(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for(ItemStack itemStack : output){
if(itemStack != null){
builder.add(itemStack.copy());
}
}
return builder.build();
}
public ImmutableList<ItemStack> getInput(){
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
for(ItemStack itemStack : input){
if(itemStack != null){
builder.add(itemStack.copy());
}
}
return builder.build();
}
public boolean isApprox(){
for(ItemStack itemstack : input){
if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){
return true;
}
}
for(ItemStack itemstack : output){
if(itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("percentage")){
return true;
}
}
return false;
}
public static class ByteBufUtl{
public static Recipe fromByte(ByteBuf buf){
short a = buf.readShort();
if(a == 0){
return null;
}
short b = buf.readShort();
ItemStack[] output = new ItemStack[4];
ItemStack[] input = new ItemStack[12];
for(int i=0; i<a; i++){
output[i] = ByteBufUtils.readItemStack(buf);
}
for(int i=0; i<b; i++){
input[i] = ByteBufUtils.readItemStack(buf);
}
return new Recipe(output, input);
}
public static void toByte(ByteBuf buf, Recipe recipe){
if(recipe == null){
buf.writeShort(0);
return;
}
short a = 0;
short b = 0;
for(ItemStack itemStack : recipe.output){
if(itemStack != null){
a++;
}
}
for(ItemStack itemStack : recipe.input){
if(itemStack != null){
b++;
}
}
buf.writeShort(a);
buf.writeShort(b);
ItemStack[] output1 = recipe.output;
for (ItemStack itemStack : output1) {
if(itemStack != null){
ByteBufUtils.writeItemStack(buf, itemStack);
}
}
ItemStack[] input1 = recipe.input;
for (ItemStack itemStack : input1) {
if(itemStack != null){
ByteBufUtils.writeItemStack(buf, itemStack);
}
}
}
}
public static class NBTUtl{
public static NBTTagCompound toNBT(Recipe recipe){
NBTTagCompound tagCompound = new NBTTagCompound();
for(int i=0; i<4; i++){
if(recipe.output[i] != null){
NBTTagCompound buffer = new NBTTagCompound();
recipe.output[i].writeToNBT(buffer);
tagCompound.setTag(i+"", buffer);
}
}
for(int i=0; i<12; i++){
if(recipe.input[i] != null){
NBTTagCompound buffer = new NBTTagCompound();
recipe.input[i].writeToNBT(buffer);
tagCompound.setTag((i+4)+"", buffer);
}
}
return tagCompound;
}
public static Recipe fromNBT (NBTTagCompound tagCompound){
ItemStack[] output = new ItemStack[4];
ItemStack[] input = new ItemStack[12];
boolean inputNull = true;
boolean outputNull = true;
for(int i=0; i<4; i++){
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i));
if(buffer != null){
output[i] = ItemStack.loadItemStackFromNBT(buffer);
if(output[i] != null){
outputNull = false;
}
}
}
for(int i=0; i<12; i++){
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i+4));
if(buffer != null){
input[i] = ItemStack.loadItemStackFromNBT(buffer);
if(input[i]!= null){
inputNull = false;
}
}
}
return inputNull || outputNull ? null : new Recipe(output, input);
}
}
}
@@ -0,0 +1,97 @@
package me.towdium.jecalculation.event;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import me.towdium.jecalculation.gui.guis.calculator.GuiCalculator;
import net.minecraftforge.client.event.GuiOpenEvent;
import java.util.Date;
/**
* @author Towdium
*/
public class GuiEventHandler {
long time = new Date().getTime();
@SubscribeEvent(priority = EventPriority.HIGH)
public void onMouseClick(InputEvent.MouseInputEvent event){
/*if(event.gui instanceof GuiRecipeEditor){
if(new Date().getTime() - time < 200){
event.setCanceled(true);
return;
}
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());
slot.putStack(itemStack == null ? null : itemStack.copy());
if(Mouse.isButtonDown(0)){
time = new Date().getTime();
if(guiContainer.getSlotUnderMouse() != null){
guiContainer.setActiveSlot(guiContainer.getSlotUnderMouse().getSlotIndex());
event.gui.mc.thePlayer.playSound("random.click", 1f, 1f );
event.setCanceled(true);
return;
}
int y = guiContainer.height - Mouse.getEventY() * guiContainer.height / guiContainer.mc.displayHeight - 1;
int x = Mouse.getEventX() * guiContainer.width / guiContainer.mc.displayWidth;
boolean over = ((ItemListOverlay)JEIPlugin.runtime.getItemListOverlay()).isMouseOver(x, y);
if(!over || (y>25 && y<guiContainer.height-15)){
((GuiRecipeEditor) event.gui).setActiveSlot(-1);
event.gui.mc.thePlayer.playSound("random.click", 1f, 1f );
event.setCanceled(true);
}
}
}
}else
if(event.gui instanceof GuiCalculator){
if(new Date().getTime() - time < 200){
event.setCanceled(true);
return;
}
if (((GuiCalculator) event.gui).getActiveSlot() == 0){
Slot slot = ((GuiCalculator) event.gui).inventorySlots.getSlot(0);
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
if(itemStack != null){
itemStack = itemStack.copy();
}
if(itemStack != null){
ItemStackWrapper.NBT.initNBT(itemStack);
itemStack.getTagCompound().setBoolean("mark", true);
}
slot.putStack(itemStack == null ? null : itemStack);
if (Mouse.isButtonDown(0)){
time = new Date().getTime();
Slot slot1 = ((GuiCalculator) event.gui).getSlotUnderMouse();
if(slot1 != null){
((GuiCalculator) event.gui).setActiveSlot(slot1.getSlotIndex());
}else {
((GuiCalculator) event.gui).setActiveSlot(-1);
}
((ContainerCalculator)((GuiCalculator) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
event.setCanceled(true);
}
} else if(((GuiCalculator) event.gui).getActiveSlot() != -1) {
if (Mouse.isButtonDown(0)){
Slot slot1 = ((GuiCalculator) event.gui).getSlotUnderMouse();
if(slot1 != null){
((GuiCalculator) event.gui).setActiveSlot(slot1.getSlotIndex());
}else {
((GuiCalculator) event.gui).setActiveSlot(-1);
}
((ContainerCalculator)((GuiCalculator) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
event.setCanceled(true);
}
}
}*/
}
@SubscribeEvent
public void onOpen(GuiOpenEvent event){
if(event.gui instanceof GuiCalculator){
((GuiCalculator) event.gui).onOpen();
}
}
}
@@ -0,0 +1,32 @@
package me.towdium.jecalculation.event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.guis.calculator.ContainerCalculator;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.*;
/**
* @author Towdium
*/
public class PlayerEventHandler {
@SubscribeEvent
public void onLogin(LoadFromFile event){
JustEnoughCalculation.proxy.getPlayerHandler().handleLogin(event);
}
@SubscribeEvent
public void onSave(SaveToFile event){
JustEnoughCalculation.proxy.getPlayerHandler().handleSave(event);
}
@SubscribeEvent
public void onTooltip(ItemTooltipEvent event){
if(event.entityPlayer.openContainer instanceof ContainerCalculator){
long l = event.itemStack.hasTagCompound() ? (event.itemStack.getTagCompound().getLong("amount")+99)/100 : 0;
if(l > 999){
event.toolTip.add("Amount: " + l);
}
}
}
}
@@ -0,0 +1,43 @@
package me.towdium.jecalculation.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import me.towdium.jecalculation.gui.guis.calculator.ContainerCalculator;
import me.towdium.jecalculation.gui.guis.calculator.GuiCalculator;
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker;
import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer;
/**
* @author Towdium
*/
public class GuiHandler implements IGuiHandler {
public static final class GuiId{
public static final int CALCULATOR = 0;
public static final int RECIPE_VIEWER = 1;
public static final int RECIPE_EDITOR = 2;
public static final int RECIPE_PICKER = 3;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case GuiId.CALCULATOR: return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem()));
case GuiId.RECIPE_VIEWER: return new GuiRecipeViewer(new ContainerRecipeViewer(), null);
case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor(), null);
case GuiId.RECIPE_PICKER: return new GuiRecipePicker(new ContainerRecipe(), null, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null));
}
return null;
}
}
@@ -0,0 +1,107 @@
package me.towdium.jecalculation.gui.commom;
import codechicken.nei.guihook.GuiContainerManager;
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.renderer.texture.TextureManager;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import me.towdium.jecalculation.core.ItemStackWrapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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("jecalculation")){
boolean b = p_77021_1_.getUnicodeFlag();
p_77021_1_.setUnicodeFlag(true);
super.renderItemOverlayIntoGUI(p_77021_1_, p_77021_2_, p_77021_3_, p_77021_4_, p_77021_5_, ItemStackWrapper.getDisplayAmount(p_77021_3_));
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);
this.parent = parent;
}
@Override
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
if (slotIn != null) {
slotId = slotIn.slotNumber;
}
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
}
public void click(int mouseX, int mouseY, int mouseButton){
this.mouseClicked(mouseX, mouseY, mouseButton);
}
public void click(int index){
for(Object button : buttonList){
if(((GuiButton) button).id == index){
actionPerformed(((GuiButton) button));
}
}
}
public void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) {
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
}
public void updateLayout(){}
@Override
protected void keyTyped(char typedChar, int keyCode){
if(keyCode == 1){
mc.displayGuiScreen(parent);
}
}
@Override
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_) {}
}
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_)
}
}
@@ -0,0 +1,356 @@
package me.towdium.jecalculation.gui.commom;
import java.util.ArrayList;
import java.util.List;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* CODE IS DONE BY Zyin055
* A GuiScreen replacement that supports putting tooltips onto GuiButtons.
* SEE HERE: www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437428-guide-1-7-2-how-to-make-button-tooltips
*/
public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation implements INEIGuiHandler
{
int mousedOverButtonId = -1;
/** Show a white "?" in the top right part of any button with a tooltip assigned to it */
public static boolean ShowTooltipButtonEffect = true;
/** Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered */
public static boolean ShowTooltipButtonMouseoverEffect = true;
/** Putting this string into a tooltip will cause a line break */
public String tooltipNewlineDelimeter = "_p";
/** The amount of time in milliseconds until a tooltip is rendered */
public long tooltipDelay = 900;
/** The maximum width in pixels a tooltip can occupy before word wrapping occurs */
public int tooltipMaxWidth = 150;
protected int tooltipXOffset = 0;
protected int tooltipYOffset = 10;
private final static int LINE_HEIGHT = 11;
private long mouseoverTime = 0;
private long prevSystemTime = -1;
public GuiTooltipScreen(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
super(inventorySlotsIn, parent);
}
@Override
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
if(ShowTooltipButtonEffect)
RenderTooltipButtonEffect();
if (ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
for(Object button : buttonList){
if(((GuiButton) button).id == mousedOverButtonId){
RenderTooltipButtonMouseoverEffect(((GuiButton) button));
}
}
}
public void drawScreen(int mouseX, int mouseY, float f)
{
for (Object button : buttonList) {
if (IsButtonMouseovered(mouseX, mouseY, ((GuiButton) button))) {
mousedOverButtonId = ((GuiButton) button).id;
break;
}
}
super.drawScreen(mouseX, mouseY, f);
RenderHelper.disableStandardItemLighting();
DrawTooltipScreen(mouseX, mouseY);
/*InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
Field field;
Slot theSlot = null;
try {
field = GuiContainer.class.getDeclaredField("theSlot");
field.setAccessible(true);
theSlot = (Slot) field.get(this);
} catch (Exception ignored) {}
try {
field = GuiContainer.class.getDeclaredField("field_147006_u");
field.setAccessible(true);
theSlot = (Slot) field.get(this);
} catch (Exception ignored) {}
if (inventoryplayer.getItemStack() == null && theSlot != null && theSlot.getHasStack())
{
ItemStack itemstack1 = theSlot.getStack();
//GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true);
drawHoveringText(GuiContainerManager.itemDisplayNameMultiline(itemstack1, this, true), mouseX, mouseY, fontRendererObj);
}
RenderHelper.enableStandardItemLighting();*/
mousedOverButtonId = -1;
}
@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.
* @param buttonId The ID of the button this tooltip corresponds to
* @return The tooltip string for the specified buttonId. null if no tooltip exists for this button.
*/
protected abstract String GetButtonTooltip(int buttonId);
/**
* Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons
* that are being mouseovered.
*/
protected void DrawTooltipScreen(int mouseX, int mouseY)
{
//find out which button is being mouseovered
//calculate how long this button has been mouseovered for
if(mousedOverButtonId > -1)
{
long systemTime = System.currentTimeMillis();
if(prevSystemTime > 0)
mouseoverTime += systemTime - prevSystemTime;
prevSystemTime = systemTime;
}
else
{
mouseoverTime = 0;
}
//render the button's tooltip
if(mouseoverTime > tooltipDelay)
{
String tooltip = GetButtonTooltip(mousedOverButtonId);
if(tooltip != null)
{
RenderTooltip(mouseX, mouseY, tooltip);
}
}
}
/**
* Determines if a GuiButton is being mouseovered.
* @return true if this button is mouseovered
*/
private boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button)
{
return mouseX >= button.xPosition + button.getButtonWidth() - 10 && mouseX <= button.xPosition + button.getButtonWidth() &&
mouseY >= button.yPosition && mouseY <= button.yPosition + 10;
}
/**
* Render anything special onto all buttons that have tooltips assigned to them.
*/
private void RenderTooltipButtonEffect()
{
for (Object buttonObj : buttonList) {
GuiButton button = ((GuiButton) buttonObj);
if (GetButtonTooltip(button.id) != null) {
boolean flag = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
fontRendererObj.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7 -guiLeft, button.yPosition + 1 - guiTop, 14737632);
fontRendererObj.setUnicodeFlag(flag);
}
}
}
/**
* Render anything special onto buttons that have tooltips assigned to them when they are mousevered.
*/
private void RenderTooltipButtonMouseoverEffect(GuiButton button)
{
boolean flag = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-7 - guiLeft, button.yPosition+1 - guiTop, 14737632);
fontRendererObj.setUnicodeFlag(flag);
}
/**
* Renders a tooltip at (x,y).
*/
private void RenderTooltip(int x, int y, String tooltip)
{
String[] tooltipArray = ParseTooltipArrayFromString(tooltip);
this.drawHoveringText(ImmutableList.copyOf(tooltipArray), x, y, fontRendererObj);
}
/**
* Converts a String representation of a tooltip into a String[], and also decodes any font codes used.
* @param s Ex: "Hello,_nI am your _ltooltip_r and you love me."
* @return An array of Strings such that each String width does not exceed tooltipMaxWidth
*/
private String[] ParseTooltipArrayFromString(String s)
{
s = DecodeStringCodes(s);
String[] tooltipSections = s.split(tooltipNewlineDelimeter);
ArrayList<String> tooltipArrayList = new ArrayList();
for(String section : tooltipSections)
{
String tooltip = "";
String[] tooltipWords = section.split(" ");
for (String tooltipWord : tooltipWords) {
int lineWidthWithNextWord = mc.fontRenderer.getStringWidth(tooltip + tooltipWord);
if (lineWidthWithNextWord > tooltipMaxWidth) {
tooltipArrayList.add(tooltip.trim());
tooltip = tooltipWord + " ";
} else {
tooltip += tooltipWord + " ";
}
}
tooltipArrayList.add(tooltip.trim());
}
String[] tooltipArray = new String[tooltipArrayList.size()];
tooltipArrayList.toArray(tooltipArray);
return tooltipArray;
}
/**
* Decodes any font codes into something useable by the fontRendererObj.
* @param s E.x.: "Hello,_nI am your _ltooltip_r and you love me."
* @return E.x. output (html not included): <br>"Hello,<br>I am your <b>tooltip</b> and you love me."
*/
private String DecodeStringCodes(String s)
{
return s.replace("_0", FontCodes.BLACK)
.replace("_1", FontCodes.DARK_BLUE)
.replace("_2", FontCodes.DARK_GREEN)
.replace("_3", FontCodes.DARK_AQUA)
.replace("_4", FontCodes.DARK_RED)
.replace("_5", FontCodes.DARK_PURPLE)
.replace("_6", FontCodes.GOLD)
.replace("_7", FontCodes.GRAY)
.replace("_8", FontCodes.DARK_GREY)
.replace("_9", FontCodes.BLUE)
.replace("_a", FontCodes.GREEN)
.replace("_b", FontCodes.AQUA)
.replace("_c", FontCodes.RED)
.replace("_d", FontCodes.LIGHT_PURPLE)
.replace("_e", FontCodes.YELLOW)
.replace("_f", FontCodes.WHITE)
.replace("_k", FontCodes.OBFUSCATED)
.replace("_l", FontCodes.BOLD)
.replace("_m", FontCodes.STRIKETHROUGH)
.replace("_n", FontCodes.UNDERLINE)
.replace("_o", FontCodes.ITALICS)
.replace("_r", FontCodes.RESET);
}
/***
* Gets the width of the tooltip in pixels.
*/
private int GetTooltipWidth(String[] tooltipArray)
{
int longestWidth = 0;
for(String s : tooltipArray)
{
int width = mc.fontRenderer.getStringWidth(s);
if(width > longestWidth)
longestWidth = width;
}
return longestWidth;
}
/**
* Gets the height of the tooltip in pixels.
*/
private int GetTooltipHeight(String[] tooltipArray)
{
int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2;
if (tooltipArray.length > 1)
{
tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
}
return tooltipHeight;
}
@Override
public VisiblityData modifyVisiblity(GuiContainer guiContainer, VisiblityData visiblityData) {
return null;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer guiContainer, ItemStack itemStack) {
return new ArrayList<>();
}
@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
{
//color codes for rendered strings
public static final String BLACK = "\2470";
public static final String DARK_BLUE = "\2471";
public static final String DARK_GREEN = "\2472";
public static final String DARK_AQUA = "\2473";
public static final String DARK_RED = "\2474";
public static final String DARK_PURPLE = "\2475";
public static final String GOLD = "\2476";
public static final String GRAY = "\2477";
public static final String DARK_GREY = "\2478";
public static final String BLUE = "\2479";
public static final String GREEN = "\247a";
public static final String AQUA = "\247b";
public static final String RED = "\247c";
public static final String LIGHT_PURPLE = "\247d";
public static final String YELLOW = "\247e";
public static final String WHITE = "\247f";
//font styles
public static final String OBFUSCATED = "\247k";
public static final String BOLD = "\247l";
public static final String STRIKETHROUGH = "\247m";
public static final String UNDERLINE = "\247n";
public static final String ITALICS = "\247o";
public static final String RESET = "\247r";
}
}
@@ -0,0 +1,113 @@
package me.towdium.jecalculation.gui.commom.recipe;
import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import me.towdium.jecalculation.core.ItemStackWrapper;
import me.towdium.jecalculation.core.Recipe;
/**
* @author Towdium
*/
public class ContainerRecipe extends Container {
public ContainerRecipe(){
InventoryRecipe inventoryRecipe = new InventoryRecipe();
int i, left, top;
i = 0; left = 9; top = 9;
for(int a = 0; a < 2; a++){
for(int b =0; b < 2; b++){
addSlotToContainer(new Slot(inventoryRecipe,i+2*a+b,left+b*59,top+a*24));
}
}
i = 4; left = 9; top = 69;
for(int a = 0; a < 4; a++){
for(int b =0; b < 3; b++){
addSlotToContainer(new Slot(inventoryRecipe,i+3*a+b,left+b*59,top+a*24));
}
}
}
@Override
public Slot getSlot(int p_75139_1_) {
if(p_75139_1_ <= 15)
return super.getSlot(p_75139_1_);
else
return null;
}
@Override
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
}
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
if(slotId<0 || slotId>=16){
return null;
}
Slot slot = getSlot(slotId);
if(slot != null){
ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex());
if(itemStack != null){
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;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
return null;
}
public Recipe buildRecipe(){
ItemStack[] output = new ItemStack[4];
boolean flag1 = false, flag2 = false;
for(int i=0; i<4; i++){
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++){
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;
}
}
return flag1 && flag2 ? new Recipe(output, input) : null;
}
}
@@ -0,0 +1,175 @@
package me.towdium.jecalculation.gui.commom.recipe;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.core.Recipe;
import me.towdium.jecalculation.gui.commom.GuiTooltipScreen;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import me.towdium.jecalculation.core.ItemStackWrapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* @author Towdium
*/
public class GuiRecipe extends GuiTooltipScreen {
private int activeSlot = -1;
public GuiRecipe(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
super(inventorySlotsIn, parent);
}
@Override
public void initGui() {
super.initGui();
int i, left, top;
i = 0; left = 31 + guiLeft; top = 7 + guiTop;
for(int a = 0; a < 2; a++){
for(int b =0; b < 2; b++){
buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "#"));
}
}
i = 4; left = 31 + guiLeft; top = 67 + guiTop;
for(int a = 0; a < 4; a++){
for(int b =0; b < 3; b++){
buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "#"));
}
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipe.png"));
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
if(activeSlot != -1){
Slot slot = inventorySlots.getSlot(activeSlot);
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
}
}
@Override
protected void actionPerformed(GuiButton button){
int buttonId = button.id;
if(buttonId <= 15){
Slot slot = inventorySlots.getSlot(buttonId);
if(button.displayString.equals("#")){
slot.putStack(ItemStackWrapper.toPercentage(slot.getStack()));
button.displayString = "%";
}else {
slot.putStack(ItemStackWrapper.toNormal(slot.getStack()));
button.displayString = "#";
}
}
}
/*@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
super.mouseClicked(mouseX, mouseY, mouseButton);
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) {
if (keyCode == 1) {
if(activeSlot != -1){
setActiveSlot(-1);
}else {
super.keyTyped(typedChar, keyCode);
}
}
}
@Override
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
boolean b = false;
if(slotIn != null){
b = slotIn.getHasStack();
}
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
if(slotIn != null && b && !slotIn.getHasStack()){
((GuiButton) buttonList.get(slotIn.getSlotIndex())).displayString = "#";
}
}
public int getActiveSlot() {
return activeSlot;
}
public void setActiveSlot(int activeSlot) {
this.activeSlot = activeSlot;
}
public void displayRecipe(Recipe recipe){
List<ItemStack> output = recipe.getOutput();
List<ItemStack> input = recipe.getInput();
for(int i=0; i<4; i++){
if(i<output.size()){
ItemStack itemStack = output.get(i);
this.inventorySlots.getSlot(i).putStack(itemStack);
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);
}
}
for(int i=0; i<12; i++){
if(i<input.size()){
ItemStack itemStack = input.get(i);
this.inventorySlots.getSlot(i+4).putStack(itemStack);
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);
}
}
}
@Override
protected String GetButtonTooltip(int buttonId) {
if(buttonId == 0){
return StatCollector.translateToLocal("gui.calculator.tooltipUse");
}else {
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, "jecalculation", true);
buffer.stackSize=1;
Slot slot = getSlotUnderMouse(i, i1);
if(slot!=null){
slot.putStack(buffer);
itemStack.stackSize=0;
}
return false;
}
}
@@ -0,0 +1,12 @@
package me.towdium.jecalculation.gui.commom.recipe;
import net.minecraft.inventory.InventoryBasic;
/**
* @author Towdium
*/
public class InventoryRecipe extends InventoryBasic {
public InventoryRecipe() {
super("Recipe", false, 16);
}
}
@@ -0,0 +1,65 @@
package me.towdium.jecalculation.gui.guis.calculator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* @author Towdium
*/
public class ContainerCalculator extends Container {
EntityPlayer player;
InventoryCalculator inventoryCalculator;
public ContainerCalculator(EntityPlayer player, ItemStack itemCalculator){
this.player = player;
this.inventoryCalculator = new InventoryCalculator(itemCalculator);
addSlotToContainer(new Slot(inventoryCalculator, 0,9,9));
int i, left, top;
i = 1; left = 8; top = 80;
for(int a = 0; a < 3; a++){
for(int b =0; b < 9; b++){
addSlotToContainer(new Slot(inventoryCalculator,i+9*a+b,left+b*18,top+a*18));
}
}
i = 28; left = 8; top = 32;
for(int a = 0; a < 1; a++){
for(int b =0; b < 6; b++){
addSlotToContainer(new Slot(inventoryCalculator,i+9*a+b,left+b*18,top+a*18));
}
}
}
@Override
public Slot getSlot(int p_75139_1_) {
if(p_75139_1_ <= 33)
return super.getSlot(p_75139_1_);
else
return null;
}
@Override
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
return null;
}
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
return null;
}
public EntityPlayer getPlayer() {
return player;
}
}
@@ -0,0 +1,495 @@
package me.towdium.jecalculation.gui.guis.calculator;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
import me.towdium.jecalculation.network.packets.PacketSyncRecord;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import me.towdium.jecalculation.core.Calculator;
import me.towdium.jecalculation.core.CostRecord;
import me.towdium.jecalculation.core.ItemStackWrapper;
import me.towdium.jecalculation.gui.commom.GuiTooltipScreen;
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
import me.towdium.jecalculation.gui.guis.recipePicker.GuiRecipePicker;
import me.towdium.jecalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
import me.towdium.jecalculation.gui.guis.recipeViewer.GuiRecipeViewer;
import java.util.*;
/**
* @author Towdium
*/
public class GuiCalculator extends GuiTooltipScreen{
static int recentLen = 6;
GuiTextField textFieldAmount;
GuiButton buttonLeft;
GuiButton buttonRight;
GuiButton buttonEdit;
GuiButton buttonMode;
//GuiButton buttonCalculate;
GuiButton buttonView;
CostRecord costRecord;
Map<Integer, Integer> items;
int activeSlot = -1;
int page = 1;
int total = 0;
EnumMode mode = EnumMode.INPUT;
ItemStack buffer;
boolean init = false;
public enum EnumMode {
INPUT, PROCEDURE, OUTPUT, CATALYST;
int toInt(){
switch (this){
case INPUT:
return 1;
case PROCEDURE:
return 2;
case OUTPUT:
return 3;
case CATALYST:
return 4;
default:
return 1;
}
}
static EnumMode fromInt(int i){
switch (i){
case 1:
return INPUT;
case 2:
return PROCEDURE;
case 3:
return OUTPUT;
case 4:
return CATALYST;
default:
return INPUT;
}
}
}
public GuiCalculator(ContainerCalculator containerCalculator){
super(containerCalculator, null);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord());
items = new HashMap<>(27);
}
@Override
public void initGui() {
super.initGui();
buttonLeft = new GuiButton(4, guiLeft+7, guiTop+139, 20, 20, "<");
buttonRight = new GuiButton(5, guiLeft+65, guiTop+139, 20, 20, ">");
buttonEdit = new GuiButton(3, guiLeft+7, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.edit"));
//buttonCalculate = new GuiButton(1, guiLeft+111, guiTop+7, 58, 20, StatCollector.translateToLocal("gui.calculator.calculate"));
buttonView = new GuiButton(7, guiLeft+90, guiTop+53, 79, 20, StatCollector.translateToLocal("gui.calculator.view"));
//buttonList.add(buttonCalculate);
buttonList.add(new GuiButton(2, guiLeft+101, guiTop+7, 68, 20, StatCollector.translateToLocal("gui.calculator.add")));
buttonList.add(buttonEdit);
buttonList.add(buttonView);
buttonList.add(buttonLeft);
buttonList.add(buttonRight);
buttonMode = new GuiButton(6, guiLeft+89, guiTop+139, 80, 20, StatCollector.translateToLocal("gui.calculator.input"));
buttonList.add(buttonMode);
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft+39, guiTop+8, 57, 18);
Slot dest = inventorySlots.getSlot(0);
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
ItemStack calculatorItem = ((ContainerCalculator) inventorySlots).getPlayer().getHeldItem();
for(int i=0; i<recentLen; i++){
inventorySlots.getSlot(28+i).putStack(ItemStackWrapper.NBT.getItem(calculatorItem, "recent"+i));
}
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
mode = EnumMode.fromInt(ItemStackWrapper.NBT.getInt(calculatorItem, "mode"));
init = true;
onOpen();
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;
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiCalculator.png"));
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
if(activeSlot == 0){
Slot slot = inventorySlots.getSlot(activeSlot);
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
}else if(activeSlot > 0){
Slot slot = inventorySlots.getSlot(activeSlot);
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-1, this.guiTop+slot.yDisplayPosition-1, 196, 0, 18, 18);
}
textFieldAmount.drawTextBox();
drawMissingTexture();
}
@Override
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
fontRendererObj.drawString("x", 30, 13, 4210752);
drawCenteredStringWithoutShadow(fontRendererObj, StatCollector.translateToLocal("gui.calculator.recent"), 143, 36, 4210752);
drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 0xFFFFFF);
}
@Override
protected String GetButtonTooltip(int buttonId) {
switch (buttonId){
case 2: return StatCollector.translateToLocal("gui.calculator.addTooltip");
case 3: return StatCollector.translateToLocal("gui.calculator.editTooltip");
case 6: return StatCollector.translateToLocal("gui.calculator.modeTooltip");
case 7: return StatCollector.translateToLocal("gui.calculator.viewTooltip");
}
return null;
}
@Override
protected void actionPerformed(GuiButton button){
switch (button.id){
/*case 1:
if(inventorySlots.getSlot(0).getStack() != null){
mode = EnumMode.INPUT;
refreshRecipe();
}
break;*/
case 2:
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this));
break;
case 3:
List<Integer> list;
if (activeSlot == -1) {
list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(0).getStack(), null);
}else {
list = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndexOf(inventorySlots.getSlot(activeSlot).getStack(), null);
}
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:
mode = EnumMode.PROCEDURE;
break;
case PROCEDURE:
mode = EnumMode.OUTPUT;
break;
case OUTPUT:
mode = EnumMode.CATALYST;
break;
case CATALYST:
mode = EnumMode.INPUT;
break;
}
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt());
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
page = 1;
break;
case 7:
mc.displayGuiScreen(new GuiRecipeViewer(new ContainerRecipeViewer(), this));
break;
}
updateLayout();
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
//+JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
textFieldAmount.mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
if(mouseButton == 1 && buttonMode.mousePressed(mc, mouseX, mouseY)){
switch (mode){
case INPUT:
mode = EnumMode.CATALYST;
break;
case PROCEDURE:
mode = EnumMode.INPUT;
break;
case OUTPUT:
mode = EnumMode.PROCEDURE;
break;
case CATALYST:
mode = EnumMode.OUTPUT;
break;
}
mc.thePlayer.playSound("random.click", 0.8f, 0.8f );
updateLayout();
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
ItemStackWrapper.NBT.setInt(calculatorItem, "mode", mode.toInt());
}
Slot s = getSlotUnderMouse(mouseX,mouseY);
if(s != null && s.getSlotIndex() > 27 && s.getStack() != null){
inventorySlots.getSlot(0).putStack(s.getStack());
mode = EnumMode.INPUT;
refreshRecipe();
updateLayout();
}else if(s != null && s.getSlotIndex() > 0 && s.getSlotIndex() <= 27 && s.getStack() != null){
GuiCraftingRecipe.openRecipeGui("item", s.getStack().copy());
}
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
//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){
if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)){
if(keyCode == 1){
if(activeSlot != -1){
inventorySlots.getSlot(activeSlot).putStack(buffer);
setActiveSlot(-1);
}else {
super.keyTyped(typedChar, keyCode);
}
}
} else {
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
refreshRecipe();
updateLayout();
}
}
public void updateLayout(){
switch (mode){
case OUTPUT:
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.output");
break;
case PROCEDURE:
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.procedure");
break;
case INPUT:
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.input");
break;
case CATALYST:
buttonMode.displayString = StatCollector.translateToLocal("gui.calculator.catalyst");
break;
}
boolean b = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null);
if(activeSlot == -1){
buttonEdit.enabled = b;
}else {
buttonEdit.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(activeSlot).getStack(), null);
}
//buttonCalculate.enabled = b;
buttonView.enabled = JustEnoughCalculation.proxy.getPlayerHandler().getHasRecipe(null);
if(costRecord != null){
switch (mode){
case OUTPUT:
total = (costRecord.getOutputStack().size()+26)/27;
fillSlotsWith(costRecord.getOutputStack(), (page-1)*27);break;
case PROCEDURE:
total = (costRecord.getProcedureStack().size()+26)/27;
fillSlotsWith(costRecord.getProcedureStack(), (page-1)*27);break;
case INPUT:
total = (costRecord.getInputStack().size()+26)/27;
fillSlotsWith(costRecord.getInputStack(), (page-1)*27);break;
case CATALYST:
total = (costRecord.getCatalystStack().size()+26)/27;
fillSlotsWith(costRecord.getCatalystStack(), (page-1)*27);break;
}
}else {
fillSlotsWith(new ArrayList<ItemStack>(), 0);
total = 0;
}
buttonLeft.enabled = page != 1;
buttonRight.enabled = page < total;
if(JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()){
checkItem();
}
}
public int getActiveSlot() {
return activeSlot;
}
public void setActiveSlot(int activeSlot) {
if(activeSlot == -1){
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
}else {
buffer = inventorySlots.getSlot(activeSlot).getStack();
}
this.activeSlot = activeSlot;
updateLayout();
}
public void onOpen(){
if(inventorySlots.getSlot(0).getStack() != null){
refreshRecipe();
}
if(init){
updateLayout();
}
}
protected void fillSlotsWith(List<ItemStack> itemStacks, int start){
int pos = 1;
for(int i=start; i<start+27; i++){
if(i<=itemStacks.size()-1){
ItemStack buffer = itemStacks.get(i);
ItemStackWrapper.NBT.setBool(buffer, JustEnoughCalculation.Reference.MODID, true);
inventorySlots.getSlot(pos++).putStack(buffer);
}else {
inventorySlots.getSlot(pos++).putStack(null);
}
}
}
protected void refreshRecipe(){
ItemStack dest = inventorySlots.getSlot(0).getStack();
int i;
try{
i = Integer.valueOf(textFieldAmount.getText());
} catch ( NumberFormatException e ){
i = 1;
textFieldAmount.setTextColor(16711680);
TimerTask r = new TimerTask() {
@Override
public void run() {
textFieldAmount.setTextColor(14737632);
}
};
Timer t = new Timer();
t.schedule(r, 1000);
if(inventorySlots.getSlot(0).getStack() == null) {
return;
}
}
if(dest == null) {
return;
}
Calculator calculator = new Calculator(dest, i*100);
costRecord = calculator.getCost();
dest = dest.copy();
dest.getTagCompound().removeTag(JustEnoughCalculation.Reference.MODID);
ItemStack calculatorItem = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
ItemStack[] stack = new ItemStack[6];
for(int j=0; j<recentLen; j++){
stack[j] = ItemStackWrapper.NBT.getItem(calculatorItem, "recent"+j);
}
int duplicate = -1;
for(int j=0; j<recentLen; j++){
if(stack[j] != null && ItemStackWrapper.isTypeEqual(dest, stack[j])){
duplicate = j;
}
}
if(duplicate == -1){
ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest);
inventorySlots.getSlot(28).putStack(dest);
for(int j=0; j<recentLen-1; j++){
ItemStackWrapper.NBT.setItem(calculatorItem, "recent"+(j+1), stack[j]);
inventorySlots.getSlot(27+2+j).putStack(stack[j]);
}
}else {
ItemStackWrapper.NBT.setItem(calculatorItem, "recent0", dest);
inventorySlots.getSlot(28).putStack(dest);
for(int j=0; j<duplicate; j++){
ItemStackWrapper.NBT.setItem(calculatorItem, "recent"+(j+1), stack[j]);
inventorySlots.getSlot(27+2+j).putStack(stack[j]);
}
}
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(dest, textFieldAmount.getText());
}
protected void drawMissingTexture(){
for(int i=0; i<27; i++){
Slot slot = inventorySlots.getSlot(i+1);
if(items.containsKey(i)){
int store = items.get(i);
int a = store == 0 ? 0 : store*0x8000000+0x12ff0000;
drawRect(slot.xDisplayPosition+guiLeft-1, slot.yDisplayPosition+guiTop-1, slot.xDisplayPosition+guiLeft+17, slot.yDisplayPosition+guiTop+17, a);
}
}
}
protected void checkItem(){
if(mode != EnumMode.INPUT){
for(int i=0; i<27; i++){
items.put(i, 0);
}
return;
}
for(int i=0; i<27; i++){
ItemStack itemStack = inventorySlots.getSlot(i+1).getStack();
if(itemStack == null){
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);
}
}
@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);
mode = EnumMode.INPUT;
refreshRecipe();
updateLayout();
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
}
itemStack.stackSize=0;
return false;
}
}
@@ -0,0 +1,14 @@
package me.towdium.jecalculation.gui.guis.calculator;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack;
/**
* @author Towdium
*/
public class InventoryCalculator extends InventoryBasic{
public InventoryCalculator(ItemStack itemStack) {
super("Calculator", false, 37);
}
}
@@ -0,0 +1,10 @@
package me.towdium.jecalculation.gui.guis.recipeEditor;
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
/**
* @author Towdium
*/
public class ContainerRecipeEditor extends ContainerRecipe {
}
@@ -0,0 +1,68 @@
package me.towdium.jecalculation.gui.guis.recipeEditor;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.inventory.Slot;
import net.minecraft.util.StatCollector;
import me.towdium.jecalculation.core.Recipe;
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
/**
* @author Towdium
*/
public class GuiRecipeEditor extends GuiRecipe{
int index = -1;
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent, int index){
super(containerRecipeEditor, parent);
this.index = index;
}
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent){
super(containerRecipeEditor, parent);
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
super.drawScreen(mouseX, mouseY, f);
}
@Override
public void initGui() {
super.initGui();
buttonList.add(new GuiButton(16, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.save")));
buttonList.add(new GuiButton(17, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.clear")));
if(index != -1){
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(index, null));
}
}
@Override
protected void actionPerformed(GuiButton button){
super.actionPerformed(button);
int buttonId = button.id;
if(buttonId == 16) {
Recipe recipe = ((ContainerRecipe)inventorySlots).buildRecipe();
if(recipe == null){
mc.displayGuiScreen(parent);
return;
}
if(index == -1){
JustEnoughCalculation.proxy.getPlayerHandler().addRecipe(recipe, null);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, -1));
mc.displayGuiScreen(parent);
}else {
JustEnoughCalculation.proxy.getPlayerHandler().setRecipe(recipe, index, null);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(recipe, index));
mc.displayGuiScreen(parent);
}
}else if(buttonId == 17) {
for(Object slot : inventorySlots.inventorySlots){
((Slot) slot).inventory.setInventorySlotContents(((Slot) slot).getSlotIndex(), null);
}
}
}
}
@@ -0,0 +1,86 @@
package me.towdium.jecalculation.gui.guis.recipePicker;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.StatCollector;
import me.towdium.jecalculation.gui.commom.recipe.ContainerRecipe;
import me.towdium.jecalculation.gui.commom.recipe.GuiRecipe;
import java.util.List;
/**
* @author Towdium
*/
public class GuiRecipePicker extends GuiRecipe{
protected List<Integer> recipes;
protected int index;
protected GuiButton buttonLeft;
protected GuiButton buttonRight;
public GuiRecipePicker(ContainerRecipe containerRecipe, GuiScreen parent, List<Integer> recipes){
super(containerRecipe, parent);
this.recipes = recipes;
}
@Override
public void initGui() {
super.initGui();
buttonLeft = new GuiButton(16, guiLeft+125, guiTop+7, 20, 20, "<");
buttonRight = new GuiButton(17, guiLeft+149, guiTop+7, 20, 20, ">");
buttonList.add(buttonLeft);
buttonList.add(buttonRight);
buttonList.add(new GuiButton(18, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipePicker.delete")));
updateLayout();
}
@Override
protected void actionPerformed(GuiButton button){
super.actionPerformed(button);
int buttonId = button.id;
if(buttonId>=0 && buttonId<=15){
GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index));
mc.displayGuiScreen(recipeEditor);
recipeEditor.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
recipeEditor.click(buttonId);
}else if(buttonId == 16) {
if(index>0){
index--;
updateLayout();
}
}else if(buttonId == 17) {
if(index<recipes.size()-1){
index++;
updateLayout();
}
}else if(buttonId == 18) {
JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get(index), null);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get(index)));
mc.displayGuiScreen(parent);
}
}
/*@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton){
super.mouseClicked(mouseX, mouseY, mouseButton);
Slot slot = getSlotUnderMouse(mouseX, mouseY);
if(slot != null){
GuiRecipeEditor recipeEditor = new GuiRecipeEditor(new ContainerRecipeEditor(), parent, recipes.get(index));
mc.displayGuiScreen(recipeEditor);
recipeEditor.displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
recipeEditor.click(mouseX, mouseY, mouseButton);
if(slot.getStack() == null){
recipeEditor.setActiveSlot(slot.getSlotIndex());
}
}
}*/
public void updateLayout(){
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null));
buttonRight.enabled = index != recipes.size() - 1;
buttonLeft.enabled = index != 0;
}
}
@@ -0,0 +1,51 @@
package me.towdium.jecalculation.gui.guis.recipeViewer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* @author Towdium
*/
public class ContainerRecipeViewer extends Container {
InventoryBasic inventory = new InventoryBasic("RecipeViewer", false, 24);
public ContainerRecipeViewer(){
int i, left, top;
i = 0; left = 8; top = 8;
for(int a = 0; a < 6; a++){
for(int b =0; b < 4; b++){
addSlotToContainer(new Slot(inventory,i+4*a+b,left+b*18,top+a*22));
}
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
return null;
}
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
return null;
}
@Override
public Slot getSlot(int p_75139_1_) {
if(p_75139_1_ <= 23)
return super.getSlot(p_75139_1_);
else
return null;
}
@Override
public void putStackInSlot(int p_75141_1_, ItemStack p_75141_2_) {
}
}
@@ -0,0 +1,140 @@
package me.towdium.jecalculation.gui.guis.recipeViewer;
import cpw.mods.fml.client.config.GuiButtonExt;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
import me.towdium.jecalculation.gui.guis.recipeEditor.GuiRecipeEditor;
import me.towdium.jecalculation.network.packets.PacketRecipeUpdate;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import me.towdium.jecalculation.core.ItemStackWrapper;
import me.towdium.jecalculation.core.Recipe;
import me.towdium.jecalculation.gui.commom.GuiJustEnoughCalculation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* @author Towdium
*/
public class GuiRecipeViewer extends GuiJustEnoughCalculation {
List<Integer> recipes;
GuiButton buttonLeft;
GuiButton buttonRight;
int page = 1;
int total;
public GuiRecipeViewer (@Nonnull ContainerRecipeViewer container, @Nullable GuiScreen parent){
super(container, parent);
}
@Override
public void initGui() {
super.initGui();
buttonLeft = new GuiButton(0, guiLeft+7, guiTop+139, 20, 20, "<");
buttonRight = new GuiButton(1, guiLeft+149, guiTop+139, 20, 20, ">");
buttonList.add(buttonLeft);
buttonList.add(buttonRight);
for(int i=0; i<6; i++){
buttonList.add(new GuiButtonExt(2+2*i, guiLeft+83, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.edit")));
buttonList.add(new GuiButtonExt(3+2*i, guiLeft+128, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.delete")));
}
updateLayout();
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipeViewer.png"));
drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
drawCenteredString(fontRendererObj, page + "/" + total, 88, 145, 0xFFFFFF);
}
@Override
public void updateLayout() {
recipes = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null);
total = recipes == null ? 0 : (recipes.size()+5)/6;
if(page>total && page != 1){
page = total;
}
displayRecipes();
for(int i=0; i<6; i++){
boolean flag = recipes.size() > (page-1)*6+i;
((GuiButton) buttonList.get(2 + 2 * i)).enabled = flag;
((GuiButton) buttonList.get(3 + 2 * i)).enabled = flag;
}
buttonLeft.enabled = page != 1;
buttonRight.enabled = page < total;
}
@Override
protected void actionPerformed(GuiButton button){
int i = button.id;
switch (i){
case 0:
page--;
updateLayout();
break;
case 1:
page++;
updateLayout();
break;
default:
if(i%2 == 0){
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this, recipes.get((page-1)*6+i/2-1)));
}else{
JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get((page-1)*6+i/2-1), null);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get((page-1)*6+i/2-1)));
updateLayout();
}
}
}
/**
* display the recipe at the position
* @param position range 1-6
*/
public void displayRecipe(@Nullable Recipe recipe, int position){
if(recipe != null){
List<ItemStack> items = recipe.getOutput();
for(int i=0; i<4; i++){
if(i<items.size()){
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);
}
}
}else {
for(int i=0; i<4; i++){
inventorySlots.getSlot((position-1)*4+i).putStack(null);
}
}
}
public void displayRecipes(){
if(recipes != null){
for(int i=1; i<=6; i++){
int index = i-1+6*(page-1);
if(index<recipes.size()){
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null), i);
}else {
displayRecipe(null, i);
}
}
}else {
for(int i=1; i<=6; i++){
displayRecipe(null, i);
}
}
}
}
@@ -0,0 +1,27 @@
package me.towdium.jecalculation.item;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.GuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* @author Towdium
*/
public class ItemCalculator extends Item {
public ItemCalculator() {
setMaxStackSize(1);
}
@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;
}
}
@@ -0,0 +1,47 @@
package me.towdium.jecalculation.network;
import com.google.common.collect.ImmutableList;
import me.towdium.jecalculation.core.Recipe;
import net.minecraft.item.ItemStack;
import java.util.UUID;
/**
* @author Towdium
*/
public interface IPlayerHandler {
boolean getHasRecipeOf(ItemStack itemStack, UUID uuid);
Recipe getRecipeOf(ItemStack itemStack, UUID uuid);
ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid);
int getRecipeIndexOf(ItemStack itemStack, UUID uuid);
ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid);
void addRecipe(Recipe recipe, UUID uuid);
void removeRecipe(int index, UUID uuid);
void setRecipe(Recipe recipe, int index, UUID uuid);
Recipe getRecipe(int index, UUID uuid);
void syncItemCalculator(ItemStack itemIn, String string);
void handleLogin(net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile event);
void handleSave(net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile event);
boolean removeRecipe(Recipe recipe, UUID uuid);
boolean containsRecipe(Recipe recipe, UUID uuid);
boolean getHasRecipe(UUID uuid);
ImmutableList<Recipe> getAllRecipe(UUID uuid);
ImmutableList<Integer> getAllRecipeIndex(UUID uuid);
}
@@ -0,0 +1,14 @@
package me.towdium.jecalculation.network;
/**
* @author Towdium
*/
public interface IProxy {
IPlayerHandler getPlayerHandler();
void init();
}
@@ -0,0 +1,211 @@
package me.towdium.jecalculation.network;
import com.google.common.collect.ImmutableList;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.core.ItemStackWrapper;
import me.towdium.jecalculation.core.Recipe;
import me.towdium.jecalculation.network.packets.PacketCalculatorUpdate;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.player.PlayerEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author Towdium
*/
public class PlayerHandlerClient implements IPlayerHandler {
public List<Recipe> recipes = new ArrayList();
@Override
public void addRecipe(Recipe recipe, UUID uuid) {
for (Recipe oneRecipe : recipes){
if(oneRecipe.equals(recipe)){
return;
}
}
if(recipe != null){
recipes.add(recipe);
}
}
@Override
public boolean getHasRecipe(UUID uuid) {
return recipes.size()!=0;
}
@Override
public ImmutableList<Integer> getAllRecipeIndex(UUID uuid) {
int a = recipes.size();
ImmutableList.Builder<Integer> builder = new ImmutableList.Builder();
for (int i = 0; i<a; i++){
builder.add(i);
}
return builder.build();
}
@Override
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
if(itemStack == null){
return false;
}
for (Recipe recipe : recipes){
if(recipe.getHasOutput(itemStack)){
return true;
}
}
return false;
}
@Override
public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) {
int i = getRecipeIndexOf(itemStack, null);
if(i == -1){
return null;
}else {
return recipes.get(i);
}
}
@Override
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder();
for(Integer index : getAllRecipeIndexOf(itemStack, null)){
recipeBuilder.add(recipes.get(index));
}
return recipeBuilder.build();
}
@Override
public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) {
int[] result = new int[]{-1, -1, -1, -1};
for(int[] record : getAllUnsortedRecipeIndexOf(itemStack)){
result[record[1]] = record[0];
}
for (int index : result) {
if (index != -1) {
return index;
}
}
return -1;
}
@Override
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) {
ImmutableList.Builder<ImmutableList.Builder<Integer>> builder1 = new ImmutableList.Builder<>();
for(int i=0; i<4; i++){
builder1.add(new ImmutableList.Builder<Integer>());
}
ImmutableList<ImmutableList.Builder<Integer>> resultBuffer = builder1.build();
for(int[] result : getAllUnsortedRecipeIndexOf(itemStack)){
resultBuffer.get(result[1]).add(result[0]);
}
ImmutableList.Builder<Integer> builder2 = new ImmutableList.Builder<>();
for(ImmutableList.Builder<Integer> priority : resultBuffer){
builder2.addAll(priority.build().reverse());
}
return builder2.build();
}
@Override
public void removeRecipe(int index, UUID uuid) {
recipes.remove(index);
}
@Override
public void setRecipe(Recipe recipe, int index, UUID uuid) {
recipes.set(index, recipe);
}
@Override
public Recipe getRecipe(int index, UUID uuid) {
return index<recipes.size() ? recipes.get(index) : null;
}
@Override
public void syncItemCalculator(ItemStack itemIn, String string) {
ItemStack itemStack = Minecraft.getMinecraft().thePlayer.getHeldItem();
ItemStackWrapper.NBT.setItem(itemStack, "dest",itemIn );
ItemStackWrapper.NBT.setString(itemStack, "text", string);
JustEnoughCalculation.networkWrapper.sendToServer(new PacketCalculatorUpdate(itemStack));
}
@Override
public void handleLogin(PlayerEvent.LoadFromFile event) {
try {
FileInputStream stream = new FileInputStream(event.getPlayerFile("jeca"));
NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(stream);
readFromNBT(tagCompound);
} catch (Exception e) {
recipes = new ArrayList<>();
}
}
@Override
public void handleSave(PlayerEvent.SaveToFile event) {
try{
File file = event.getPlayerFile("jeca");
NBTTagCompound compound = new NBTTagCompound();
writeToNBT(compound);
FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(compound, fileoutputstream);
}catch (Exception e){
JustEnoughCalculation.log.warn("Fail to save records for"+event.entityPlayer.getDisplayName());
}
}
@Override
public boolean removeRecipe(Recipe recipe, UUID uuid) {
return recipes.remove(recipe);
}
@Override
public boolean containsRecipe(Recipe recipe, UUID uuid) {
return recipes.contains(recipe);
}
@Override
public ImmutableList<Recipe> getAllRecipe(UUID uuid) {
return ImmutableList.copyOf(recipes);
}
ImmutableList<int[]> getAllUnsortedRecipeIndexOf(ItemStack itemStack){
ImmutableList.Builder<int[]> builder = new ImmutableList.Builder<>();
int size = recipes.size();
int buffer;
for(int i = 0; i<size; i++){
buffer = recipes.get(i).getOutputIndex(itemStack);
if(buffer != -1){
builder.add(new int[]{i, buffer});
}
}
return builder.build();
}
public void readFromNBT(NBTTagCompound tagCompound){
int amount = tagCompound.getInteger("amount");
List<Recipe> recipes = new ArrayList<>(amount);
for(int i=0; i<amount; i++){
Recipe buffer = Recipe.NBTUtl.fromNBT((NBTTagCompound)tagCompound.getTag(String.valueOf(i)));
if(buffer!=null){
recipes.add(buffer);
}
}
this.recipes = recipes;
}
public void writeToNBT(NBTTagCompound tagCompound){
tagCompound.setInteger("amount", recipes.size());
int index = 0;
for(Recipe recipe : recipes){
tagCompound.setTag(String.valueOf(index++), Recipe.NBTUtl.toNBT(recipe));
}
}
}
@@ -0,0 +1,108 @@
package me.towdium.jecalculation.network;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent;
import me.towdium.jecalculation.core.Recipe;
import java.util.HashMap;
import java.util.UUID;
/**
* @author Towdium
*/
public class PlayerHandlerServer implements IPlayerHandler {
private HashMap<UUID,PlayerHandlerClient> players = new HashMap<>();
@Override
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
return false;
}
@Override
public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) {
return null;
}
@Override
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
return null;
}
@Override
public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) {
return 0;
}
@Override
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) {
return null;
}
@Override
public void addRecipe(Recipe recipe, UUID uuid) {
players.get(uuid).addRecipe(recipe, null);
}
@Override
public void removeRecipe(int index, UUID uuid) {
players.get(uuid).removeRecipe(index, null);
}
@Override
public void setRecipe(Recipe recipe, int index, UUID uuid) {
players.get(uuid).setRecipe(recipe, index, null);
}
@Override
public ImmutableList<Recipe> getAllRecipe(UUID uuid) {
return null;
}
@Override
public ImmutableList<Integer> getAllRecipeIndex(UUID uuid) {
return null;
}
@Override
public Recipe getRecipe(int index, UUID uuid) {
return null;
}
@Override
public void syncItemCalculator(ItemStack itemIn, String string) {
}
@Override
public void handleLogin(PlayerEvent.LoadFromFile event) {
PlayerHandlerClient client = new PlayerHandlerClient();
client.handleLogin(event);
players.put(event.entityPlayer.getUniqueID(), client);
//JustEnoughCalculation.networkWrapper.sendTo(new PacketSyncRecord(client), ((EntityPlayerMP) event.entityPlayer));
}
@Override
public boolean getHasRecipe(UUID uuid) {
return false;
}
@Override
public void handleSave(PlayerEvent.SaveToFile event) {
players.get(UUID.fromString(event.playerUUID)).handleSave(event);
}
@Override
public boolean removeRecipe(Recipe recipe, UUID uuid) {
return false;
}
@Override
public boolean containsRecipe(Recipe recipe, UUID uuid) {
return false;
}
public PlayerHandlerClient getClient(UUID uuid){
return players.get(uuid);
}
}
@@ -0,0 +1,31 @@
package me.towdium.jecalculation.network;
import cpw.mods.fml.common.network.NetworkRegistry;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.event.GuiEventHandler;
import me.towdium.jecalculation.event.PlayerEventHandler;
import me.towdium.jecalculation.gui.GuiHandler;
import net.minecraftforge.common.MinecraftForge;
/**
* @author Towdium
*/
public class ProxyClient implements IProxy {
PlayerHandlerClient playerHandler = new PlayerHandlerClient();
@Override
public IPlayerHandler getPlayerHandler() {
return playerHandler;
}
@Override
public void init() {
NetworkRegistry.INSTANCE.registerGuiHandler(JustEnoughCalculation.instance, new GuiHandler());
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
}
public void setPlayerHandler(PlayerHandlerClient playerHandler) {
this.playerHandler = playerHandler;
}
}
@@ -0,0 +1,22 @@
package me.towdium.jecalculation.network;
import net.minecraftforge.common.MinecraftForge;
import me.towdium.jecalculation.event.PlayerEventHandler;
/**
* @author Towdium
*/
public class ProxyServer implements IProxy {
public static PlayerHandlerServer playerHandler = new PlayerHandlerServer();
@Override
public IPlayerHandler getPlayerHandler() {
return playerHandler;
}
@Override
public void init() {
MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
}
}
@@ -0,0 +1,42 @@
package me.towdium.jecalculation.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 me.towdium.jecalculation.item.ItemCalculator;
/**
* @author Towdium
*/
public class PacketCalculatorUpdate implements IMessage, IMessageHandler<PacketCalculatorUpdate, IMessage> {
ItemStack itemStack;
public PacketCalculatorUpdate(){}
public PacketCalculatorUpdate(ItemStack itemStack) {
this.itemStack = itemStack;
}
@Override
public void fromBytes(ByteBuf buf) {
itemStack = ByteBufUtils.readItemStack(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeItemStack(buf, itemStack);
}
@Override
public IMessage onMessage(PacketCalculatorUpdate message, MessageContext ctx) {
if(ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof ItemCalculator){
ctx.getServerHandler().playerEntity.inventory.setInventorySlotContents(
ctx.getServerHandler().playerEntity.inventory.currentItem, message.itemStack);
}
return null;
}
}
@@ -0,0 +1,56 @@
package me.towdium.jecalculation.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 me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.core.Recipe;
import me.towdium.jecalculation.network.IPlayerHandler;
import me.towdium.jecalculation.network.PlayerHandlerServer;
import java.util.UUID;
/**
* @author Towdium
*/
public class PacketRecipeUpdate implements IMessage, IMessageHandler<PacketRecipeUpdate, IMessage> {
Recipe recipe;
int index;
public PacketRecipeUpdate(){}
public PacketRecipeUpdate(Recipe recipe, int index){
this.recipe = recipe;
this.index = index;
}
@Override
public void toBytes(ByteBuf buffer) {
buffer.writeInt(index);
Recipe.ByteBufUtl.toByte(buffer, recipe);
}
@Override
public void fromBytes(ByteBuf buffer) {
index = buffer.readInt();
recipe = Recipe.ByteBufUtl.fromByte(buffer);
}
@Override
public IMessage onMessage(PacketRecipeUpdate message, MessageContext context) {
IPlayerHandler playerHandler = JustEnoughCalculation.proxy.getPlayerHandler();
if(playerHandler instanceof PlayerHandlerServer){
UUID uuid = context.getServerHandler().playerEntity.getUniqueID();
if(message.index == -1){
playerHandler.addRecipe(message.recipe, uuid);
}else if (message.recipe != null){
playerHandler.setRecipe(message.recipe, message.index, uuid);
}else {
playerHandler.removeRecipe(index, uuid);
}
}
return null;
}
}
@@ -0,0 +1,67 @@
package me.towdium.jecalculation.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 me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.network.PlayerHandlerClient;
import me.towdium.jecalculation.network.PlayerHandlerServer;
import me.towdium.jecalculation.network.ProxyClient;
import me.towdium.jecalculation.network.ProxyServer;
import java.util.UUID;
/**
* @author Towdium
*/
public class PacketSyncRecord implements IMessage, IMessageHandler<PacketSyncRecord, IMessage> {
PlayerHandlerClient client;
public PacketSyncRecord(){}
public PacketSyncRecord(PlayerHandlerClient client){
this.client = client;
}
@Override
public void toBytes(ByteBuf buf) {
if (client == null){
buf.writeShort(-1);
return;
}
buf.writeShort(0);
NBTTagCompound tagCompound = new NBTTagCompound();
client.writeToNBT(tagCompound);
ByteBufUtils.writeTag(buf, tagCompound);
}
@Override
public void fromBytes(ByteBuf buf) {
short s = buf.readShort();
if(s == -1){
return;
}
this.client = new PlayerHandlerClient();
NBTTagCompound tagCompound = ByteBufUtils.readTag(buf);
client.readFromNBT(tagCompound);
}
@Override
public IMessage onMessage(PacketSyncRecord message, MessageContext ctx) {
if(message.client == null && JustEnoughCalculation.proxy instanceof ProxyServer){
//JustEnoughCalculation.proxy.getPlayerHandler().handleLogin(ctx.getServerHandler().playerEntity.getDisplayNameString());
UUID uuida = ctx.getServerHandler().playerEntity.getUniqueID();
UUID uuidb = ctx.getServerHandler().playerEntity.getPersistentID();
return new PacketSyncRecord(((PlayerHandlerServer) JustEnoughCalculation.proxy.getPlayerHandler()).getClient(uuida));
}if(message.client == null && JustEnoughCalculation.proxy instanceof ProxyClient){
return null;
}
((ProxyClient) JustEnoughCalculation.proxy).setPlayerHandler(message.client);
return null;
}
}
@@ -0,0 +1,40 @@
package me.towdium.jecalculation.plugin;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.IRecipeHandler;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.core.ItemStackWrapper;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
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.items[0])){
current.stackSize++;
continue LOOP;
}
}
itemStacks.add(item.items[0].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,35 @@
package me.towdium.jecalculation.plugin;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.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;
}
}