mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
Add auto recipe category detect and config.
This commit is contained in:
1 parent
600e0c2ea5
commit
491e1b78b9
9 files changed
+179
-680
No files matched your search
@@ -8,6 +8,7 @@ import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
@@ -36,7 +37,6 @@ public class JustEnoughCalculation {
|
||||
public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator");
|
||||
public static SimpleNetworkWrapper networkWrapper;
|
||||
public static Logger log = LogManager.getLogger(Reference.MODID);
|
||||
public static Configuration config;
|
||||
|
||||
@SidedProxy(clientSide = "pers.towdium.justEnoughCalculation.network.ProxyClient", serverSide = "pers.towdium.justEnoughCalculation.network.ProxyServer")
|
||||
public static IProxy proxy;
|
||||
@@ -47,15 +47,12 @@ public class JustEnoughCalculation {
|
||||
public static class Reference {
|
||||
public static final String MODID = "je_calculation";
|
||||
public static final String MODNAME = "Just Enough Calculation";
|
||||
public static final String VERSION = "0.3.0";
|
||||
public static final String VERSION = "1.1.0";
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void preInit(FMLPreInitializationEvent event){
|
||||
config = new Configuration(new File(event.getModConfigurationDirectory(), "JustEnoughCalculation" +".cfg"), Reference.VERSION);
|
||||
config.load();
|
||||
config.get("General", "EnableInventoryCheck", true, "Set to false to disable auto inventory check");
|
||||
config.save();
|
||||
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);
|
||||
@@ -73,4 +70,132 @@ public class JustEnoughCalculation {
|
||||
GameRegistry.addRecipe(new ItemStack(itemCalculator), "SIS", "SRS", "SRS", 'S', new ItemStack(Blocks.stone, 1, 0), 'I', new ItemStack(Items.dye, 1, EnumDyeColor.BLACK.getDyeDamage()), 'R', Items.redstone);
|
||||
proxy.init();
|
||||
}
|
||||
|
||||
public static class JECConfig{
|
||||
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[]{ "minecraft.crafting", "minecraft.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
* This is calculating core v3.0, I call it global coordinating calculation XD.
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
|
||||
public class Calculator {
|
||||
List<CostRecord> costRecords;
|
||||
|
||||
|
||||
public Calculator(ItemStack itemStack, long amount){
|
||||
costRecords = new ArrayList<>();
|
||||
costRecords.add(new CostRecord(new ItemRecord(itemStack, amount, false)));
|
||||
|
||||
@@ -3,6 +3,7 @@ package pers.towdium.justEnoughCalculation.gui.commom;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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;
|
||||
@@ -14,6 +15,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* CODE IS DONE BY Zyin055
|
||||
@@ -174,41 +176,7 @@ public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
protected void RenderTooltip(int x, int y, String tooltip)
|
||||
{
|
||||
String[] tooltipArray = ParseTooltipArrayFromString(tooltip);
|
||||
|
||||
int tooltipWidth = GetTooltipWidth(tooltipArray);
|
||||
int tooltipHeight = GetTooltipHeight(tooltipArray);
|
||||
|
||||
int tooltipX = x + tooltipXOffset;
|
||||
int tooltipY = y + tooltipYOffset;
|
||||
|
||||
if(tooltipX > width - tooltipWidth - 7)
|
||||
tooltipX = width - tooltipWidth - 7;
|
||||
if(tooltipY > height - tooltipHeight - 8)
|
||||
tooltipY = height - tooltipHeight - 8;
|
||||
|
||||
//render the background inside box
|
||||
int innerAlpha = -0xFEFFFF0; //very very dark purple
|
||||
drawGradientRect(tooltipX, tooltipY - 1, tooltipX + tooltipWidth + 6, tooltipY, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 6, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 7, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX - 1, tooltipY, tooltipX, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 6, tooltipY, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
|
||||
//render the background outside box
|
||||
int outerAlpha1 = 0x505000FF;
|
||||
int outerAlpha2 = (outerAlpha1 & 0xFEFEFE) >> 1 | outerAlpha1 & -0x1000000;
|
||||
drawGradientRect(tooltipX, tooltipY + 1, tooltipX + 1, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 5, tooltipY + 1, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 3, tooltipY + 1, outerAlpha1, outerAlpha1);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 5, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, outerAlpha2, outerAlpha2);
|
||||
|
||||
//render the foreground text
|
||||
int lineCount = 0;
|
||||
for (String s : tooltipArray)
|
||||
{
|
||||
mc.fontRendererObj.drawStringWithShadow(s, tooltipX + 2, tooltipY + 2 + lineCount * LINE_HEIGHT, 0xFFFFFF);
|
||||
lineCount++;
|
||||
}
|
||||
this.drawHoveringText(ImmutableList.copyOf(tooltipArray), x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -227,7 +227,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
if(JustEnoughCalculation.config.get("General", "EnableInventoryCheck", true, "Set to false to disable auto inventory check").getBoolean()){
|
||||
if(JustEnoughCalculation.JECConfig.EnumItems.EnableInventoryCheck.getProperty().getBoolean()){
|
||||
checkItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package pers.towdium.justEnoughCalculation.plugin;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import mezz.jei.api.*;
|
||||
import mezz.jei.api.recipe.IRecipeCategory;
|
||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -11,29 +17,50 @@ import javax.annotation.Nonnull;
|
||||
@mezz.jei.api.JEIPlugin
|
||||
public class JEIPlugin implements IModPlugin{
|
||||
public static IJeiRuntime runtime;
|
||||
public static IRecipeRegistry recipeRegistry;
|
||||
|
||||
|
||||
@Override
|
||||
public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRegistryAvailable(IItemRegistry itemRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(@Nonnull IModRegistry registry) {
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new NormalRecipeTransferHandler(VanillaRecipeCategoryUid.CRAFTING));
|
||||
String[] blackList = JustEnoughCalculation.JECConfig.EnumItems.ListRecipeBlackList.getProperty().getStringList();
|
||||
LOOP:
|
||||
for(String s : JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()){
|
||||
for(String black : blackList){
|
||||
if(black.equals(s)){
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new NormalRecipeTransferHandler(s));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecipeRegistryAvailable(@Nonnull IRecipeRegistry recipeRegistry) {
|
||||
|
||||
JEIPlugin.recipeRegistry = recipeRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(@Nonnull IJeiRuntime jeiRuntime) {
|
||||
Set<String> identifiers = new HashSet<>();
|
||||
runtime = jeiRuntime;
|
||||
identifiers.addAll(ImmutableList.copyOf(JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().getStringList()));
|
||||
for(IRecipeCategory category : recipeRegistry.getRecipeCategories()){
|
||||
identifiers.add(category.getUid());
|
||||
}
|
||||
int size = identifiers.size();
|
||||
String[] buffer = new String[size];
|
||||
for (String s : identifiers){
|
||||
buffer[--size] = s;
|
||||
}
|
||||
JustEnoughCalculation.JECConfig.EnumItems.ListRecipeCategory.getProperty().set(buffer);
|
||||
JustEnoughCalculation.JECConfig.save();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user