Merge pull request #127 from Discreater/1.7.10-dev

[1.7.10] Migrate gradle build system
This commit is contained in:
Discreater authored and GitHub committed 2022-12-18 16:27:31 +08:00
commit 19fb4c49c3
116 files changed
+3420 -2545

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
* text eol=lf
*.[jJ][aA][rR] binary
*.[pP][nN][gG] binary
*.[jJ][pP][gG] binary
*.[jJ][pP][eE][gG] binary
*.[gG][iI][fF] binary
*.[tT][iI][fF] binary
*.[tT][iI][fF][fF] binary
*.[iI][cC][oO] binary
*.[sS][vV][gG] text
*.[eE][pP][sS] binary
*.[xX][cC][fF] binary
*.[kK][aA][rR] binary
*.[mM]4[aA] binary
*.[mM][iI][dD] binary
*.[mM][iI][dD][iI] binary
*.[mM][pP]3 binary
*.[oO][gG][gG] binary
*.[rR][aA] binary
*.7[zZ] binary
*.[gG][zZ] binary
*.[tT][aA][rR] binary
*.[tT][gG][zZ] binary
*.[zZ][iI][pP] binary
*.[tT][cC][nN] binary
*.[sS][oO] binary
*.[dD][lL][lL] binary
*.[dD][yY][lL][iI][bB] binary
*.[pP][sS][dD] binary
*.[tT][tT][fF] binary
*.[oO][tT][fF] binary
*.[pP][aA][tT][cC][hH] -text
*.[bB][aA][tT] text eol=crlf
*.[cC][mM][dD] text eol=crlf
*.[pP][sS]1 text eol=crlf
*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
if ! git diff --name-only HEAD HEAD~1 | grep -qF 'build.gradle'; then
new_version="$(date +%s)"
sed --in-place "s!^//version:.*!//version: $new_version!g" build.gradle
git add build.gradle
git commit -m "[ci skip] update build script version to $new_version"
git push
printf 'Updated buildscript version to %s\n' "$new_version"
else
printf 'Ignored buildscript version update: no changes detected\n'
fi
+13
View File
@@ -0,0 +1,13 @@
name: Build and test
on:
pull_request:
branches: [ 1.7.10, 1.7.10-dev ]
push:
branches: [ 1.7.10, 1.7.10-dev ]
jobs:
build-and-test:
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master
secrets: inherit
+74
View File
@@ -0,0 +1,74 @@
name: Release tagged build
on:
push:
tags: [ '*' ]
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout mod repo
uses: actions/checkout@v3
with:
fetch-depth: 32
- name: Set release version
run: |
IFS='-' read -r mv pv <<< "${GITHUB_REF#refs/*/}"
echo "MC_VERSION=${mv}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${pv}" >> $GITHUB_ENV
echo "VERSION=${pv}" >> $GITHUB_ENV
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup the workspace
run: ./gradlew --info --stacktrace ${{ inputs.workspace }}
- name: Build the mod
run: ./gradlew --info --stacktrace build
# Continue on error in the following steps to make sure releases still get made even if one of the methods fails
- name: Delete old release if it already exists
run: gh release delete --yes "${MC_VERSION}-${RELEASE_VERSION}"
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release under current tag
run: |
export "CHANGELOG_FILE=$(mktemp --suffix=.md)"
echo "CHANGELOG_FILE=${CHANGELOG_FILE}" >> $GITHUB_ENV
gh api --method POST -H "Accept: application/vnd.github+json" \
"/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
-f tag_name="${MC_VERSION}-${RELEASE_VERSION}" \
--jq ".body" > "${CHANGELOG_FILE}"
cat "${CHANGELOG_FILE}"
gh release create "${MC_VERSION}-${RELEASE_VERSION}" -F "${CHANGELOG_FILE}" ./build/libs/*.jar
shell: bash
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Maven, Modrinth and CurseForge
run: ./gradlew --info --stacktrace build publish
continue-on-error: true
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
if: ${{ env.MAVEN_USER != '' }}
+5
View File
@@ -2,6 +2,11 @@
To be consistent with the main branch, it may miss some versions
## 3.8.5
- Fixed: gtpp transfer crash
- Fixed: gtpp recipe output doubles
- Chore: upgrade gradle build system
## 3.8.4
- Rebuild of 3.8.3
+1051 -52
View File
File diff suppressed because it is too large. Load diff
+27
View File
@@ -0,0 +1,27 @@
// Add your dependencies here
dependencies {
// compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-122-GTNH:dev")
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.5:dev")
compile("com.github.GTNewHorizons:CodeChickenCore:1.1.6:dev")
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.2-GTNH:dev")
// compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
// compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.9.1:dev")
// compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.0.15-gtnh:dev") { transitive = false }
// compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.5.4-GTNH:dev") { transitive = false }
// compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.12:dev") { transitive = false }
compileOnly('com.github.GTNewHorizons:EnderIO:2.3.1.47:dev') {transitive=false}
compileOnly("com.github.GTNewHorizons:ForestryMC:4.4.14:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.41.37:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTplusplus:1.7.90:dev") { transitive = false }
// compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.3.19-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Botania:1.9.11-GTNH:dev") { transitive = false }
compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") { transitive = false }
compileOnly("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false }
// compileOnly("curse.maven:thermal-expansion-69163:2388759") { transitive = false }
// runtime("curse.maven:cofh-core-69162:2388751")
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
}
+79 -7
View File
@@ -1,7 +1,79 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
# suppress inspection "UnusedProperty" for whole file
mc_version=1.7.10
nei_version=2.1.5-GTNH
proj_version=3.8.4
modName = Just Enough Calculation
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
modId = jecalculation
modGroup = me.towdium.jecalculation
# WHY is there no version field?
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/
# Will update your build.gradle automatically whenever an update is available
autoUpdateBuildScript = false
minecraftVersion = 1.7.10
forgeVersion = 10.13.4.1614
# Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task.
channel = stable
mappingsVersion = 12
# Define other MCP mappings for dependency deobfuscation
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
# restart Minecraft in development. Choose this dependent on your mod:
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
developmentEnvironmentUserName = Developer
# Define a source file of your project with:
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...])
# Leave these properties empty to skip individual token replacements
replaceGradleTokenInFile = Tags.java
gradleTokenModId = GRADLETOKEN_MODID
gradleTokenModName = GRADLETOKEN_MODNAME
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenGroupName = GRADLETOKEN_GROUPNAME
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
accessTransformersFile = jeca_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
# Adds some debug arguments like verbose output and export
usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
containsMixinsAndOrCoreModOnly = false
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
forceEnableMixins = false
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
# responsibility check the licence and request permission for distribution, if required.
usesShadowedDependencies = false
# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
# projects. New projects should not use this parameter.
customArchiveBaseName = JustEnoughCalculation
# Optional parameter to prevent the source code from being published
# noPublishedSources =
+1 -2
View File
@@ -1,6 +1,5 @@
#Wed Jul 02 15:54:47 CDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
+2
View File
@@ -0,0 +1,2 @@
before_install:
- ./gradlew setupCIWorkspace
Binary file not shown.
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
// Add any additional repositories for your dependencies here
repositories {
maven {
name 'GTNH Maven'
url 'http://jenkins.usrv.eu:8081/nexus/content/groups/public/'
allowInsecureProtocol
}
maven {
url 'https://cursemaven.com'
content {
includeGroup 'curse.maven'
}
}
maven {
url 'https://jitpack.io'
}
}
+10
View File
@@ -0,0 +1,10 @@
plugins {
id 'com.diffplug.blowdryerSetup' version '1.6.0'
}
apply plugin: 'com.diffplug.blowdryerSetup'
blowdryerSetup {
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.1.5')
//devLocal '.' // Use this when testing config updates locally
}
@@ -2,11 +2,10 @@ package me.towdium.jecalculation;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import java.io.File;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import java.io.File;
public class JecaConfig {
public static File configDir = new File(Loader.instance().getConfigDir(), "JustEnoughCalculation/");
public static final File configFile = new File(configDir, "main.cfg");
@@ -27,7 +26,10 @@ public class JecaConfig {
}
public enum EnumItems {
ClientMode, EnableInventoryCheck, ListRecipeBlackList, ListRecipeCategory;
ClientMode,
EnableInventoryCheck,
ListRecipeBlackList,
ListRecipeCategory;
public String getComment() {
switch (this) {
@@ -36,8 +38,8 @@ public class JecaConfig {
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";
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";
}
@@ -89,7 +91,7 @@ public class JecaConfig {
case ListRecipeBlackList:
return new String[0];
case ListRecipeCategory:
return new String[]{"minecraft.crafting", "minecraft.smelting"};
return new String[] {"minecraft.crafting", "minecraft.smelting"};
}
return JecaConfig.empty;
}
@@ -99,11 +101,11 @@ public class JecaConfig {
if (type != null) {
switch (this.getType()) {
case Boolean:
return config.get(this.getCategory(), this.getName(), (Boolean) this.getDefault(),
this.getComment());
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());
return config.get(
this.getCategory(), this.getName(), (String[]) this.getDefault(), this.getComment());
}
config.getCategory(EnumCategory.General.toString()).get(this.getName());
}
@@ -128,19 +130,20 @@ public class JecaConfig {
}
public enum EnumType {
Boolean, ListString, Error
Boolean,
ListString,
Error
}
public static Object empty;
public static void preInit(FMLPreInitializationEvent event) {
config = new Configuration(configFile, JustEnoughCalculation.Reference.VERSION);
config = new Configuration(configFile, Tags.VERSION);
config.load();
handleInit();
config.save();
}
public static void handleInit() {
for (EnumItems item : EnumItems.values()) {
item.init();
@@ -1,57 +1,73 @@
package me.towdium.jecalculation;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.network.ClientHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.network.CommonProxy;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* @author Towdium
*/
@ParametersAreNonnullByDefault
@SuppressWarnings("unused")
@SideOnly(Side.CLIENT)
@Mod(modid = JustEnoughCalculation.Reference.MODID,
name = JustEnoughCalculation.Reference.MODNAME,
version = JustEnoughCalculation.Reference.VERSION,
dependencies = "required-after:NotEnoughItems")
@Mod(
modid = Tags.MODID,
name = Tags.MODNAME,
version = Tags.VERSION,
dependencies = "required-after:NotEnoughItems",
acceptedMinecraftVersions = "[1.7.10]")
public class JustEnoughCalculation {
@Mod.Instance(Reference.MODID)
public static Logger logger = LogManager.getLogger(Tags.MODID);
@SidedProxy(
clientSide = Tags.GROUPNAME + ".network.ClientProxy",
serverSide = Tags.GROUPNAME + ".network.CommonProxy")
public static CommonProxy proxy;
@Mod.Instance(Tags.MODID)
public static JustEnoughCalculation INSTANCE;
public static ClientHandler handler = new ClientHandler();
public static Logger logger = LogManager.getLogger(Reference.MODID);
@Mod.EventHandler
public static void initPre(FMLPreInitializationEvent event) {
JecaConfig.preInit(event);
handler.initPre();
public static void preInit(FMLPreInitializationEvent event) {
proxy.preInit(event);
}
@Mod.EventHandler
public static void init(FMLInitializationEvent event) {
handler.init();
proxy.init(event);
}
@Mod.EventHandler
public static void postInit(FMLPostInitializationEvent event) {
handler.initPost();
NEIPlugin.init();
proxy.postInit(event);
}
public static class Reference {
public static final String MODID = "jecalculation";
public static final String MODNAME = "Just Enough Calculation";
public static final String VERSION = "@VERSION@";
@Mod.EventHandler
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
proxy.serverAboutToStart(event);
}
@Mod.EventHandler
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
}
@Mod.EventHandler
public void serverStarted(FMLServerStartedEvent event) {
proxy.serverStarted(event);
}
@Mod.EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
proxy.serverStopping(event);
}
@Mod.EventHandler
public void serverStopped(FMLServerStoppedEvent event) {
proxy.serverStopped(event);
}
}
@@ -0,0 +1,9 @@
package me.towdium.jecalculation;
public class Tags {
public static final String MODID = "GRADLETOKEN_MODID";
public static final String MODNAME = "GRADLETOKEN_MODNAME";
public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.command;
import java.util.HashMap;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.commands.CCraft;
import me.towdium.jecalculation.command.commands.CHelp;
import me.towdium.jecalculation.command.commands.CMath;
import me.towdium.jecalculation.command.commands.CState;
import me.towdium.jecalculation.command.commands.CCraft;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.HashMap;
/**
* Author: towdium
@@ -1,11 +1,10 @@
package me.towdium.jecalculation.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
/**
* Author: towdium
@@ -1,5 +1,8 @@
package me.towdium.jecalculation.command;
import java.util.Collections;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.commands.CHelp;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import net.minecraft.command.CommandBase;
@@ -7,10 +10,6 @@ import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentTranslation;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
/**
* Author: towdium
* Date: 8/10/17.
@@ -27,7 +26,6 @@ public class JecaCommand extends CommandBase {
return "/jeca [options]";
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
@@ -48,8 +46,7 @@ public class JecaCommand extends CommandBase {
}
private String[] cut(String[] args) {
if (args.length == 0)
return new String[0];
if (args.length == 0) return new String[0];
String[] ret = new String[args.length - 1];
System.arraycopy(args, 1, ret, 0, args.length - 1);
return ret;
@@ -66,12 +63,11 @@ public class JecaCommand extends CommandBase {
return getListOfStringsFromIterableMatchingLastWord(args, Commands.commands.keySet());
} else {
Wrapper<ISubCommand> sub = new Wrapper<>(null);
Commands.commands.values().stream().filter(c -> c.getName().equals(cmd))
.findFirst().ifPresent(sub::push);
return sub.value != null ? sub.value.getTabCompletions(sender, cut(args))
: Collections.emptyList();
Commands.commands.values().stream()
.filter(c -> c.getName().equals(cmd))
.findFirst()
.ifPresent(sub::push);
return sub.value != null ? sub.value.getTabCompletions(sender, cut(args)) : Collections.emptyList();
}
}
}
@@ -1,14 +1,9 @@
package me.towdium.jecalculation.command.commands;
import me.towdium.jecalculation.command.ISubCommand;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.util.ChatComponentText;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.ISubCommand;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.command.ICommandSender;
/**
* Author: Towdium
@@ -26,7 +21,6 @@ public class CCraft implements ISubCommand {
return "/jeca craft";
}
@Override
public void execute(ICommandSender sender, String[] args) {
JecaGui.openGuiCraft(true);
@@ -1,15 +1,13 @@
package me.towdium.jecalculation.command.commands;
import java.util.Comparator;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.Commands;
import me.towdium.jecalculation.command.ISubCommand;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Comparator;
/**
* Author: towdium
* Date: 8/10/17.
@@ -17,6 +15,7 @@ import java.util.Comparator;
@ParametersAreNonnullByDefault
public class CHelp implements ISubCommand {
public static final String NAME = "help";
@Override
public String getName() {
return NAME;
@@ -30,7 +29,8 @@ public class CHelp implements ISubCommand {
@Override
public void execute(ICommandSender sender, String[] args) {
sender.addChatMessage(new ChatComponentTranslation(getKey("list")));
Commands.commands.values().stream().sorted(Comparator.comparing(ISubCommand::getName))
.forEachOrdered(c -> sender.addChatMessage(new ChatComponentText(c.getUsage(sender))));
Commands.commands.values().stream()
.sorted(Comparator.comparing(ISubCommand::getName))
.forEachOrdered(c -> sender.addChatMessage(new ChatComponentText(c.getUsage(sender))));
}
}
@@ -1,11 +1,10 @@
package me.towdium.jecalculation.command.commands;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.ISubCommand;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.command.ICommandSender;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: Towdium
* Date: 19-1-21
@@ -1,13 +1,10 @@
package me.towdium.jecalculation.command.commands;
import me.towdium.jecalculation.JustEnoughCalculation;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.command.ISubCommand;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentTranslation;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 8/10/17.
@@ -2,6 +2,14 @@ package me.towdium.jecalculation.data;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.io.File;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.JecaConfig;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
@@ -14,15 +22,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentTranslation;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.io.File;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Author: towdium
* Date: 17-10-15.
@@ -51,8 +50,7 @@ public class Controller {
public static List<Pair<String, Recipes>> discover() {
File dir = JecaConfig.dataDir;
File[] fs = dir.listFiles();
if (fs == null)
return new ArrayList<>();
if (fs == null) return new ArrayList<>();
Function<File, Recipes> read = f -> {
NBTTagCompound nbt = Utilities.Json.read(f);
if (nbt == null) {
@@ -63,22 +61,20 @@ public class Controller {
}
};
return Arrays.stream(fs)
.map(i -> new Pair<>(i.getName(), read.apply(i)))
.filter(i -> i.two != null)
.collect(Collectors.toList());
.map(i -> new Pair<>(i.getName(), read.apply(i)))
.filter(i -> i.two != null)
.collect(Collectors.toList());
}
public static void inport(Recipes recipes, String group) {
ArrayList<Recipe> buffer = new ArrayList<>();
recipes.getGroup(group).stream().filter(i -> !hasDuplicate(i)).forEach(buffer::add);
for (Recipe r : buffer)
addRecipe(group, r);
for (Recipe r : buffer) addRecipe(group, r);
}
private static void export(String s, Function<Recipes, NBTTagCompound> r) {
EntityClientPlayerMP player = Utilities.getPlayer();
if (player == null)
return;
if (player == null) return;
File f = JecaConfig.getDataFile(s);
Utilities.Json.write(r.apply(getRecipes()), f);
@@ -192,10 +188,8 @@ public class Controller {
public static boolean hasDuplicate(Recipe r, String group, int index) {
Recipes.RecipeIterator ri = recipeIterator();
return ri.stream().anyMatch(i -> {
if (ri.getIndex() == index && ri.getGroup().equals(group))
return false;
else
return i.equals(r);
if (ri.getIndex() == index && ri.getGroup().equals(group)) return false;
else return i.equals(r);
});
}
@@ -203,7 +197,6 @@ public class Controller {
return recipeIterator().stream().anyMatch(i -> i.equals(r));
}
public static void loadFromLocal() {
//noinspection ResultOfMethodCallIgnored
JecaConfig.dataDir.mkdirs();
@@ -214,9 +207,8 @@ public class Controller {
if (nbt != null) {
rCraftClient = new RecordCraft(nbt.getCompoundTag(KEY_CRAFT));
rMathClient = new RecordMath(nbt.getCompoundTag(KEY_MATH));
rPlayerClient = nbt.hasKey(KEY_PLAYER) ?
new RecordPlayer(nbt.getCompoundTag(KEY_PLAYER)) :
new RecordPlayer();
rPlayerClient =
nbt.hasKey(KEY_PLAYER) ? new RecordPlayer(nbt.getCompoundTag(KEY_PLAYER)) : new RecordPlayer();
} else {
rPlayerClient = new RecordPlayer();
rCraftClient = new RecordCraft(new NBTTagCompound());
@@ -2,6 +2,13 @@ package me.towdium.jecalculation.data.label;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.labels.LFluidStack;
import me.towdium.jecalculation.data.label.labels.LItemStack;
@@ -24,14 +31,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* Author: towdium
* Date: 8/11/17.
@@ -68,10 +67,10 @@ public interface ILabel {
MERGER.register("itemStack", "itemStack", Impl.form(LItemStack.class, LItemStack.class, LItemStack::merge));
MERGER.register("oreDict", "oreDict", Impl.form(LOreDict.class, LOreDict.class, LOreDict::mergeSame));
MERGER.register("oreDict", "itemStack", Impl.form(LOreDict.class, LItemStack.class, LOreDict::mergeFuzzy));
MERGER.register("fluidStack", "fluidStack",
Impl.form(LFluidStack.class, LFluidStack.class, LFluidStack::merge));
MERGER.register("placeholder", "placeholder",
Impl.form(LPlaceholder.class, LPlaceholder.class, LPlaceholder::merge));
MERGER.register(
"fluidStack", "fluidStack", Impl.form(LFluidStack.class, LFluidStack.class, LFluidStack::merge));
MERGER.register(
"placeholder", "placeholder", Impl.form(LPlaceholder.class, LPlaceholder.class, LPlaceholder::merge));
}
long getAmount();
@@ -114,7 +113,6 @@ public interface ILabel {
@SideOnly(Side.CLIENT)
void drawLabel(JecaGui gui, int xPos, int yPos, boolean center);
/**
* Since {@link ILabel} merging is bidirectional, it is redundant to
* implement on both side. So this class is created for merging
@@ -126,8 +124,7 @@ public interface ILabel {
class Merger {
private final Utilities.Relation<String, MergerFunction> functions = new Utilities.Relation<>();
private Merger() {
}
private Merger() {}
public void register(String a, String b, MergerFunction func) {
functions.put(a, b, func);
@@ -144,8 +141,7 @@ public interface ILabel {
*/
public Optional<ILabel> merge(ILabel a, ILabel b) {
MergerFunction mf = functions.get(a.getIdentifier(), b.getIdentifier());
if (mf == null)
return Optional.empty();
if (mf == null) return Optional.empty();
return Optional.ofNullable(mf.merge(a, b));
}
@@ -175,8 +171,7 @@ public interface ILabel {
private final HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
private Serializer() {
}
private Serializer() {}
public void register(String identifier, Function<NBTTagCompound, ILabel> deserializer) {
idToData.put(identifier, deserializer);
@@ -198,8 +193,7 @@ public interface ILabel {
public ILabel deserialize(NBTTagCompound nbt) {
String s = nbt.getString(KEY_IDENTIFIER);
Function<NBTTagCompound, ILabel> func = idToData.get(s);
if (func == null)
JustEnoughCalculation.logger.warn("Unrecognized identifier \"" + s + "\", abort");
if (func == null) JustEnoughCalculation.logger.warn("Unrecognized identifier \"" + s + "\", abort");
else
try {
return func.apply(nbt.getCompoundTag(KEY_CONTENT));
@@ -237,7 +231,10 @@ public interface ILabel {
* while input does not contain all entries recorded in tag
* Fallback is also used with one input label to guess possible conventions
*/
public enum Priority {SUGGEST, FALLBACK}
public enum Priority {
SUGGEST,
FALLBACK
}
static {
handlers = new EnumMap<>(Priority.class);
@@ -246,12 +243,9 @@ public interface ILabel {
}
public static ILabel from(@Nullable Object o) {
if (o == null)
return ILabel.EMPTY;
else if (o instanceof ItemStack)
return new LItemStack((ItemStack) o);
else if (o instanceof FluidStack)
return new LFluidStack((FluidStack) o);
if (o == null) return ILabel.EMPTY;
else if (o instanceof ItemStack) return new LItemStack((ItemStack) o);
else if (o instanceof FluidStack) return new LFluidStack((FluidStack) o);
else if (o instanceof EnchantmentData) {
ItemStack itemStack = new ItemStack(Items.enchanted_book);
new ItemEnchantedBook().addEnchantment(itemStack, (EnchantmentData) o);
@@ -274,17 +268,10 @@ public interface ILabel {
// to test if the labels can be converted to other labels (like oreDict)
public Pair<List<ILabel>, List<ILabel>> guess(List<ILabel> labels, @Nullable Class<?> context) {
List<ILabel> suggest = new ReversedIterator<>(handlers.get(Priority.SUGGEST)).stream()
.flatMap(h -> h.convert(labels,
context)
.stream())
.collect(Collectors.toList());
List<ILabel> fallback = new ReversedIterator<>(handlers.get(Priority.FALLBACK)).stream()
.flatMap(h -> h.convert(
labels, context)
.stream())
.collect(
Collectors.toList());
List<ILabel> suggest = new ReversedIterator<>(handlers.get(Priority.SUGGEST))
.stream().flatMap(h -> h.convert(labels, context).stream()).collect(Collectors.toList());
List<ILabel> fallback = new ReversedIterator<>(handlers.get(Priority.FALLBACK))
.stream().flatMap(h -> h.convert(labels, context).stream()).collect(Collectors.toList());
return new Pair<>(suggest, fallback);
}
@@ -298,14 +285,12 @@ public interface ILabel {
private final ArrayList<Record> records = new ArrayList<>();
private RegistryEditor() {
}
private RegistryEditor() {}
public void register(Supplier<IPicker> editor, String unlocalizedName, ILabel representation) {
records.add(new Record(editor, "common.label." + unlocalizedName, representation));
}
public List<Record> getRecords() {
return records;
}
@@ -332,11 +317,9 @@ public interface ILabel {
}
@Override
public void drawLabel(JecaGui gui, int xPos, int yPos, boolean center) {
}
public void drawLabel(JecaGui gui, int xPos, int yPos, boolean center) {}
private LEmpty() {
}
private LEmpty() {}
@Nullable
@Override
@@ -395,8 +378,7 @@ public interface ILabel {
}
@Override
public void getToolTip(List<String> existing, boolean detailed) {
}
public void getToolTip(List<String> existing, boolean detailed) {}
@Override
public ILabel copy() {
@@ -412,7 +394,6 @@ public interface ILabel {
public String getIdentifier() {
return IDENTIFIER;
}
}
abstract class Impl implements ILabel {
@@ -453,7 +434,7 @@ public interface ILabel {
GlStateManager.popMatrix();
}
abstract protected void drawLabel(JecaGui gui);
protected abstract void drawLabel(JecaGui gui);
@Override
public ILabel increaseAmount() {
@@ -466,7 +447,8 @@ public interface ILabel {
public ILabel decreaseAmount() {
if (getAmount() <= 0) {
return ILabel.EMPTY;
} if (getAmount() <= getMultiplier()) {
}
if (getAmount() <= getMultiplier()) {
return setAmount(1);
} else {
return setAmount(getAmount() - getMultiplier());
@@ -490,22 +472,17 @@ public interface ILabel {
long amountD = d.isPercent() ? d.getAmount() : Math.multiplyExact(d.getAmount(), 100);
long amount = Math.addExact(amountC, amountD);
long amountI = (amount > 0 ? Math.addExact(amount, 99) : Math.subtractExact(amount, 99)) / 100;
if (amount == 0)
return EMPTY;
else if (amount > 0)
return d.copy().setAmount(d.isPercent() ? amount : amountI);
else
return c.copy().setAmount(c.isPercent() ? amount : amountI);
} else
return null;
if (amount == 0) return EMPTY;
else if (amount > 0) return d.copy().setAmount(d.isPercent() ? amount : amountI);
else return c.copy().setAmount(c.isPercent() ? amount : amountI);
} else return null;
};
}
@Override
public ILabel multiply(float i) {
float amount = i * getAmount();
if (amount > Long.MAX_VALUE)
throw new ArithmeticException("Multiply overflow");
if (amount > Long.MAX_VALUE) throw new ArithmeticException("Multiply overflow");
return setAmount((long) amount);
}
@@ -519,12 +496,9 @@ public interface ILabel {
boolean showStack = stack != 0;
boolean showReminder = stack < 1000 && remainder != 0;
String tip = "";
if (showStack)
tip += Utilities.cutNumber(stack, 5) + "x64";
if (showStack && showReminder)
tip += "+";
if (showReminder)
tip += Long.toString(remainder);
if (showStack) tip += Utilities.cutNumber(stack, 5) + "x64";
if (showStack && showReminder) tip += "+";
if (showReminder) tip += Long.toString(remainder);
existing.add(FORMAT_GREY + Utilities.I18n.get("label.common.amount", tip));
}
}
@@ -536,8 +510,7 @@ public interface ILabel {
@Override
public ILabel setAmount(long amount) {
if (amount == 0)
return ILabel.EMPTY;
if (amount == 0) return ILabel.EMPTY;
this.amount = amount;
return this;
}
@@ -546,8 +519,7 @@ public interface ILabel {
public NBTTagCompound toNbt() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setLong(KEY_AMOUNT, amount);
if (percent)
nbt.setBoolean(KEY_PERCENT, true);
if (percent) nbt.setBoolean(KEY_PERCENT, true);
return nbt;
}
@@ -557,8 +529,7 @@ public interface ILabel {
}
public ILabel setPercent(boolean p) {
if (p && !acceptPercent())
throw new UnsupportedOperationException();
if (p && !acceptPercent()) throw new UnsupportedOperationException();
if (p && !percent) {
amount *= 100;
percent = true;
@@ -583,18 +554,14 @@ public interface ILabel {
@SideOnly(Side.CLIENT)
@SuppressWarnings("IntegerDivisionInFloatingPointContext")
public String getAmountString(boolean round) {
if (getAmount() == 0)
return "";
else if (!percent)
return Utilities.cutNumber(getAmount(), 5);
else if (round)
return Utilities.cutNumber((getAmount() + 99) / 100, 5);
else
return Utilities.cutNumber(getAmount(), 4) + "%";
if (getAmount() == 0) return "";
else if (!percent) return Utilities.cutNumber(getAmount(), 5);
else if (round) return Utilities.cutNumber((getAmount() + 99) / 100, 5);
else return Utilities.cutNumber(getAmount(), 4) + "%";
}
@Override
abstract public Impl copy();
public abstract Impl copy();
@Override
public boolean matches(Object l) {
@@ -2,6 +2,11 @@ package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
@@ -11,12 +16,6 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Author: towdium
* Date: 17-9-27.
@@ -58,8 +57,7 @@ public class LFluidStack extends ILabel.Impl {
super(nbt);
String id = nbt.getString(KEY_FLUID);
Fluid f = FluidRegistry.getFluid(id);
if (f == null)
throw new Serializer.SerializationException("Fluid " + id + " cannot be resolved, ignoring");
if (f == null) throw new Serializer.SerializationException("Fluid " + id + " cannot be resolved, ignoring");
init(f, nbt.hasKey(KEY_NBT) ? nbt.getCompoundTag(KEY_NBT) : null);
}
@@ -86,7 +84,6 @@ public class LFluidStack extends ILabel.Impl {
return amount >= 1000 ? Utilities.cutNumber(amount / 1000f, 4) + "B" : amount + "mB";
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
@@ -103,8 +100,7 @@ public class LFluidStack extends ILabel.Impl {
if (l instanceof LFluidStack) {
LFluidStack lfs = (LFluidStack) l;
return (Objects.equals(nbt, lfs.nbt)) && fluid == lfs.fluid;
} else
return false;
} else return false;
}
@Override
@@ -116,8 +112,7 @@ public class LFluidStack extends ILabel.Impl {
public NBTTagCompound toNbt() {
NBTTagCompound ret = super.toNbt();
ret.setString(KEY_FLUID, FluidRegistry.getFluidName(fluid));
if (nbt != null)
ret.setTag(KEY_NBT, nbt);
if (nbt != null) ret.setTag(KEY_NBT, nbt);
return ret;
}
@@ -129,7 +124,6 @@ public class LFluidStack extends ILabel.Impl {
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid));
}
@Override
@SideOnly(Side.CLIENT)
public void drawLabel(JecaGui gui) {
@@ -147,9 +141,7 @@ public class LFluidStack extends ILabel.Impl {
}
public static boolean merge(ILabel a, ILabel b) {
if (a instanceof LFluidStack && b instanceof LFluidStack)
return a.matches(b);
else
return false;
if (a instanceof LFluidStack && b instanceof LFluidStack) return a.matches(b);
else return false;
}
}
@@ -1,8 +1,16 @@
package me.towdium.jecalculation.data.label.labels;
import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.utils.ItemStackHelper;
@@ -11,15 +19,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE;
/**
* Author: towdium
* Date: 8/11/17.
@@ -59,8 +58,12 @@ public class LItemStack extends ILabel.Impl {
if (ItemStackHelper.isEmpty(stack))
throw new Serializer.SerializationException("Item " + strId + " cannot be resolved, ignoring");
Item i = stack.getItem();
init(i, tag.getInteger(KEY_META), tag.hasKey(KEY_NBT) ? stack.stackTagCompound : null,
tag.getBoolean(KEY_F_META), tag.getBoolean(KEY_F_NBT));
init(
i,
tag.getInteger(KEY_META),
tag.hasKey(KEY_NBT) ? stack.stackTagCompound : null,
tag.getBoolean(KEY_F_META),
tag.getBoolean(KEY_F_NBT));
}
private LItemStack(LItemStack lis) {
@@ -84,20 +87,19 @@ public class LItemStack extends ILabel.Impl {
rep.setTagCompound(this.nbt);
}
public static boolean merge(ILabel a, ILabel b) {
if (a instanceof LItemStack && b instanceof LItemStack) {
LItemStack lisA = (LItemStack) a;
LItemStack lisB = (LItemStack) b;
if (lisA.meta != lisB.meta && !lisA.fMeta && lisA.meta != WILDCARD_VALUE && !lisB.fMeta &&
lisB.meta != WILDCARD_VALUE)
return false;
if (lisA.meta != lisB.meta
&& !lisA.fMeta
&& lisA.meta != WILDCARD_VALUE
&& !lisB.fMeta
&& lisB.meta != WILDCARD_VALUE) return false;
if (!lisA.fNbt && !lisB.fNbt) {
if (lisA.nbt == null) {
if (lisB.nbt != null)
return false;
} else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt))
return false;
if (lisB.nbt != null) return false;
} else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt)) return false;
}
return lisA.item == lisB.item;
}
@@ -105,39 +107,29 @@ public class LItemStack extends ILabel.Impl {
}
public static List<ILabel> suggest(List<ILabel> iss, @Nullable Class<?> context) {
if (iss.size() == 0)
return new ArrayList<>();
for (ILabel i : iss)
if (!(i instanceof LItemStack))
return new ArrayList<>();
if (iss.size() == 0) return new ArrayList<>();
for (ILabel i : iss) if (!(i instanceof LItemStack)) return new ArrayList<>();
LItemStack lis = (LItemStack) iss.get(0);
boolean fMeta = false;
boolean fNbt = false;
for (ILabel i : iss) {
LItemStack ii = (LItemStack) i;
if (ii.item != lis.item)
return new ArrayList<>();
if (ii.meta != lis.meta || ii.fMeta)
fMeta = true;
if (!Objects.equals(ii.nbt, lis.nbt))
fNbt = true;
if (ii.item != lis.item) return new ArrayList<>();
if (ii.meta != lis.meta || ii.fMeta) fMeta = true;
if (!Objects.equals(ii.nbt, lis.nbt)) fNbt = true;
}
if (fMeta || fNbt)
return Collections.singletonList(lis.copy().setFMeta(fMeta).setFNbt(fNbt));
else
return new ArrayList<>();
else return new ArrayList<>();
}
public static List<ILabel> fallback(List<ILabel> iss, @Nullable Class<?> context) {
List<ILabel> ret = new ArrayList<>();
if (iss.size() == 1) {
ILabel label = iss.get(0);
if (!(label instanceof LItemStack))
return ret;
if (!(label instanceof LItemStack)) return ret;
LItemStack lis = (LItemStack) label;
if (lis.fNbt || lis.fMeta)
return new ArrayList<>();
if (lis.fNbt || lis.fMeta) return new ArrayList<>();
ret.add(lis.copy().setFMeta(true));
ret.add(lis.copy().setFNbt(true));
ret.add(lis.copy().setFMeta(true).setFNbt(true));
@@ -147,8 +139,7 @@ public class LItemStack extends ILabel.Impl {
public LItemStack setFMeta(boolean f) {
fMeta = f;
if (f)
meta = 0;
if (f) meta = 0;
rep = new ItemStack(item, 1, meta);
rep.setTagCompound(nbt);
return this;
@@ -156,8 +147,7 @@ public class LItemStack extends ILabel.Impl {
public LItemStack setFNbt(boolean f) {
fNbt = f;
if (f)
nbt = null;
if (f) nbt = null;
rep = new ItemStack(item, 1, meta);
rep.setTagCompound(nbt);
return this;
@@ -171,10 +161,8 @@ public class LItemStack extends ILabel.Impl {
@SideOnly(Side.CLIENT)
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
if (fMeta)
existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_meta"));
if (fNbt)
existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_nbt"));
if (fMeta) existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_meta"));
if (fNbt) existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_nbt"));
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(item));
}
@@ -198,10 +186,13 @@ public class LItemStack extends ILabel.Impl {
public boolean matches(Object l) {
if (l instanceof LItemStack) {
LItemStack lis = (LItemStack) l;
return (Objects.equals(nbt, lis.nbt)) && meta == lis.meta && item == lis.item && fNbt == lis.fNbt &&
super.matches(l) && fMeta == lis.fMeta;
} else
return false;
return (Objects.equals(nbt, lis.nbt))
&& meta == lis.meta
&& item == lis.item
&& fNbt == lis.fNbt
&& super.matches(l)
&& fMeta == lis.fMeta;
} else return false;
}
@Override
@@ -211,19 +202,14 @@ public class LItemStack extends ILabel.Impl {
@Override
public NBTTagCompound toNbt() {
if (item == null)
return ILabel.EMPTY.toNbt();
if (item == null) return ILabel.EMPTY.toNbt();
String strId = Item.itemRegistry.getNameForObject(item);
NBTTagCompound ret = super.toNbt();
if (meta != 0)
ret.setInteger(KEY_META, meta);
if (meta != 0) ret.setInteger(KEY_META, meta);
ret.setString(KEY_ITEM, strId);
if (nbt != null)
ret.setTag(KEY_NBT, nbt);
if (fMeta)
ret.setBoolean(KEY_F_META, true);
if (fNbt)
ret.setBoolean(KEY_F_NBT, true);
if (nbt != null) ret.setTag(KEY_NBT, nbt);
if (fMeta) ret.setBoolean(KEY_F_META, true);
if (fNbt) ret.setBoolean(KEY_F_NBT, true);
return ret;
}
@@ -242,6 +228,9 @@ public class LItemStack extends ILabel.Impl {
@Override
public int hashCode() { // TODO all labels use super hashcode
return (nbt == null ? 0 : nbt.hashCode()) ^ meta ^ item.getUnlocalizedName().hashCode() ^ (int) amount;
return (nbt == null ? 0 : nbt.hashCode())
^ meta
^ item.getUnlocalizedName().hashCode()
^ (int) amount;
}
}
@@ -2,7 +2,14 @@ package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.Tags;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
@@ -15,14 +22,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
/**
* Author: towdium
* Date: 17-9-10.
@@ -59,8 +58,7 @@ public class LOreDict extends ILabel.Impl {
LOreDict lodA = (LOreDict) a;
LOreDict lodB = (LOreDict) b;
return lodA.getName().equals(lodB.getName());
} else
return false;
} else return false;
}
public static boolean mergeFuzzy(ILabel a, ILabel b) {
@@ -81,35 +79,32 @@ public class LOreDict extends ILabel.Impl {
public static List<ILabel> suggest(List<ILabel> iss, @Nullable Class<?> context) {
ILabel l = iss.get(0);
if (!(l instanceof LItemStack))
return new ArrayList<>();
if (!(l instanceof LItemStack)) return new ArrayList<>();
LItemStack lis = (LItemStack) l;
HashSet<Integer> ids = new HashSet<>();
long amount = lis.getAmount();
for (int i : OreDictionary.getOreIDs(lis.getRep()))
if (check(i, iss, true))
ids.add(i);
return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i), amount)).collect(Collectors.toList());
for (int i : OreDictionary.getOreIDs(lis.getRep())) if (check(i, iss, true)) ids.add(i);
return ids.stream()
.map(i -> new LOreDict(OreDictionary.getOreName(i), amount))
.collect(Collectors.toList());
}
public static List<ILabel> fallback(List<ILabel> iss, @Nullable Class<?> context) {
ILabel l = iss.get(0);
if (!(l instanceof LItemStack))
return new ArrayList<>();
if (!(l instanceof LItemStack)) return new ArrayList<>();
LItemStack lis = (LItemStack) l;
HashSet<Integer> ids = new HashSet<>();
long amount = lis.getAmount();
for (int i : OreDictionary.getOreIDs(lis.getRep()))
if (check(i, iss, false))
ids.add(i);
return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i), amount)).collect(Collectors.toList());
for (int i : OreDictionary.getOreIDs(lis.getRep())) if (check(i, iss, false)) ids.add(i);
return ids.stream()
.map(i -> new LOreDict(OreDictionary.getOreName(i), amount))
.collect(Collectors.toList());
}
// check labels in the list suitable for the ore id
private static boolean check(int id, List<ILabel> labels, boolean biDir) {
ArrayList<ItemStack> ores = OreDictionary.getOres(OreDictionary.getOreName(id));
if (labels.size() == 1 && ores.size() == 1 && biDir && !MODE_FORCE)
return false;
if (labels.size() == 1 && ores.size() == 1 && biDir && !MODE_FORCE) return false;
Wrapper<Boolean> acceptable = new Wrapper<>(true);
if (biDir) {
@@ -159,8 +154,7 @@ public class LOreDict extends ILabel.Impl {
list.add(ore);
}
}
if (list.isEmpty())
return ItemStackHelper.EMPTY_ITEM_STACK;
if (list.isEmpty()) return ItemStackHelper.EMPTY_ITEM_STACK;
long index = System.currentTimeMillis() / 1500;
return list.get((int) (index % list.size()));
}
@@ -205,7 +199,7 @@ public class LOreDict extends ILabel.Impl {
@SideOnly(Side.CLIENT)
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Tags.MODNAME);
}
@Override
@@ -2,16 +2,6 @@ package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -19,6 +9,15 @@ import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.Tags;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.nbt.NBTTagCompound;
/**
* Author: towdium
@@ -28,7 +27,7 @@ import java.util.stream.Collectors;
public class LPlaceholder extends ILabel.Impl {
public static final String KEY_NAME = "name";
public static final String IDENTIFIER = "placeholder";
public static boolean state = true; // true for client, false for server
public static boolean state = true; // true for client, false for server
static Utilities.Recent<LPlaceholder> recentClient = new Utilities.Recent<>(100);
static Utilities.Recent<LPlaceholder> recentServer = new Utilities.Recent<>(100);
@@ -51,8 +50,7 @@ public class LPlaceholder extends ILabel.Impl {
public LPlaceholder(String name, long amount, boolean silent) {
super(amount, false);
this.name = name;
if (!silent)
getActive().push(new LPlaceholder(name, 1, true), false);
if (!silent) getActive().push(new LPlaceholder(name, 1, true), false);
}
public LPlaceholder(LPlaceholder label) {
@@ -119,7 +117,7 @@ public class LPlaceholder extends ILabel.Impl {
@SideOnly(Side.CLIENT)
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Tags.MODNAME);
}
public static boolean merge(ILabel a, ILabel b) {
@@ -127,15 +125,14 @@ public class LPlaceholder extends ILabel.Impl {
LPlaceholder lpA = (LPlaceholder) a;
LPlaceholder lpB = (LPlaceholder) b;
return lpA.name.equals(lpB.name);
} else
return false;
} else return false;
}
public static class Converter {
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
static List<Pair<Pattern, Function<Matcher, LPlaceholder>>> converters = Arrays.asList(
new Pair<>(Pattern.compile("\\[\\[Gas: mekanism:(.+)], (\\d+)]"),
i -> new LPlaceholder("Gas - " + capitalize(i.group(1)), Integer.parseInt(i.group(2)))));
static List<Pair<Pattern, Function<Matcher, LPlaceholder>>> converters = Arrays.asList(new Pair<>(
Pattern.compile("\\[\\[Gas: mekanism:(.+)], (\\d+)]"),
i -> new LPlaceholder("Gas - " + capitalize(i.group(1)), Integer.parseInt(i.group(2)))));
public static String capitalize(String s) {
String[] arr = s.replace('_', ' ').split(" ");
@@ -150,10 +147,14 @@ public class LPlaceholder extends ILabel.Impl {
public static LPlaceholder from(Object o) {
String s = o.toString();
return converters.stream().map(i -> {
Matcher m = i.one.matcher(s);
return m.matches() ? i.two.apply(m) : null;
}).filter(Objects::nonNull).findFirst().orElseGet(() -> new LPlaceholder(s, 1));
return converters.stream()
.map(i -> {
Matcher m = i.one.matcher(s);
return m.matches() ? i.two.apply(m) : null;
})
.filter(Objects::nonNull)
.findFirst()
.orElseGet(() -> new LPlaceholder(s, 1));
}
}
}
@@ -1,27 +1,22 @@
package me.towdium.jecalculation.data.structure;
import static me.towdium.jecalculation.utils.Utilities.stream;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.util.ChatComponentTranslation;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.data.structure.Recipe.IO.INPUT;
import static me.towdium.jecalculation.data.structure.Recipe.IO.OUTPUT;
import static me.towdium.jecalculation.utils.Utilities.stream;
// positive => generate; negative => require
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class CostList {
List<ILabel> labels;
public CostList() {
@@ -30,41 +25,50 @@ public class CostList {
public CostList(List<ILabel> labels) {
this.labels = labels.stream()
.filter(i -> i != ILabel.EMPTY)
.map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
.filter(i -> i != ILabel.EMPTY)
.map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
}
public CostList(List<ILabel> positive, List<ILabel> negative) {
this(positive);
multiply(-1);
merge(new CostList(negative), false, true);
mergeInplace(new CostList(negative), false);
}
@SuppressWarnings("UnusedReturnValue")
public CostList merge(CostList costList, boolean strict, boolean inplace) {
CostList ret = inplace ? this : copy();
costList.labels.forEach(i -> ret.labels.add(i.copy()));
for (int i = 0; i < ret.labels.size(); i++) {
for (int j = i + 1; j < ret.labels.size(); j++) {
public static CostList merge(CostList a, CostList b, boolean strict) {
CostList ret = a.copy();
ret.mergeInplace(b, strict);
return ret;
}
/**
* Merge that to this
*
* @param that cost list to merge
* @param strict if true, only merge same label
*/
public void mergeInplace(CostList that, boolean strict) {
that.labels.forEach(i -> this.labels.add(i.copy()));
for (int i = 0; i < this.labels.size(); i++) {
for (int j = i + 1; j < this.labels.size(); j++) {
if (strict) {
ILabel a = ret.labels.get(i);
ILabel b = ret.labels.get(j);
ILabel a = this.labels.get(i);
ILabel b = this.labels.get(j);
if (a.matches(b)) {
ret.labels.set(i, a.setAmount(Math.addExact(a.getAmount(), b.getAmount())));
ret.labels.set(j, ILabel.EMPTY);
this.labels.set(i, a.setAmount(Math.addExact(a.getAmount(), b.getAmount())));
this.labels.set(j, ILabel.EMPTY);
}
} else {
Optional<ILabel> l = ILabel.MERGER.merge(ret.labels.get(i), ret.labels.get(j));
Optional<ILabel> l = ILabel.MERGER.merge(this.labels.get(i), this.labels.get(j));
if (l.isPresent()) {
ret.labels.set(i, l.get());
ret.labels.set(j, ILabel.EMPTY);
this.labels.set(i, l.get());
this.labels.set(j, ILabel.EMPTY);
}
}
}
}
ret.labels = ret.labels.stream().filter(i -> i != ILabel.EMPTY).collect(Collectors.toList());
return ret;
this.labels = this.labels.stream().filter(i -> i != ILabel.EMPTY).collect(Collectors.toList());
}
public CostList multiply(long i) {
@@ -77,9 +81,8 @@ public class CostList {
if (obj instanceof CostList) {
CostList c = (CostList) obj;
CostList m = c.copy().multiply(-1);
return merge(m, true, false).labels.isEmpty();
} else
return false;
return CostList.merge(this, m, true).labels.isEmpty();
} else return false;
}
public CostList copy() {
@@ -88,7 +91,6 @@ public class CostList {
return ret;
}
public boolean isEmpty() {
return labels.isEmpty();
}
@@ -97,7 +99,6 @@ public class CostList {
return labels;
}
public Calculator calculate() {
return new Calculator();
}
@@ -105,8 +106,7 @@ public class CostList {
@Override
public int hashCode() {
int hash = 0;
for (ILabel i : labels)
hash ^= i.hashCode();
for (ILabel i : labels) hash ^= i.hashCode();
return hash;
}
@@ -117,59 +117,63 @@ public class CostList {
private int index;
public Calculator() throws ArithmeticException {
EntityClientPlayerMP player = Utilities.getPlayer();
HashSet<CostList> set = new HashSet<>();
set.add(CostList.this);
Pair<Recipe, Long> next = find(true);
// reset index & iterator
reset();
Pair<Recipe, Long> next = find();
int count = 0;
while (next != null) {
CostList original = getCurrent();
List<ILabel> outL = next.one.getLabel(OUTPUT)
.stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
List<ILabel> outL = next.one.getOutput().stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
CostList outC = new CostList(outL);
outC.multiply(-next.two);
List<ILabel> inL = next.one.getLabel(INPUT)
.stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
List<ILabel> inL = next.one.getInput().stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
CostList inC = new CostList(inL);
inC.multiply(next.two);
CostList result = original.merge(outC, false, false);
result.merge(inC, false, true);
if (set.contains(result))
next = find(false);
else {
CostList result = CostList.merge(original, outC, false);
result.mergeInplace(inC, false);
if (!set.contains(result)) {
set.add(result);
procedure.add(new Pair<>(result, outC));
addCatalyst(next.one.getLabel(Recipe.IO.CATALYST));
next = find(true);
addCatalyst(next.one.getCatalyst());
reset();
}
if (count++ > 1000 && player != null) {
player.addChatMessage(
new ChatComponentTranslation("jecalculation.chat.max_loop"));
next = find();
if (count++ > 1000) {
Utilities.addChatMessage(Utilities.ChatMessage.MAX_LOOP);
break;
}
}
}
private void reset() {
index = 0;
iterator = Controller.recipeIterator();
}
/**
* Find next recipe and its amount
*
* @return pair of the next recipe and its amount
*/
@Nullable
private Pair<Recipe, Long> find(boolean reset) {
if (reset) {
index = 0;
iterator = Controller.recipeIterator();
}
private Pair<Recipe, Long> find() {
List<ILabel> labels = getCurrent().labels;
for (; index < labels.size(); index++) {
ILabel label = labels.get(index);
if (label.getAmount() >= 0)
continue;
// Only negative label is required to calculate
if (label.getAmount() >= 0) continue;
// Find the recipe for the label.
// Reset or not reset the iterator is a question
while (iterator.hasNext()) {
Recipe r = iterator.next();
if (r.matches(label).isPresent())
return new Pair<>(r, r.multiplier(label));
if (r.matches(label).isPresent()) return new Pair<>(r, r.multiplier(label));
}
iterator = Controller.recipeIterator();
}
@@ -177,13 +181,11 @@ public class CostList {
}
private void addCatalyst(List<ILabel> labels) {
labels.stream()
.filter(i -> i != ILabel.EMPTY)
.forEach(i -> catalysts.stream()
.filter(j -> j.matches(i))
.findAny()
.map(j -> j.setAmount(Math.max(i.getAmount(), j.getAmount())))
.orElseGet(Utilities.fake(() -> catalysts.add(i))));
labels.stream().filter(i -> i != ILabel.EMPTY).forEach(i -> catalysts.stream()
.filter(j -> j.matches(i))
.findAny()
.map(j -> j.setAmount(Math.max(i.getAmount(), j.getAmount())))
.orElseGet(Utilities.fake(() -> catalysts.add(i))));
}
private CostList getCurrent() {
@@ -196,28 +198,30 @@ public class CostList {
public List<ILabel> getInputs() {
return getCurrent().labels.stream()
.filter(i -> i.getAmount() < 0)
.map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
.filter(i -> i.getAmount() < 0)
.map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
}
public List<ILabel> getOutputs(List<ILabel> ignore) {
return getCurrent().labels.stream()
.map(i -> i.copy().multiply(-1))
.map(i -> ignore.stream()
.flatMap(j -> stream(ILabel.MERGER.merge(i, j)))
.findFirst()
.orElse(i))
.filter(i -> i != ILabel.EMPTY && i.getAmount() < 0)
.map(i -> i.multiply(-1))
.collect(Collectors.toList());
.map(i -> i.copy().multiply(-1))
.map(i -> ignore.stream()
.flatMap(j -> stream(ILabel.MERGER.merge(i, j)))
.findFirst()
.orElse(i))
.filter(i -> i != ILabel.EMPTY && i.getAmount() < 0)
.map(i -> i.multiply(-1))
.collect(Collectors.toList());
}
public List<ILabel> getSteps() {
List<ILabel> ret = procedure.stream().map(i -> i.two.labels.get(0)).collect(Collectors.toList());
Collections.reverse(ret);
CostList cl = new CostList(ret).multiply(-1);
return new CostList().merge(cl, false, true).labels;
CostList temp = new CostList();
temp.mergeInplace(cl, false);
return temp.labels;
}
}
}
@@ -1,13 +1,5 @@
package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -18,6 +10,13 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
/**
* Author: towdium
@@ -34,35 +33,34 @@ public class Recipe {
List<ILabel> output;
public Recipe(NBTTagCompound nbt) {
this(readNbtList(nbt.getTagList(KEY_INPUT, 10)), readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
this(
readNbtList(nbt.getTagList(KEY_INPUT, 10)),
readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
}
public Recipe(List<ILabel> input, List<ILabel> catalyst, List<ILabel> output) {
boolean a = Stream.of(input, output, catalyst).anyMatch(i ->
!i.isEmpty() && i.get(i.size() - 1) == ILabel.EMPTY);
boolean b = Stream.of(input, output).anyMatch(i ->
i.stream().allMatch(j -> j == ILabel.EMPTY));
boolean a =
Stream.of(input, output, catalyst).anyMatch(i -> !i.isEmpty() && i.get(i.size() - 1) == ILabel.EMPTY);
boolean b = Stream.of(input, output).anyMatch(i -> i.stream().allMatch(j -> j == ILabel.EMPTY));
if (a || b) throw new IllegalArgumentException("Invalid recipe");
this.input = input;
this.catalyst = catalyst;
this.output = output;
}
static private List<ILabel> readNbtList(NBTTagList list) {
private static List<ILabel> readNbtList(NBTTagList list) {
return StreamSupport.stream(NBTHelper.spliterator(list), false)
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
}
@Override
public int hashCode() {
int[] hash = new int[1];
Consumer<List<ILabel>> hasher = (ls) -> ls.stream()
.filter(Objects::nonNull)
.forEach(i -> hash[0] ^= i.hashCode());
Consumer<List<ILabel>> hasher =
(ls) -> ls.stream().filter(Objects::nonNull).forEach(i -> hash[0] ^= i.hashCode());
hasher.accept(input);
hasher.accept(catalyst);
hasher.accept(output);
@@ -71,20 +69,28 @@ public class Recipe {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Recipe))
return false;
if (!(obj instanceof Recipe)) return false;
Recipe r = (Recipe) obj;
BiPredicate<List<ILabel>, List<ILabel>> p = (i, j) -> {
if (i.size() != j.size())
return false;
for (int k = 0; k < i.size(); k++)
if (!i.get(k).equals(j.get(k)))
return false;
if (i.size() != j.size()) return false;
for (int k = 0; k < i.size(); k++) if (!i.get(k).equals(j.get(k))) return false;
return true;
};
return p.test(input, r.input) && p.test(catalyst, r.catalyst) && p.test(output, r.output);
}
public List<ILabel> getInput() {
return input;
}
public List<ILabel> getOutput() {
return output;
}
public List<ILabel> getCatalyst() {
return catalyst;
}
public List<ILabel> getLabel(IO type) {
return get(type, input, output, catalyst);
}
@@ -103,9 +109,7 @@ public class Recipe {
}
public ILabel getRep() {
for (int i = 0; i < 8; i++)
if (output.get(i) != ILabel.EMPTY)
return output.get(i);
for (int i = 0; i < 8; i++) if (output.get(i) != ILabel.EMPTY) return output.get(i);
return ILabel.EMPTY;
}
@@ -132,23 +136,29 @@ public class Recipe {
}
public Optional<ILabel> matches(ILabel label) {
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny();
return output.stream()
.filter(i -> ILabel.MERGER.merge(label, i).isPresent())
.findAny();
}
public long multiplier(ILabel label) {
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny().map(i -> {
long amountA = label.getAmount();
if (!label.isPercent())
amountA = Math.multiplyExact(amountA, 100L);
long amountB = i.getAmount();
if (!i.isPercent())
amountB = Math.multiplyExact(amountB, 100L);
return (amountB + Math.abs(amountA) - 1) / amountB;
}).orElse(0L);
return output.stream()
.filter(i -> ILabel.MERGER.merge(label, i).isPresent())
.findAny()
.map(i -> {
long amountA = label.getAmount();
if (!label.isPercent()) amountA = Math.multiplyExact(amountA, 100L);
long amountB = i.getAmount();
if (!i.isPercent()) amountB = Math.multiplyExact(amountB, 100L);
return (amountB + Math.abs(amountA) - 1) / amountB;
})
.orElse(0L);
}
public enum IO {
INPUT, OUTPUT, CATALYST;
INPUT,
OUTPUT,
CATALYST;
public static IO isInput(boolean b) {
return b ? INPUT : OUTPUT;
@@ -1,5 +1,13 @@
package me.towdium.jecalculation.data.structure;
import java.io.File;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.JecaConfig;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
@@ -10,20 +18,10 @@ import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.io.File;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Author: towdium
* Date: 18-8-28.
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class Recipes {
@@ -32,8 +30,7 @@ public class Recipes {
public Recipes() {
File file = JecaConfig.defaultFile;
NBTTagCompound nbt = Utilities.Json.read(file);
if (nbt == null)
JustEnoughCalculation.logger.info("Failed to load default records at " + file + ".");
if (nbt == null) JustEnoughCalculation.logger.info("Failed to load default records at " + file + ".");
else {
JustEnoughCalculation.logger.info("Loading default records at " + file + ".");
deserialize(nbt);
@@ -50,14 +47,14 @@ public class Recipes {
keySet.stream().sorted().forEach(i -> {
NBTTagList group = nbt.getTagList(i, 10);
StreamSupport.stream(NBTHelper.spliterator(group), false)
.filter(r -> r instanceof NBTTagCompound)
.forEach(r -> {
try {
add(i, new Recipe((NBTTagCompound) r));
} catch (IllegalArgumentException e) {
JustEnoughCalculation.logger.warn("Invalid recipe record :" + r);
}
});
.filter(r -> r instanceof NBTTagCompound)
.forEach(r -> {
try {
add(i, new Recipe((NBTTagCompound) r));
} catch (IllegalArgumentException e) {
JustEnoughCalculation.logger.warn("Invalid recipe record :" + r);
}
});
});
}
@@ -73,19 +70,13 @@ public class Recipes {
public void modify(String neu, @Nullable String old, int index, @Nullable Recipe recipe) {
if (index == -1) {
if (recipe != null)
add(neu, recipe);
else if (old != null)
renameGroup(old, neu);
else
remove(neu);
if (recipe != null) add(neu, recipe);
else if (old != null) renameGroup(old, neu);
else remove(neu);
} else {
if (recipe == null)
remove(neu, index);
else if (old == null || old.equals(neu))
set(neu, index, recipe);
else
set(neu, old, index, recipe);
if (recipe == null) remove(neu, index);
else if (old == null || old.equals(neu)) set(neu, index, recipe);
else set(neu, old, index, recipe);
}
}
@@ -109,8 +100,7 @@ public class Recipes {
public void remove(String group, int index) {
List<Recipe> l = records.get(group);
l.remove(index);
if (l.isEmpty())
records.remove(group);
if (l.isEmpty()) records.remove(group);
}
public void remove(String group) {
@@ -191,8 +181,7 @@ public class Recipes {
List<Recipe> rs = records.get(group);
index = rs.size();
j = new ReversedIterator<>(rs);
} else
return false;
} else return false;
}
return true;
}
@@ -1,15 +1,14 @@
package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
/**
* Author: Towdium
@@ -28,9 +27,9 @@ public class RecordCraft implements IRecord {
public RecordCraft(NBTTagCompound nbt) {
List<ILabel> ls = StreamSupport.stream(NBTHelper.spliterator(nbt.getTagList(KEY_RECENTS, 10)), false)
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
new Utilities.ReversedIterator<>(ls).forEachRemaining(l -> record.push(l, false));
amount = nbt.getString(KEY_AMOUNT);
inventory = nbt.getBoolean(KEY_INVENTORY);
@@ -67,6 +66,9 @@ public class RecordCraft implements IRecord {
}
public enum Mode {
INPUT, OUTPUT, CATALYST, STEPS
INPUT,
OUTPUT,
CATALYST,
STEPS
}
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.data.structure;
import net.minecraft.nbt.NBTTagCompound;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
/**
* Author: Towdium
@@ -25,10 +24,18 @@ public class RecordMath implements IRecord {
public Operator operator;
String current;
public enum State {INPUT, OUTPUT, ERROR}
public enum State {
INPUT,
OUTPUT,
ERROR
}
public enum Operator {
EQUALS, PLUS, MINUS, TIMES, DIVIDE;
EQUALS,
PLUS,
MINUS,
TIMES,
DIVIDE;
public BigDecimal operate(BigDecimal a, BigDecimal b) {
switch (this) {
@@ -48,21 +55,15 @@ public class RecordMath implements IRecord {
}
}
public RecordMath(State state,
Operator operator,
BigDecimal last,
boolean sign,
int dot,
List<BigDecimal> numbers) {
public RecordMath(
State state, Operator operator, BigDecimal last, boolean sign, int dot, List<BigDecimal> numbers) {
this.state = state;
this.operator = operator;
this.last = last;
StringBuilder sb = new StringBuilder();
if (!sign)
sb.append('-');
if (!sign) sb.append('-');
numbers.forEach(i -> sb.append(i.toString()));
if (dot != DOT_NONE)
sb.insert(sb.length() - dot, '.');
if (dot != DOT_NONE) sb.insert(sb.length() - dot, '.');
current = sb.toString();
}
@@ -89,19 +90,16 @@ public class RecordMath implements IRecord {
public LinkedList<BigDecimal> getNumbers() {
LinkedList<BigDecimal> ret = new LinkedList<>();
if (current == null)
return ret;
if (current == null) return ret;
for (int i = 0; i < current.length(); i++) {
char ch = current.charAt(i);
if (ch != '-' && ch != '.')
ret.add(new BigDecimal(ch - '0'));
if (ch != '-' && ch != '.') ret.add(new BigDecimal(ch - '0'));
}
return ret;
}
public int getDot() {
if (current == null)
return DOT_NONE;
if (current == null) return DOT_NONE;
int index = current.indexOf('.');
return index == -1 ? DOT_NONE : current.length() - index - 1;
}
@@ -11,7 +11,7 @@ public class RecordPlayer implements IRecord {
public static final String KEY_LAST = "last";
public Recipes recipes;
public String last; // last group edited
public String last; // last group edited
public RecordPlayer() {
recipes = new Recipes();
@@ -25,8 +25,7 @@ public class RecordPlayer implements IRecord {
@Override
public NBTTagCompound serialize() {
NBTTagCompound ret = new NBTTagCompound();
if (last != null)
ret.setString(KEY_LAST, last);
if (last != null) ret.setString(KEY_LAST, last);
ret.setTag(KEY_RECIPES, recipes.serialize());
return ret;
}
@@ -2,13 +2,12 @@ package me.towdium.jecalculation.event;
import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.FMLCommonHandler;
import java.util.ArrayList;
import me.towdium.jecalculation.event.handlers.EBusEventHandler;
import me.towdium.jecalculation.event.handlers.FMLBusEventHandler;
import me.towdium.jecalculation.event.handlers.NEIEventHandler;
import net.minecraftforge.common.MinecraftForge;
import java.util.ArrayList;
public class Handlers {
public static final ArrayList<Object> fmlHandlers;
public static final ArrayList<Object> ebHandlers;
@@ -3,7 +3,4 @@ package me.towdium.jecalculation.event.handlers;
/**
* register to MinecraftForge.EVENT_BUS
*/
public class EBusEventHandler {
}
public class EBusEventHandler {}
@@ -42,6 +42,4 @@ public class FMLBusEventHandler {
JecaGui.onGameTick();
}
}
}
@@ -16,20 +16,18 @@ public class NEIEventHandler implements IContainerInputHandler {
}
@Override
public void onKeyTyped(GuiContainer guiContainer, char c, int i) {
}
public void onKeyTyped(GuiContainer guiContainer, char c, int i) {}
@Override
public boolean lastKeyTyped(GuiContainer guiContainer, char keyChar, int keyCode) {
if (guiContainer == Minecraft.getMinecraft().currentScreen && guiContainer instanceof JecaGui) {
JecaGui gui = (JecaGui) guiContainer;
ILabel label = gui.getLabelUnderMouse();
if (label == null)
return false;
if (label == null) return false;
Object stack = label.getRepresentation();
if (keyCode == NEIClientConfig.getKeyBinding("gui.usage") ||
(keyCode == NEIClientConfig.getKeyBinding("gui.recipe") && NEIClientUtils.shiftKey())) {
if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")
|| (keyCode == NEIClientConfig.getKeyBinding("gui.recipe") && NEIClientUtils.shiftKey())) {
return NEIPlugin.openRecipeGui(stack, true);
}
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) {
@@ -48,9 +46,7 @@ public class NEIEventHandler implements IContainerInputHandler {
}
@Override
public void onMouseClicked(GuiContainer guiContainer, int i, int i1, int i2) {
}
public void onMouseClicked(GuiContainer guiContainer, int i, int i1, int i2) {}
@Override
public void onMouseUp(GuiContainer guiContainer, int i, int i1, int i2) {
@@ -63,12 +59,8 @@ public class NEIEventHandler implements IContainerInputHandler {
}
@Override
public void onMouseScrolled(GuiContainer guiContainer, int i, int i1, int i2) {
}
public void onMouseScrolled(GuiContainer guiContainer, int i, int i1, int i2) {}
@Override
public void onMouseDragged(GuiContainer guiContainer, int i, int i1, int i2, long l) {
}
public void onMouseDragged(GuiContainer guiContainer, int i, int i1, int i2, long l) {}
}
@@ -1,13 +1,20 @@
package me.towdium.jecalculation.gui;
import static org.lwjgl.input.Keyboard.KEY_NONE;
import cpw.mods.fml.client.config.GuiUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.guis.GuiCraft;
import me.towdium.jecalculation.gui.guis.GuiMath;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.WLabel;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.ItemStackHelper;
@@ -32,15 +39,6 @@ import net.minecraftforge.fluids.Fluid;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static org.lwjgl.input.Keyboard.KEY_NONE;
/**
* Author: towdium
* Date: 8/12/17.
@@ -48,18 +46,20 @@ import static org.lwjgl.input.Keyboard.KEY_NONE;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class JecaGui extends GuiContainer {
public static final KeyBinding keyOpenGuiCraft = new KeyBinding("jecalculation.key.gui_craft", KEY_NONE,
"jecalculation.key.category");
public static final KeyBinding keyOpenGuiMath = new KeyBinding("jecalculation.key.gui_math", KEY_NONE,
"jecalculation.key.category");
public static final KeyBinding keyOpenGuiCraft =
new KeyBinding("jecalculation.key.gui_craft", KEY_NONE, "jecalculation.key.category");
public static final KeyBinding keyOpenGuiMath =
new KeyBinding("jecalculation.key.gui_math", KEY_NONE, "jecalculation.key.category");
public static final int COLOR_GUI_GREY = 0xFFA1A1A1;
public static final int COLOR_TEXT_RED = 0xFF0000;
public static final int COLOR_TEXT_GREY = 0x404040;
public static final int COLOR_TEXT_WHITE = 0xFFFFFF;
public static final boolean ALWAYS_TOOLTIP = false;
@SuppressWarnings("StringOperationCanBeSimplified")
public static final String SEPARATOR = new String();
public ILabel hand = ILabel.EMPTY;
protected static JecaGui last;
protected static Runnable scheduled;
@@ -75,8 +75,7 @@ public class JecaGui extends GuiContainer {
super(acceptsTransfer ? new JecaGui.ContainerTransfer() : new JecaGui.ContainerNonTransfer());
this.parent = parent;
this.root = root;
if (inventorySlots instanceof JecaContainer)
((JecaContainer) inventorySlots).setGui(this);
if (inventorySlots instanceof JecaContainer) ((JecaContainer) inventorySlots).setGui(this);
}
public static int getMouseX() {
@@ -89,22 +88,19 @@ public class JecaGui extends GuiContainer {
return gui.height - Mouse.getEventY() * gui.height / gui.mc.displayHeight - 1 - gui.guiTop;
}
/**
* @return true to terminate further processing of this event.
*/
public static boolean onMouse() {
Optional<JecaGui> optionalJecaGui = currentJecaGui();
if (!optionalJecaGui.isPresent())
return false;
if (!optionalJecaGui.isPresent()) return false;
JecaGui gui = optionalJecaGui.get();
int xMouse = getMouseX();
int yMouse = getMouseY();
int button = Mouse.getEventButton();
if (button == -1) {
int diff = Mouse.getEventDWheel() / 120;
if (diff != 0)
gui.root.onMouseScroll(gui, xMouse, yMouse, diff);
if (diff != 0) gui.root.onMouseScroll(gui, xMouse, yMouse, diff);
} else if (Mouse.getEventButtonState()) {
gui.root.onMouseFocused(gui, xMouse, yMouse, button);
if (gui.root.onMouseClicked(gui, xMouse, yMouse, button)) {
@@ -125,8 +121,7 @@ public class JecaGui extends GuiContainer {
public static void onMouseReleased() {
Optional<JecaGui> optionalJecaGui = currentJecaGui();
if (!optionalJecaGui.isPresent())
return;
if (!optionalJecaGui.isPresent()) return;
JecaGui gui = optionalJecaGui.get();
int xMouse = getMouseX();
int yMouse = getMouseY();
@@ -134,15 +129,13 @@ public class JecaGui extends GuiContainer {
gui.root.onMouseReleased(gui, xMouse, yMouse, button);
}
@Nullable
public Slot getSlotUnderMouse() {
IInventory i = new InventoryBasic("", false, 1);
Slot s = new Slot(i, 0, 0, 0);
ILabel l = getLabelUnderMouse();
Object rep = l == null ? null : l.getRepresentation();
if (rep instanceof ItemStack)
s.putStack((ItemStack) rep);
if (rep instanceof ItemStack) s.putStack((ItemStack) rep);
return s;
}
@@ -161,14 +154,12 @@ public class JecaGui extends GuiContainer {
public static void displayGui(boolean updateParent, boolean acceptsTransfer, boolean scheduled, IGui root) {
Runnable r = () -> {
// isCallingFromMinecraftThread
if (Minecraft.getMinecraft().func_152345_ab())
displayGuiUnsafe(updateParent, acceptsTransfer, root);
if (Minecraft.getMinecraft().func_152345_ab()) displayGuiUnsafe(updateParent, acceptsTransfer, root);
};
if (scheduled) {
JecaGui.scheduled = r;
JecaGui.timeout = 1;
} else
r.run();
} else r.run();
}
public static Optional<JecaGui> currentJecaGui() {
@@ -194,14 +185,10 @@ public class JecaGui extends GuiContainer {
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IGui root) {
Minecraft mc = Minecraft.getMinecraft();
JecaGui parent;
if (mc.currentScreen == null)
parent = null;
else if (!(mc.currentScreen instanceof JecaGui))
parent = last;
else if (updateParent)
parent = (JecaGui) mc.currentScreen;
else
parent = ((JecaGui) mc.currentScreen).parent;
if (mc.currentScreen == null) parent = null;
else if (!(mc.currentScreen instanceof JecaGui)) parent = last;
else if (updateParent) parent = (JecaGui) mc.currentScreen;
else parent = ((JecaGui) mc.currentScreen).parent;
JecaGui toShow = new JecaGui(parent, acceptsTransfer, root);
root.onVisible(toShow);
last = toShow;
@@ -229,10 +216,8 @@ public class JecaGui extends GuiContainer {
* I think they won't conflict
*/
public static void onKey() {
if (keyOpenGuiCraft.isPressed())
JecaGui.openGuiCraft(false);
if (keyOpenGuiMath.isPressed())
JecaGui.openGuiMath(false);
if (keyOpenGuiCraft.isPressed()) JecaGui.openGuiCraft(false);
if (keyOpenGuiMath.isPressed()) JecaGui.openGuiMath(false);
}
public static void onGameTick() {
@@ -241,8 +226,7 @@ public class JecaGui extends GuiContainer {
Runnable r = scheduled;
scheduled = null;
r.run();
} else
timeout--;
} else timeout--;
}
}
@@ -302,22 +286,17 @@ public class JecaGui extends GuiContainer {
int separators = 0;
for (String s : textLines) {
int j = font.getStringWidth(s);
if (j > i)
i = j;
if (j > i) i = j;
//noinspection StringEquality
if (s == JecaGui.SEPARATOR)
separators++;
if (s == JecaGui.SEPARATOR) separators++;
}
//noinspection StringEquality
if (textLines.get(textLines.size() - 1) == SEPARATOR)
separators--;
if (textLines.get(textLines.size() - 1) == SEPARATOR) separators--;
int l1 = x + 12;
int i2 = y - 12;
int k = 8 + (textLines.size() - separators - 1) * 10 + 2 * separators;
if (l1 + i > this.width)
l1 -= 28 + i;
if (i2 + k + 6 > this.height)
i2 = this.height - k - 6;
if (l1 + i > this.width) l1 -= 28 + i;
if (i2 + k + 6 > this.height) i2 = this.height - k - 6;
zLevel = 300.0F;
itemRender.zLevel = 300.0F;
drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, -267386864, -267386864);
@@ -331,8 +310,7 @@ public class JecaGui extends GuiContainer {
drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, 1344798847, 1344798847);
for (String s1 : textLines) {
//noinspection StringEquality
if (s1 == SEPARATOR)
i2 += 2;
if (s1 == SEPARATOR) i2 += 2;
else {
font.drawStringWithShadow(s1, l1, i2, -1);
i2 += 10;
@@ -361,18 +339,31 @@ public class JecaGui extends GuiContainer {
drawResourceContinuous(r, xPos, yPos, xSize, ySize, border, border, border, border);
}
public void drawResourceContinuous(Resource r,
int xPos,
int yPos,
int xSize,
int ySize,
int borderTop,
int borderBottom,
int borderLeft,
int borderRight) {
GuiUtils.drawContinuousTexturedBox(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), xSize, ySize,
r.getXSize(), r.getYSize(), borderTop, borderBottom, borderLeft, borderRight,
0);
public void drawResourceContinuous(
Resource r,
int xPos,
int yPos,
int xSize,
int ySize,
int borderTop,
int borderBottom,
int borderLeft,
int borderRight) {
GuiUtils.drawContinuousTexturedBox(
r.getResourceLocation(),
xPos,
yPos,
r.getXPos(),
r.getYPos(),
xSize,
ySize,
r.getXSize(),
r.getYSize(),
borderTop,
borderBottom,
borderLeft,
borderRight,
0);
}
private void setColor(int color) {
@@ -385,12 +376,10 @@ public class JecaGui extends GuiContainer {
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
IIcon fluidIcon = f.getFlowingIcon();
if (fluidIcon == null)
fluidIcon = f.getStillIcon();
if (fluidIcon == null) fluidIcon = f.getStillIcon();
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
setColor(f.getColor() & 0x00FFFFFF);
if (fluidIcon != null)
drawTexturedModelRectFromIcon(xPos, yPos, fluidIcon, xSize, ySize);
if (fluidIcon != null) drawTexturedModelRectFromIcon(xPos, yPos, fluidIcon, xSize, ySize);
}
public void drawRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
@@ -426,10 +415,8 @@ public class JecaGui extends GuiContainer {
drawText(xPos, yPos, f, () -> {
int y = 0;
for (String i : ss) {
if (f.shadow)
fontRendererObj.drawStringWithShadow(i, 0, y, f.color);
else
fontRendererObj.drawString(i, 0, y, f.color);
if (f.shadow) fontRendererObj.drawStringWithShadow(i, 0, y, f.color);
else fontRendererObj.drawString(i, 0, y, f.color);
y += fontRendererObj.FONT_HEIGHT + 1;
}
});
@@ -446,20 +433,17 @@ public class JecaGui extends GuiContainer {
int ellipsisWidth = f.getTextWidth("...");
if (strWidth > width && strWidth > ellipsisWidth)
str = f.trimToWidth(str, width - ellipsisWidth).trim() + "...";
if (f.shadow)
fontRendererObj.drawStringWithShadow(str, 0, 0, f.color);
if (f.shadow) fontRendererObj.drawStringWithShadow(str, 0, 0, f.color);
fontRendererObj.drawString(str, 0, 0, f.color);
});
}
private void drawText(float xPos, float yPos, Font f, Runnable r) {
boolean unicode = fontRendererObj.getUnicodeFlag();
if (f.raw)
fontRendererObj.setUnicodeFlag(false);
if (f.raw) fontRendererObj.setUnicodeFlag(false);
GlStateManager.pushMatrix();
GlStateManager.translate(xPos, yPos, 0);
if (f.half)
GlStateManager.scale(0.5, 0.5, 1);
if (f.half) GlStateManager.scale(0.5, 0.5, 1);
r.run();
GlStateManager.popMatrix();
fontRendererObj.setUnicodeFlag(unicode);
@@ -477,8 +461,7 @@ public class JecaGui extends GuiContainer {
GlStateManager.enableDepth();
RenderHelper.enableGUIStandardItemLighting();
FontRenderer font = is.getItem().getFontRenderer(is);
if (font == null)
font = this.fontRendererObj;
if (font == null) font = this.fontRendererObj;
itemRender.renderItemAndEffectIntoGUI(font, Minecraft.getMinecraft().renderEngine, is, xPos, yPos);
itemRender.renderItemOverlayIntoGUI(font, Minecraft.getMinecraft().renderEngine, is, xPos, yPos);
RenderHelper.disableStandardItemLighting();
@@ -494,13 +477,10 @@ public class JecaGui extends GuiContainer {
@Override
protected void keyTyped(char typedChar, int keyCode) {
if (keyCode == Keyboard.KEY_ESCAPE && hand != ILabel.EMPTY)
hand = ILabel.EMPTY;
if (keyCode == Keyboard.KEY_ESCAPE && hand != ILabel.EMPTY) hand = ILabel.EMPTY;
else if (!root.onKeyPressed(this, typedChar, keyCode)) {
if (keyCode == Keyboard.KEY_ESCAPE && parent != null)
displayParent();
else
super.keyTyped(typedChar, keyCode);
if (keyCode == Keyboard.KEY_ESCAPE && parent != null) displayParent();
else super.keyTyped(typedChar, keyCode);
}
}
@@ -524,8 +504,7 @@ public class JecaGui extends GuiContainer {
public int getTextWidth(String s) {
FontRenderer fr = getCurrent().fontRendererObj;
boolean flag = fr.getUnicodeFlag();
if (raw)
fr.setUnicodeFlag(false);
if (raw) fr.setUnicodeFlag(false);
int ret = (int) Math.ceil(fr.getStringWidth(s) * (half ? 0.5f : 1));
fr.setUnicodeFlag(flag);
return ret;
@@ -540,7 +519,6 @@ public class JecaGui extends GuiContainer {
}
}
@SideOnly(Side.CLIENT)
public static class JecaContainer extends Container {
JecaGui gui;
@@ -560,15 +538,12 @@ public class JecaGui extends GuiContainer {
}
@SideOnly(Side.CLIENT)
public static class ContainerTransfer extends JecaContainer {
}
public static class ContainerTransfer extends JecaContainer {}
@SideOnly(Side.CLIENT)
public static class ContainerNonTransfer extends JecaContainer {
}
public static class ContainerNonTransfer extends JecaContainer {}
public void drawHoveringText(List<String> textLines, int x, int y) {
this.drawHoveringText(textLines, x, y, fontRendererObj);
}
}
@@ -2,10 +2,9 @@ package me.towdium.jecalculation.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.util.ResourceLocation;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.Tags;
import net.minecraft.util.ResourceLocation;
/**
* Author: towdium
@@ -14,8 +13,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class Resource {
public static final ResourceLocation location = new ResourceLocation(
JustEnoughCalculation.Reference.MODID, "textures/gui/resources.png");
public static final ResourceLocation location = new ResourceLocation(Tags.MODID, "textures/gui/resources.png");
// letters abbr for button & icon: N - normal, F - focused, D - disabled
// letters abbr for fuzzy related: N - normal, F - fuzzy
// letters abbr for state related: N - normal, A - active
@@ -1,11 +1,10 @@
package me.towdium.jecalculation.gui.guis;
import me.towdium.jecalculation.gui.widgets.IWidget;
import me.towdium.jecalculation.gui.widgets.WContainer;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.widgets.IWidget;
import me.towdium.jecalculation.gui.widgets.WContainer;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
@@ -20,8 +19,7 @@ public class Gui extends WContainer implements IGui {
public void setOverlay(@Nullable IWidget overlay) {
this.overlay.clear();
if (overlay != null)
this.overlay.add(overlay);
if (overlay != null) this.overlay.add(overlay);
}
@Override
@@ -1,7 +1,14 @@
package me.towdium.jecalculation.gui.guis;
import static me.towdium.jecalculation.data.structure.RecordCraft.Mode.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.CostList;
@@ -18,14 +25,6 @@ import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static me.towdium.jecalculation.data.structure.RecordCraft.Mode.*;
/**
* Author: towdium
* Date: 8/14/17.
@@ -37,25 +36,28 @@ public class GuiCraft extends Gui {
Calculator calculator = null;
RecordCraft record;
WLabel label = new WLabel(31, 7, 20, 20, true).setLsnrUpdate((i, v) -> refreshLabel(v, false, true));
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrLeftClick(
(i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) {
label.setLabel(i.get(v).getLabel().copy(), true);
}
});
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrLeftClick((i, v) -> {
Object rep = i.get(v).getLabel().getRepresentation();
NEIPlugin.openRecipeGui(rep, false);
}).setLsnrRightClick((widget, value) -> {
Object rep = widget.get(value).getLabel().getRepresentation();
NEIPlugin.openRecipeGui(rep, true);
}).setFmtAmount(i -> i.getAmountString(true)).setFmtTooltip((i, j) -> i.getToolTip(j, true));
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrLeftClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) {
label.setLabel(i.get(v).getLabel().copy(), true);
}
});
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false)
.setLsnrLeftClick((i, v) -> {
Object rep = i.get(v).getLabel().getRepresentation();
NEIPlugin.openRecipeGui(rep, false);
})
.setLsnrRightClick((widget, value) -> {
Object rep = widget.get(value).getLabel().getRepresentation();
NEIPlugin.openRecipeGui(rep, true);
})
.setFmtAmount(i -> i.getAmountString(true))
.setFmtTooltip((i, j) -> i.getToolTip(j, true));
WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "craft.step").setListener(i -> setMode(STEPS));
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "common.catalyst").setListener(
i -> setMode(CATALYST));
WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "craft.output").setListener(
i -> setMode(OUTPUT));
WButton catalyst =
new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "common.catalyst").setListener(i -> setMode(CATALYST));
WButton output =
new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "craft.output").setListener(i -> setMode(OUTPUT));
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "common.input").setListener(i -> setMode(INPUT));
WButton invE = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_E, "craft.inventory_enabled");
WButton invD = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_D, "craft.inventory_disabled");
@@ -65,21 +67,20 @@ public class GuiCraft extends Gui {
refreshCalculator();
});
public GuiCraft() {
record = Controller.getRCraft();
amount.setText(record.amount);
add(new WHelp("craft"));
add(new WPanel());
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "craft.label").setListener(
i -> JecaGui.displayGui(new GuiLabel(l -> {
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "craft.label")
.setListener(i -> JecaGui.displayGui(new GuiLabel(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}))));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "craft.recipe").setListener(
i -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "craft.search").setListener(
i -> JecaGui.displayGui(new GuiSearch())));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "craft.recipe")
.setListener(i -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "craft.search")
.setListener(i -> JecaGui.displayGui(new GuiSearch())));
add(new WText(53, 13, JecaGui.Font.RAW, "x"));
add(new WLine(55));
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "craft.history"));
@@ -137,7 +138,8 @@ public class GuiCraft extends Gui {
String s = amount.getText();
long i = s.isEmpty() ? 1 : Long.parseLong(amount.getText());
amount.setColor(JecaGui.COLOR_TEXT_WHITE);
List<ILabel> dest = Collections.singletonList(label.getLabel().copy().setAmount(i));
List<ILabel> dest =
Collections.singletonList(label.getLabel().copy().setAmount(i));
CostList list = record.inventory ? new CostList(getInventory(), dest) : new CostList(dest);
calculator = list.calculate();
} catch (NumberFormatException | ArithmeticException e) {
@@ -151,14 +153,13 @@ public class GuiCraft extends Gui {
InventoryPlayer inv = Utilities.getPlayer().inventory;
ArrayList<ILabel> labels = new ArrayList<>();
Consumer<ItemStack[]> add = i -> Arrays.stream(i)
.filter(j -> !ItemStackHelper.isEmpty(j))
.forEach(j -> labels.add(ILabel.Converter.from(j)));
.filter(j -> !ItemStackHelper.isEmpty(j))
.forEach(j -> labels.add(ILabel.Converter.from(j)));
add.accept(inv.armorInventory);
add.accept(inv.mainInventory);
return labels;
}
void refreshResult() {
if (calculator == null) {
result.setLabels(new ArrayList<>());
@@ -192,24 +193,21 @@ public class GuiCraft extends Gui {
Stream.of(guess.one, guess.two).flatMap(Collection::stream).forEach(i -> {
List<ILabel> list = findRecipe(i);
list.forEach(j -> match.add(j.setPercent(false).setAmount(1)));
if (!list.isEmpty())
fuzzy.add(i);
if (!list.isEmpty()) fuzzy.add(i);
});
match.addAll(fuzzy);
List<ILabel> list = new ArrayList<>(match);
if (!match.isEmpty())
setOverlay(new Suggest(list.size() > 3 ? list.subList(0, 3) : list, !dup));
if (!match.isEmpty()) setOverlay(new Suggest(list.size() > 3 ? list.subList(0, 3) : list, !dup));
}
}
private static List<ILabel> findRecipe(ILabel l) {
return Controller.recipeIterator()
.stream()
.map(i -> i.matches(l))
.filter(Optional::isPresent)
.map(Optional::get)
.map(ILabel::copy)
.collect(Collectors.toList());
return Controller.recipeIterator().stream()
.map(i -> i.matches(l))
.filter(Optional::isPresent)
.map(Optional::get)
.map(ILabel::copy)
.collect(Collectors.toList());
}
class Suggest extends WOverlay {
@@ -223,8 +221,9 @@ public class GuiCraft extends Gui {
add(new WIcon(5 - width, 7, 18, 20, Resource.ICN_HELP, "craft.suggest"));
add(new WLine(26, 7, 20, false));
for (int i = 0; i < labels.size(); i++) {
add(new WLabel(3 - i * 20, 7, 20, 20, false).setLabel(labels.get(i))
.setLsnrUpdate((j, v) -> refresh(v)));
add(new WLabel(3 - i * 20, 7, 20, 20, false)
.setLabel(labels.get(i))
.setLsnrUpdate((j, v) -> refresh(v)));
}
}
@@ -1,5 +1,13 @@
package me.towdium.jecalculation.gui.guis;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.structure.Recipes;
import me.towdium.jecalculation.gui.JecaGui;
@@ -9,15 +17,6 @@ import me.towdium.jecalculation.utils.Utilities.I18n;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Quad;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
/**
* Author: Towdium
* Date: 18-12-6
@@ -25,14 +24,16 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class GuiImport extends Gui implements ISearchable {
List<Quad<Boolean, String, String, Recipes>> data; // selected, file, group, recipes
List<Quad<Boolean, String, String, Recipes>> data; // selected, file, group, recipes
List<Quad<Boolean, String, String, Recipes>> filtered;
WSearch search = new WSearch(26, 25, 90, this);
WSwitcher page;
WButton confirm = new WButtonIcon(149, 25, 20, 20, BTN_YES, "import.confirm").setDisabled(true).setListener(i -> {
data.stream().filter(j -> j.one).forEach(j -> Controller.inport(j.four, j.three));
JecaGui.displayParent();
});
WButton confirm = new WButtonIcon(149, 25, 20, 20, BTN_YES, "import.confirm")
.setDisabled(true)
.setListener(i -> {
data.stream().filter(j -> j.one).forEach(j -> Controller.inport(j.four, j.three));
JecaGui.displayParent();
});
List<Pair<WTick, WText>> content = new ArrayList<>();
public GuiImport() {
@@ -40,10 +41,12 @@ public class GuiImport extends Gui implements ISearchable {
add(new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search"));
add(search, confirm);
IntStream.range(0, 7).forEach(i -> {
WTick tick = new WTick(7, 49 + 16 * i, 13, 13, "import.tick").setDisabled(true).setListener(j -> {
filtered.get(page.getIndex() * 7 + i).one = j.selected();
confirm.setDisabled(data.stream().noneMatch(k -> k.one));
});
WTick tick = new WTick(7, 49 + 16 * i, 13, 13, "import.tick")
.setDisabled(true)
.setListener(j -> {
filtered.get(page.getIndex() * 7 + i).one = j.selected();
confirm.setDisabled(data.stream().noneMatch(k -> k.one));
});
WText text = new WTextExpand(49 + 16 * i, "");
add(tick, text);
content.add(new Pair<>(tick, text));
@@ -52,10 +55,9 @@ public class GuiImport extends Gui implements ISearchable {
@Override
public void onVisible(JecaGui gui) {
data = Controller.discover()
.stream()
.flatMap(i -> i.two.stream().map(j -> new Quad<>(false, i.one, j.one, i.two)))
.collect(Collectors.toList());
data = Controller.discover().stream()
.flatMap(i -> i.two.stream().map(j -> new Quad<>(false, i.one, j.one, i.two)))
.collect(Collectors.toList());
search.refresh();
}
@@ -76,12 +78,11 @@ public class GuiImport extends Gui implements ISearchable {
@Override
public boolean setFilter(String s) {
if (s.isEmpty())
filtered = new ArrayList<>(data);
if (s.isEmpty()) filtered = new ArrayList<>(data);
else
filtered = data.stream()
.filter(i -> I18n.contains(i.two, s) || I18n.contains(i.three, s))
.collect(Collectors.toList());
.filter(i -> I18n.contains(i.two, s) || I18n.contains(i.three, s))
.collect(Collectors.toList());
remove(page);
page = new WSwitcher(7, 7, 162, (filtered.size() + 6) / 7).setListener(i -> refresh());
add(page);
@@ -96,7 +97,7 @@ public class GuiImport extends Gui implements ISearchable {
super(25, yPos + 2, 140, JecaGui.Font.SHADOW, key, false);
}
//WRectangle rect = new WRectangle(22, 49 + 16 * i, 146, 13, JecaGui.COLOR_GUI_GREY);
// WRectangle rect = new WRectangle(22, 49 + 16 * i, 146, 13, JecaGui.COLOR_GUI_GREY);
@Override
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawRectangle(22, yPos - 2, 146, 13, JecaGui.COLOR_GUI_GREY);
@@ -105,8 +106,7 @@ public class GuiImport extends Gui implements ISearchable {
if (JecaGui.mouseIn(22, yPos - 2, gui.getStringWidth(key) + 6, 13, xMouse, yMouse)) {
gui.drawRectangle(22, yPos - 2, gui.getStringWidth(key) + 6, 13, JecaGui.COLOR_GUI_GREY);
gui.drawText(25, yPos, JecaGui.Font.SHADOW, key);
} else
expand = false;
} else expand = false;
} else if (JecaGui.mouseIn(22, yPos - 2, 146, 13, xMouse, yMouse) && gui.getStringWidth(key) > 140) {
gui.drawRectangle(22, yPos - 2, gui.getStringWidth(key) + 6, 13, JecaGui.COLOR_GUI_GREY);
gui.drawText(25, yPos, JecaGui.Font.SHADOW, key);
@@ -5,6 +5,8 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.function.Consumer;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.guis.pickers.IPicker;
import me.towdium.jecalculation.gui.widgets.WContainer;
@@ -14,9 +16,6 @@ import me.towdium.jecalculation.gui.widgets.WPanel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
* Date: 17-9-14.
@@ -1,5 +1,12 @@
package me.towdium.jecalculation.gui.guis;
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
import static me.towdium.jecalculation.data.structure.RecordMath.context;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.structure.RecordMath;
import me.towdium.jecalculation.data.structure.RecordMath.Operator;
@@ -10,14 +17,6 @@ import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
import static me.towdium.jecalculation.data.structure.RecordMath.context;
/**
* Author: Towdium
* Date: 19-1-3
@@ -36,28 +35,64 @@ public class GuiMath extends Gui {
public GuiMath() {
add(new WHelp("math"));
add(new WPanel(), lcd);
add(new WButtonText(7, 67, 28, 20, "7", null, true).setListener(i -> append(7)).setKeyBind(Keyboard.KEY_7, Keyboard.KEY_NUMPAD7));
add(new WButtonText(39, 67, 28, 20, "8", null, true).setListener(i -> append(8)).setKeyBind(Keyboard.KEY_8, Keyboard.KEY_NUMPAD8));
add(new WButtonText(71, 67, 28, 20, "9", null, true).setListener(i -> append(9)).setKeyBind(Keyboard.KEY_9, Keyboard.KEY_NUMPAD9));
add(new WButtonText(7, 91, 28, 20, "4", null, true).setListener(i -> append(4)).setKeyBind(Keyboard.KEY_4, Keyboard.KEY_NUMPAD4));
add(new WButtonText(39, 91, 28, 20, "5", null, true).setListener(i -> append(5)).setKeyBind(Keyboard.KEY_5, Keyboard.KEY_NUMPAD5));
add(new WButtonText(71, 91, 28, 20, "6", null, true).setListener(i -> append(6)).setKeyBind(Keyboard.KEY_6, Keyboard.KEY_NUMPAD6));
add(new WButtonText(7, 115, 28, 20, "1", null, true).setListener(i -> append(1)).setKeyBind(Keyboard.KEY_1, Keyboard.KEY_NUMPAD1));
add(new WButtonText(39, 115, 28, 20, "2", null, true).setListener(i -> append(2)).setKeyBind(Keyboard.KEY_2, Keyboard.KEY_NUMPAD2));
add(new WButtonText(71, 115, 28, 20, "3", null, true).setListener(i -> append(3)).setKeyBind(Keyboard.KEY_3, Keyboard.KEY_NUMPAD3));
add(new WButtonText(7, 139, 28, 20, "0", null, true).setListener(i -> append(0)).setKeyBind(Keyboard.KEY_0, Keyboard.KEY_NUMPAD0));
add(new WButtonText(7, 67, 28, 20, "7", null, true)
.setListener(i -> append(7))
.setKeyBind(Keyboard.KEY_7, Keyboard.KEY_NUMPAD7));
add(new WButtonText(39, 67, 28, 20, "8", null, true)
.setListener(i -> append(8))
.setKeyBind(Keyboard.KEY_8, Keyboard.KEY_NUMPAD8));
add(new WButtonText(71, 67, 28, 20, "9", null, true)
.setListener(i -> append(9))
.setKeyBind(Keyboard.KEY_9, Keyboard.KEY_NUMPAD9));
add(new WButtonText(7, 91, 28, 20, "4", null, true)
.setListener(i -> append(4))
.setKeyBind(Keyboard.KEY_4, Keyboard.KEY_NUMPAD4));
add(new WButtonText(39, 91, 28, 20, "5", null, true)
.setListener(i -> append(5))
.setKeyBind(Keyboard.KEY_5, Keyboard.KEY_NUMPAD5));
add(new WButtonText(71, 91, 28, 20, "6", null, true)
.setListener(i -> append(6))
.setKeyBind(Keyboard.KEY_6, Keyboard.KEY_NUMPAD6));
add(new WButtonText(7, 115, 28, 20, "1", null, true)
.setListener(i -> append(1))
.setKeyBind(Keyboard.KEY_1, Keyboard.KEY_NUMPAD1));
add(new WButtonText(39, 115, 28, 20, "2", null, true)
.setListener(i -> append(2))
.setKeyBind(Keyboard.KEY_2, Keyboard.KEY_NUMPAD2));
add(new WButtonText(71, 115, 28, 20, "3", null, true)
.setListener(i -> append(3))
.setKeyBind(Keyboard.KEY_3, Keyboard.KEY_NUMPAD3));
add(new WButtonText(7, 139, 28, 20, "0", null, true)
.setListener(i -> append(0))
.setKeyBind(Keyboard.KEY_0, Keyboard.KEY_NUMPAD0));
add(new WButtonText(39, 139, 28, 20, "00", null, true).setListener(i -> {
append(0);
append(0);
}));
add(new WButtonText(71, 139, 28, 20, ".", null, true).setListener(i -> dot()).setKeyBind(Keyboard.KEY_PERIOD, Keyboard.KEY_DECIMAL));
add(new WButtonIcon(109, 67, 28, 20, Resource.WGT_ARR_L).setListener(i -> remove()).setKeyBind(Keyboard.KEY_BACK));
add(new WButtonText(141, 67, 28, 20, "+", null, true).setListener(i -> operate(Operator.PLUS)).setKeyBind(Keyboard.KEY_EQUALS, Keyboard.KEY_ADD));
add(new WButtonText(109, 91, 28, 20, "C", null, true).setListener(i -> reset()).setKeyBind(Keyboard.KEY_DELETE));
add(new WButtonText(141, 91, 28, 20, "-", null, true).setListener(i -> operate(Operator.MINUS)).setKeyBind(Keyboard.KEY_SUBTRACT, Keyboard.KEY_MINUS));
add(new WButtonText(109, 115, 28, 44, "=", null, true).setListener(i -> operate(Operator.EQUALS)).setKeyBind(Keyboard.KEY_RETURN, Keyboard.KEY_NUMPADENTER, Keyboard.KEY_NUMPADEQUALS));
add(new WButtonText(141, 115, 28, 20, "x", null, true).setListener(i -> operate(Operator.TIMES)).setKeyBind(Keyboard.KEY_APOSTROPHE, Keyboard.KEY_MULTIPLY));
add(new WButtonText(141, 139, 28, 20, "/", null, true).setListener(i -> operate(Operator.DIVIDE)).setKeyBind(Keyboard.KEY_SLASH, Keyboard.KEY_DIVIDE));
add(new WButtonText(71, 139, 28, 20, ".", null, true)
.setListener(i -> dot())
.setKeyBind(Keyboard.KEY_PERIOD, Keyboard.KEY_DECIMAL));
add(new WButtonIcon(109, 67, 28, 20, Resource.WGT_ARR_L)
.setListener(i -> remove())
.setKeyBind(Keyboard.KEY_BACK));
add(new WButtonText(141, 67, 28, 20, "+", null, true)
.setListener(i -> operate(Operator.PLUS))
.setKeyBind(Keyboard.KEY_EQUALS, Keyboard.KEY_ADD));
add(new WButtonText(109, 91, 28, 20, "C", null, true)
.setListener(i -> reset())
.setKeyBind(Keyboard.KEY_DELETE));
add(new WButtonText(141, 91, 28, 20, "-", null, true)
.setListener(i -> operate(Operator.MINUS))
.setKeyBind(Keyboard.KEY_SUBTRACT, Keyboard.KEY_MINUS));
add(new WButtonText(109, 115, 28, 44, "=", null, true)
.setListener(i -> operate(Operator.EQUALS))
.setKeyBind(Keyboard.KEY_RETURN, Keyboard.KEY_NUMPADENTER, Keyboard.KEY_NUMPADEQUALS));
add(new WButtonText(141, 115, 28, 20, "x", null, true)
.setListener(i -> operate(Operator.TIMES))
.setKeyBind(Keyboard.KEY_APOSTROPHE, Keyboard.KEY_MULTIPLY));
add(new WButtonText(141, 139, 28, 20, "/", null, true)
.setListener(i -> operate(Operator.DIVIDE))
.setKeyBind(Keyboard.KEY_SLASH, Keyboard.KEY_DIVIDE));
add(new WLine(61), new WLine(103, 61, 98, false), new WLine.Joint(103, 61, false, true, true, true));
RecordMath recordMath = Controller.getRMath();
state = recordMath.state;
@@ -71,9 +106,10 @@ public class GuiMath extends Gui {
private void print() {
if (state == State.INPUT) {
String s = numbers.isEmpty() ? "0" : numbers.stream().map(Object::toString).collect(Collectors.joining());
if (!sign)
s = '-' + Utilities.repeat(" ", 6 - s.length()) + s;
String s = numbers.isEmpty()
? "0"
: numbers.stream().map(Object::toString).collect(Collectors.joining());
if (!sign) s = '-' + Utilities.repeat(" ", 6 - s.length()) + s;
lcd.text = s;
lcd.dot = dot;
} else if (state == State.ERROR) {
@@ -86,12 +122,10 @@ public class GuiMath extends Gui {
}
private void append(int i) {
if (state != State.INPUT)
state = State.INPUT;
if (state != State.INPUT) state = State.INPUT;
if ((i != 0 || !numbers.isEmpty()) && numbers.size() < (sign ? 7 : 6)) {
numbers.add(new BigDecimal(i));
if (dot != DOT_NONE)
dot++;
if (dot != DOT_NONE) dot++;
}
print();
sync();
@@ -102,8 +136,7 @@ public class GuiMath extends Gui {
}
private void operate(Operator operator) {
if (state == State.INPUT && numbers.isEmpty() && operator == Operator.MINUS)
sign = !sign;
if (state == State.INPUT && numbers.isEmpty() && operator == Operator.MINUS) sign = !sign;
else {
if (state == State.INPUT) {
try {
@@ -128,23 +161,18 @@ public class GuiMath extends Gui {
}
private void dot() {
if (state != State.INPUT)
state = State.INPUT;
if (numbers.size() == 0)
numbers.add(BigDecimal.ZERO);
if (state != State.INPUT) state = State.INPUT;
if (numbers.size() == 0) numbers.add(BigDecimal.ZERO);
dot = 0;
print();
sync();
}
private void remove() {
if (state != State.INPUT)
reset();
if (state != State.INPUT) reset();
if (numbers.size() > 0) {
numbers.removeLast();
if (dot != DOT_NONE)
dot--;
if (dot != DOT_NONE) dot--;
}
print();
sync();
@@ -163,11 +191,9 @@ public class GuiMath extends Gui {
private BigDecimal convert() {
BigDecimal f = new BigDecimal(0);
for (BigDecimal i : numbers)
f = f.add(i).multiply(BigDecimal.TEN);
for (BigDecimal i : numbers) f = f.add(i).multiply(BigDecimal.TEN);
f = f.divide(BigDecimal.TEN.pow(Math.max(dot, 0) + 1), context);
if (!sign)
f = f.negate();
if (!sign) f = f.negate();
return f;
}
}
@@ -1,7 +1,15 @@
package me.towdium.jecalculation.gui.guis;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.Resource.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.CostList;
@@ -15,15 +23,6 @@ import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Trio;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
* Date: 17-9-8.
@@ -44,29 +43,30 @@ public class GuiRecipe extends Gui {
Controller.addRecipe(group.getText(), toRecipe());
JecaGui.displayParent();
});
WButton label = new WButtonIcon(45, 25, 20, 20, BTN_LABEL, "recipe.label").setListener(
i -> JecaGui.displayGui(new GuiLabel((l) -> {
WButton label = new WButtonIcon(45, 25, 20, 20, BTN_LABEL, "recipe.label")
.setListener(i -> JecaGui.displayGui(new GuiLabel((l) -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
})));
WButton save = new WButtonIcon(26, 25, 20, 20, BTN_SAVE, "recipe.save").setDisabled(true).setListener(i -> {
if (dest == null)
Controller.addRecipe(group.getText(), toRecipe());
else {
String group = this.group.getText();
if (group.equals(dest.one))
Controller.setRecipe(dest.one, dest.two, toRecipe());
else
Controller.setRecipe(group, dest.one, dest.two, toRecipe());
}
JecaGui.displayParent();
});
WButton yes = new WButtonIcon(7, 25, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
group.setText(text.getText());
text.setText("");
setNewGroup(false);
refresh();
});
WButton save = new WButtonIcon(26, 25, 20, 20, BTN_SAVE, "recipe.save")
.setDisabled(true)
.setListener(i -> {
if (dest == null) Controller.addRecipe(group.getText(), toRecipe());
else {
String group = this.group.getText();
if (group.equals(dest.one)) Controller.setRecipe(dest.one, dest.two, toRecipe());
else Controller.setRecipe(group, dest.one, dest.two, toRecipe());
}
JecaGui.displayParent();
});
WButton yes = new WButtonIcon(7, 25, 20, 20, BTN_YES, "recipe.confirm")
.setDisabled(true)
.setListener(i -> {
group.setText(text.getText());
text.setText("");
setNewGroup(false);
refresh();
});
WButton no = new WButtonIcon(26, 25, 20, 20, BTN_NO, "common.cancel").setListener(i -> setNewGroup(false));
WButton neu = new WButtonIcon(7, 25, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
EnumMap<IO, Map<Integer, List<ILabel>>> disamb = new EnumMap<>(IO.class);
@@ -84,22 +84,21 @@ public class GuiRecipe extends Gui {
public GuiRecipe() {
for (IO j : IO.values()) {
getWidget(j).setFmtAmount(i -> i.getAmountString(false))
.setFmtTooltip((i, k) -> i.getToolTip(k, true))
.setLsnrLeftClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY)
setOverlay(new WAmount(j, v));
})
.setLsnrRightClick((widget, value) -> {
ILabel l = widget.get(value).getLabel();
if (l != ILabel.EMPTY)
widget.get(value).setLabel(ILabel.EMPTY, true);
})
.setLsnrUpdate((i, v) -> {
refresh();
removeDisamb(j, v);
});
getWidget(j)
.setFmtAmount(i -> i.getAmountString(false))
.setFmtTooltip((i, k) -> i.getToolTip(k, true))
.setLsnrLeftClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) setOverlay(new WAmount(j, v));
})
.setLsnrRightClick((widget, value) -> {
ILabel l = widget.get(value).getLabel();
if (l != ILabel.EMPTY) widget.get(value).setLabel(ILabel.EMPTY, true);
})
.setLsnrUpdate((i, v) -> {
refresh();
removeDisamb(j, v);
});
}
add(new WHelp("recipe"), new WPanel());
add(new WIcon(7, 61, 18, 36, ICN_OUTPUT, "common.output"));
@@ -107,14 +106,11 @@ public class GuiRecipe extends Gui {
add(new WIcon(7, 123, 18, 36, ICN_INPUT, "common.input"));
add(new WLine(52));
add(catalyst, input, output, group);
if (group.getTexts().isEmpty())
group.setText(Utilities.I18n.get("gui.common.default"));
if (group.getTexts().isEmpty()) group.setText(Utilities.I18n.get("gui.common.default"));
String last = Controller.getLast();
int index = -1;
if (last != null)
index = group.getTexts().indexOf(last);
if (index != -1)
group.setIndex(index);
if (last != null) index = group.getTexts().indexOf(last);
if (index != -1) group.setIndex(index);
setNewGroup(false);
copy.setDisabled(true);
text.setListener(i -> yes.setDisabled(i.getText().isEmpty()));
@@ -156,8 +152,7 @@ public class GuiRecipe extends Gui {
}
public void reset() {
for (IO i : IO.values())
getWidget(i).setLabels(new ArrayList<>());
for (IO i : IO.values()) getWidget(i).setLabels(new ArrayList<>());
disamb.clear();
refresh();
}
@@ -166,18 +161,15 @@ public class GuiRecipe extends Gui {
disamb.clear();
// generate disamb and fill slots
for (IO i : IO.values())
getWidget(i).setLabels(extract(recipe, i, context));
for (IO i : IO.values()) getWidget(i).setLabels(extract(recipe, i, context));
refresh();
}
private ArrayList<ILabel> extract(EnumMap<IO, List<Trio<ILabel, CostList, CostList>>> src,
IO type,
Class<?> context) {
private ArrayList<ILabel> extract(
EnumMap<IO, List<Trio<ILabel, CostList, CostList>>> src, IO type, Class<?> context) {
List<Trio<ILabel, CostList, CostList>> l = src.get(type);
ArrayList<ILabel> ret = new ArrayList<>();
if (l == null)
return ret;
if (l == null) return ret;
for (int i = 0; i < l.size(); i++) {
Trio<ILabel, CostList, CostList> p = l.get(i);
ret.add(p.one);
@@ -194,8 +186,7 @@ public class GuiRecipe extends Gui {
private List<ILabel> trim(List<ILabel> ls) {
for (int i = ls.size() - 1; i >= 0; i--) {
if (ls.get(i) == ILabel.EMPTY)
ls.remove(i);
if (ls.get(i) == ILabel.EMPTY) ls.remove(i);
}
return ls;
}
@@ -209,8 +200,7 @@ public class GuiRecipe extends Gui {
Recipe r = toRecipe();
boolean d = dest == null ? Controller.hasDuplicate(r) : Controller.hasDuplicate(r, dest.one, dest.two);
save.setDisabled(d);
if (dest != null)
copy.setDisabled(d);
if (dest != null) copy.setDisabled(d);
} catch (IllegalArgumentException e) {
save.setDisabled(true);
copy.setDisabled(true);
@@ -219,14 +209,12 @@ public class GuiRecipe extends Gui {
private void removeDisamb(IO type, int index) {
Map<Integer, List<ILabel>> entry = disamb.get(type);
if (entry != null)
entry.remove(index);
if (entry != null) entry.remove(index);
}
static boolean handleLabelScroll(WLabel w, int diff) {
ILabel l = w.getLabel();
for (int i = 0; i < Math.abs(diff); i++)
l = diff > 0 ? l.increaseAmount() : l.decreaseAmount();
for (int i = 0; i < Math.abs(diff); i++) l = diff > 0 ? l.increaseAmount() : l.decreaseAmount();
w.setLabel(l, true);
return true;
}
@@ -263,16 +251,15 @@ public class GuiRecipe extends Gui {
JecaGui.getCurrent().hand = temp.getLabel();
set(ILabel.EMPTY, type, idx);
});
yes = new WButtonIcon(x + 59, y - 24, 20, 20, BTN_YES, "recipe.confirm").setListener(
i -> set(temp.getLabel(), type, idx));
no = new WButtonIcon(x + 78, y - 24, 20, 20, BTN_NO, "recipe.delete").setListener(
i -> set(ILabel.EMPTY, type, idx));
yes = new WButtonIcon(x + 59, y - 24, 20, 20, BTN_YES, "recipe.confirm")
.setListener(i -> set(temp.getLabel(), type, idx));
no = new WButtonIcon(x + 78, y - 24, 20, 20, BTN_NO, "recipe.delete")
.setListener(i -> set(ILabel.EMPTY, type, idx));
disamb = new WButtonIcon(x + 40, y - 24, 20, 20, BTN_DISAMB, "recipe.disamb");
Map<Integer, List<ILabel>> entry = GuiRecipe.this.disamb.get(type);
if (entry != null && entry.containsKey(idx)) {
disamb.setListener(i -> GuiRecipe.this.setOverlay(new WDisamb(type, idx)));
} else
disamb.setDisabled(true);
} else disamb.setDisabled(true);
add(temp, text, pick, yes, no, disamb);
text.setListener(i -> {
boolean acceptable;
@@ -280,8 +267,7 @@ public class GuiRecipe extends Gui {
try {
amount = Long.parseLong(text.getText());
acceptable = amount > 0;
if (!acceptable)
amount = 1;
if (!acceptable) amount = 1;
} catch (NumberFormatException e) {
acceptable = text.getText().isEmpty();
amount = 1;
@@ -291,7 +277,6 @@ public class GuiRecipe extends Gui {
temp.setLabel(temp.getLabel().setAmount(amount));
});
update();
}
private void set(ILabel l, IO type, int idx) {
@@ -326,13 +311,13 @@ public class GuiRecipe extends Gui {
add(new WPanel(x - 7, y - 46, 111, 71));
temp = new WLabel(x - 1, y - 1, 20, 20, false);
temp.setLabel(ref.getLabel().copy());
content = new WLabelScroll(x + 8, y - 40, 4, 2, false).setLabels(disamb.get(type).get(idx))
.setLsnrLeftClick((i, v) -> {
list.setLabel(
idx, i.get(v).getLabel().copy().multiply(-1));
GuiRecipe.this.setOverlay(null);
refresh();
});
content = new WLabelScroll(x + 8, y - 40, 4, 2, false)
.setLabels(disamb.get(type).get(idx))
.setLsnrLeftClick((i, v) -> {
list.setLabel(idx, i.get(v).getLabel().copy().multiply(-1));
GuiRecipe.this.setOverlay(null);
refresh();
});
add(new WIcon(x + 22, y - 1, 20, 20, ICN_TEXT, "common.search"));
search = new WSearch(x + 42, y - 1, 56, content);
add(temp, content, search);
@@ -1,5 +1,12 @@
package me.towdium.jecalculation.gui.guis;
import static me.towdium.jecalculation.gui.Resource.*;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.Recipe;
@@ -11,55 +18,43 @@ import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Trio;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.*;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class GuiSearch extends Gui {
IdentityHashMap<ILabel, Trio<Recipe, String, Integer>> recipes;
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, false)
.setLsnrLeftClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) setOverlay(new Overlay(i.get(v)));
});
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, false).setLsnrLeftClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) setOverlay(new Overlay(i.get(v)));
});
WSwitcher group;
WTextField text = new WTextField(7, 25, 119);
WButton no = new WButtonIcon(130, 25, 20, 20, BTN_NO, "common.cancel")
.setListener(i -> setRename(false));
WButton no = new WButtonIcon(130, 25, 20, 20, BTN_NO, "common.cancel").setListener(i -> setRename(false));
WButton yes = new WButtonIcon(149, 25, 20, 20, BTN_YES, "search.confirm")
.setDisabled(true).setListener(i -> {
.setDisabled(true)
.setListener(i -> {
Controller.renameGroup(group.getText(), text.getText());
refreshGroups();
group.setText(text.getText());
refreshDisplay();
setRename(false);
});
WButton exportN = new WButtonIcon(111, 25, 20, 20, BTN_EXPORT_N, "search.export_all")
.setListener(i -> Controller.export());
WButton exportN =
new WButtonIcon(111, 25, 20, 20, BTN_EXPORT_N, "search.export_all").setListener(i -> Controller.export());
WButton export1 = new WButtonIcon(111, 25, 20, 20, BTN_EXPORT_1, "search.export_group")
.setListener(i -> Controller.export(group.getText()));
WButton deleteN = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_N, "search.delete_all")
.setListener(i -> {
Controller.getGroups().forEach(Controller::removeGroup);
refreshGroups();
refreshDisplay();
});
WButton delete1 = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_1, "search.delete_group")
.setListener(i -> {
Controller.removeGroup(group.getText());
refreshGroups();
refreshDisplay();
});
WButton deleteN = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_N, "search.delete_all").setListener(i -> {
Controller.getGroups().forEach(Controller::removeGroup);
refreshGroups();
refreshDisplay();
});
WButton delete1 = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_1, "search.delete_group").setListener(i -> {
Controller.removeGroup(group.getText());
refreshGroups();
refreshDisplay();
});
WButton inport = new WButtonIcon(92, 25, 20, 20, BTN_IMPORT, "search.import")
.setListener(i -> JecaGui.displayGui(new GuiImport()));
WButton rename = new WButtonIcon(149, 25, 20, 20, BTN_EDIT, "search.rename")
.setListener(i -> setRename(true));
WButton rename = new WButtonIcon(149, 25, 20, 20, BTN_EDIT, "search.rename").setListener(i -> setRename(true));
WIcon icon = new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search");
WSearch search = new WSearch(26, 25, 61, labels);
List<ILabel> identifiers;
@@ -73,7 +68,6 @@ public class GuiSearch extends Gui {
add(labels, icon, search, inport, exportN, deleteN, rename);
}
private void generate() {
identifiers = new ArrayList<>();
recipes = new IdentityHashMap<>();
@@ -83,7 +77,8 @@ public class GuiSearch extends Gui {
identifiers.add(id);
};
Recipes.RecipeIterator it = group.getIndex() == 0 ? Controller.recipeIterator() : Controller.recipeIterator(group.getText());
Recipes.RecipeIterator it =
group.getIndex() == 0 ? Controller.recipeIterator() : Controller.recipeIterator(group.getText());
it.stream().map(j -> new Trio<>(j, it.getGroup(), it.getIndex())).forEach(add);
}
@@ -113,8 +108,7 @@ public class GuiSearch extends Gui {
groups.add(Utilities.I18n.get("gui.search.all"));
groups.addAll(Controller.getGroups());
int index = group == null ? 0 : group.getIndex();
if (index >= groups.size())
index = groups.size() - 1;
if (index >= groups.size()) index = groups.size() - 1;
group = new WSwitcher(7, 7, 162, groups).setListener(i -> refreshDisplay());
group.setIndex(index);
add(group);
@@ -12,8 +12,7 @@ import me.towdium.jecalculation.gui.widgets.IWidget;
*/
@SideOnly(Side.CLIENT)
public interface IGui extends IContainer {
default void onVisible(JecaGui gui) {
}
default void onVisible(JecaGui gui) {}
default boolean acceptsTransfer() {
return false;
@@ -2,14 +2,13 @@ package me.towdium.jecalculation.gui.guis.pickers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.function.Consumer;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.guis.Gui;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
* Date: 17-9-28.
@@ -30,8 +29,7 @@ public interface IPicker extends IGui {
}
protected void notifyLsnr(ILabel l) {
if (callback != null && l != ILabel.EMPTY)
callback.accept(l);
if (callback != null && l != ILabel.EMPTY) callback.accept(l);
}
}
}
@@ -1,7 +1,10 @@
package me.towdium.jecalculation.gui.guis.pickers;
import static me.towdium.jecalculation.gui.Resource.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.labels.LItemStack;
import me.towdium.jecalculation.gui.guis.IGui;
@@ -9,10 +12,6 @@ import me.towdium.jecalculation.gui.widgets.WButton;
import me.towdium.jecalculation.gui.widgets.WButtonIcon;
import me.towdium.jecalculation.gui.widgets.WLabel;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: Towdium
* Date: 18-9-18
@@ -21,14 +20,14 @@ import static me.towdium.jecalculation.gui.Resource.*;
@SideOnly(Side.CLIENT)
public class PickerItemStack extends IPicker.Impl implements IGui {
WLabel label = new WLabel(7, 7, 20, 20, true).setLsnrUpdate((i, v) -> update(v));
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES, "item_stack.confirm").setListener(
i -> callback.accept(label.getLabel()));
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES, "item_stack.confirm")
.setListener(i -> callback.accept(label.getLabel()));
WButton bNbtN = new WButtonIcon(49, 7, 20, 20, BTN_NBT_N, "item_stack.nbt_normal").setListener(i -> setFNbt(true));
WButton bNbtF = new WButtonIcon(49, 7, 20, 20, BTN_NBT_F, "item_stack.nbt_fuzzy").setListener(i -> setFNbt(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, BTN_META_N, "item_stack.meta_normal").setListener(
i -> setFMeta(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, BTN_META_F, "item_stack.meta_fuzzy").setListener(
i -> setFMeta(false));
WButton bMetaN =
new WButtonIcon(30, 7, 20, 20, BTN_META_N, "item_stack.meta_normal").setListener(i -> setFMeta(true));
WButton bMetaF =
new WButtonIcon(30, 7, 20, 20, BTN_META_F, "item_stack.meta_fuzzy").setListener(i -> setFMeta(false));
ILabel raw = ILabel.EMPTY;
boolean fMeta, fNbt, fCap = false;
@@ -62,10 +61,8 @@ public class PickerItemStack extends IPicker.Impl implements IGui {
private void setF(boolean b, WButton be, WButton bd, Runnable r) {
remove(be, bd);
if (b)
add(bd);
else
add(be);
if (b) add(bd);
else add(be);
r.run();
if (raw instanceof LItemStack) {
LItemStack lis = (LItemStack) raw;
@@ -1,19 +1,18 @@
package me.towdium.jecalculation.gui.guis.pickers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-29.
@@ -24,16 +23,16 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
public class PickerPlaceholder extends IPicker.Impl implements IGui {
public PickerPlaceholder() {
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, false)
.setLabels(LPlaceholder.getRecent()).setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
WTextField create = new WTextField(26, 7, 69).setListener(
i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE));
.setLabels(LPlaceholder.getRecent())
.setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
WTextField create = new WTextField(26, 7, 69)
.setListener(i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE));
add(new WIcon(7, 45, 20, 20, ICN_TEXT, "common.search"));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "placeholder.create"));
add(new WSearch(26, 45, 90, scroll));
add(new WLine(36));
add(new WButtonIcon(95, 7, 20, 20, BTN_YES, "common.confirm").setListener(i -> {
if (!create.getText().equals(""))
callback.accept(new LPlaceholder(create.getText(), 1));
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
}));
add(scroll, create);
}
@@ -1,7 +1,13 @@
package me.towdium.jecalculation.gui.guis.pickers;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.labels.LFluidStack;
import me.towdium.jecalculation.data.label.labels.LOreDict;
@@ -13,13 +19,6 @@ import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
/**
* Author: towdium
* Date: 17-9-28.
@@ -32,23 +31,21 @@ public class PickerSimple extends IPicker.Impl implements IGui {
* @param labels label to be displayed for selection
*/
public PickerSimple(List<ILabel> labels) {
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, false).setLabels(labels)
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, false)
.setLabels(labels)
.setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "common.search"));
add(new WSearch(26, 7, 90, ls));
add(ls);
}
public static class FluidStack extends PickerSimple {
public FluidStack() {
super(FluidRegistry.getRegisteredFluids()
.values()
.stream()
// filter the fluid with no icon
.filter(fluid -> fluid.getStillIcon() != null || fluid.getFlowingIcon() != null)
.map(fluid -> new LFluidStack(1000, fluid))
.collect(Collectors.toList()));
super(FluidRegistry.getRegisteredFluids().values().stream()
// filter the fluid with no icon
.filter(fluid -> fluid.getStillIcon() != null || fluid.getFlowingIcon() != null)
.map(fluid -> new LFluidStack(1000, fluid))
.collect(Collectors.toList()));
}
}
@@ -59,9 +56,9 @@ public class PickerSimple extends IPicker.Impl implements IGui {
static List<ILabel> generate() {
return Arrays.stream(OreDictionary.getOreNames())
.filter(i -> !OreDictionary.getOres(i).isEmpty())
.map(LOreDict::new)
.collect(Collectors.toList());
.filter(i -> !OreDictionary.getOres(i).isEmpty())
.map(LOreDict::new)
.collect(Collectors.toList());
}
}
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.gui.widgets;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
/**
* Author: towdium
* Date: 8/14/17.
@@ -25,8 +24,7 @@ public interface IWidget {
return false;
}
default void onMouseFocused(JecaGui gui, int xMouse, int yMouse, int button) {
}
default void onMouseFocused(JecaGui gui, int xMouse, int yMouse, int button) {}
default boolean onMouseReleased(JecaGui gui, int xMouse, int yMouse, int button) {
return false;
@@ -1,20 +1,19 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.Resource.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.ClientUtils;
import org.lwjgl.input.Keyboard;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
* Date: 17-8-17.
@@ -50,8 +49,7 @@ public abstract class WButton extends WTooltip {
else if (hovered) res = WGT_BUTTON_F;
else res = WGT_BUTTON_N;
gui.drawResourceContinuous(res, xPos, yPos, xSize,
ySize, 5, 5, 5, 5);
gui.drawResourceContinuous(res, xPos, yPos, xSize, ySize, 5, 5, 5, 5);
return hovered;
}
@@ -60,18 +58,14 @@ public abstract class WButton extends WTooltip {
if (mouseIn(xMouse, yMouse) && !disabled && button == 0 && listener != null) {
trigger();
return true;
} else
return false;
} else return false;
}
protected boolean hovered(int xMouse, int yMouse) {
if (mouseIn(xMouse, yMouse)) {
return true;
}
if (keys != null)
for (int i : keys)
if (Keyboard.isKeyDown(i))
return true;
if (keys != null) for (int i : keys) if (Keyboard.isKeyDown(i)) return true;
return false;
}
@@ -2,11 +2,10 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
/**
* Author: towdium
@@ -25,14 +24,15 @@ public class WButtonIcon extends WButton {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, res.disabled, null);
}
private WButtonIcon(int xPos,
int yPos,
int xSize,
int ySize,
Resource normal,
Resource focused,
@Nullable Resource disabled,
@Nullable String name) {
private WButtonIcon(
int xPos,
int yPos,
int xSize,
int ySize,
Resource normal,
Resource focused,
@Nullable Resource disabled,
@Nullable String name) {
super(xPos, yPos, xSize, ySize, name);
this.rNormal = normal;
this.rFocused = focused;
@@ -2,10 +2,9 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
/**
* Author: towdium
@@ -2,17 +2,16 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Author: towdium
* Date: 17-9-14.
@@ -43,18 +42,16 @@ public class WContainer implements IContainer {
public boolean onDraw(JecaGui gui, int mouseX, int mouseY) {
Wrapper<IWidget> w = new Wrapper<>(null);
widgets.forEach(widget -> {
if (widget.onDraw(gui, mouseX, mouseY))
w.value = widget;
if (widget.onDraw(gui, mouseX, mouseY)) w.value = widget;
});
if (w.value != null)
w.value.onDraw(gui, mouseX, mouseY);
if (w.value != null) w.value.onDraw(gui, mouseX, mouseY);
return false;
}
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onMouseClicked(gui, xMouse, yMouse, button));
return new Utilities.ReversedIterator<>(widgets)
.stream().anyMatch(i -> i.onMouseClicked(gui, xMouse, yMouse, button));
}
@Override
@@ -69,25 +66,25 @@ public class WContainer implements IContainer {
@Override
public boolean onMouseReleased(JecaGui gui, int xMouse, int yMouse, int button) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onMouseReleased(gui, xMouse, yMouse, button));
return new Utilities.ReversedIterator<>(widgets)
.stream().anyMatch(i -> i.onMouseReleased(gui, xMouse, yMouse, button));
}
@Override
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onMouseScroll(gui, xMouse, yMouse, diff));
return new Utilities.ReversedIterator<>(widgets)
.stream().anyMatch(i -> i.onMouseScroll(gui, xMouse, yMouse, diff));
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onTooltip(gui, xMouse, yMouse, tooltip));
return new Utilities.ReversedIterator<>(widgets)
.stream().anyMatch(i -> i.onTooltip(gui, xMouse, yMouse, tooltip));
}
@Override
public boolean getLabelUnderMouse(int xMouse, int yMouse, Wrapper<ILabel> label) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.getLabelUnderMouse(xMouse, yMouse, label));
return new Utilities.ReversedIterator<>(widgets)
.stream().anyMatch(i -> i.getLabelUnderMouse(xMouse, yMouse, label));
}
}
@@ -1,18 +1,17 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.JecaGui.Font.SHADOW;
import static me.towdium.jecalculation.gui.Resource.*;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import org.lwjgl.input.Keyboard;
/**
* Author: Towdium
* Date: 18-9-23
@@ -24,8 +23,7 @@ public class WHelp extends WContainer {
public WHelp(String content) {
key = content;
if (I18n.search("gui." + WHelp.this.key + ".title").two
&& I18n.search("gui." + WHelp.this.key + ".help").two) {
if (I18n.search("gui." + WHelp.this.key + ".title").two && I18n.search("gui." + WHelp.this.key + ".help").two) {
add(new Impl());
}
}
@@ -51,8 +49,7 @@ public class WHelp extends WContainer {
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
boolean ret = mouseIn(xMouse, yMouse);
if (ret)
gui.root.setOverlay(new Doc());
if (ret) gui.root.setOverlay(new Doc());
return ret;
}
}
@@ -66,11 +63,9 @@ public class WHelp extends WContainer {
add(new WPanel(), new Icon(), title, text, switcher);
}
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!super.onMouseClicked(gui, xMouse, yMouse, button))
gui.root.remove(this);
if (!super.onMouseClicked(gui, xMouse, yMouse, button)) gui.root.remove(this);
return true;
}
@@ -145,8 +140,7 @@ public class WHelp extends WContainer {
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
boolean ret = mouseIn(xMouse, yMouse);
if (ret)
gui.root.setOverlay(null);
if (ret) gui.root.setOverlay(null);
return ret;
}
@@ -157,13 +151,11 @@ public class WHelp extends WContainer {
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
if (super.onKeyPressed(gui, ch, code))
return true;
if (super.onKeyPressed(gui, ch, code)) return true;
if (code == Keyboard.KEY_ESCAPE) {
gui.root.setOverlay(null);
return true;
} else
return false;
} else return false;
}
}
}
@@ -1,16 +1,15 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
/**
* Author: towdium
* Date: 17-8-18.
@@ -30,8 +29,7 @@ public class WIcon extends WTooltip {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, name);
}
private WIcon(int xPos, int yPos, int xSize, int ySize,
Resource normal, Resource focused, @Nullable String name) {
private WIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, @Nullable String name) {
super(name);
this.xPos = xPos;
this.yPos = yPos;
@@ -52,7 +50,12 @@ public class WIcon extends WTooltip {
@Override
public boolean mouseIn(int xMouse, int yMouse) {
return JecaGui.mouseIn(xPos + (xSize - normal.getXSize()) / 2,
yPos + (ySize - normal.getYSize()) / 2, normal.getXSize(), normal.getYSize(), xMouse, yMouse);
return JecaGui.mouseIn(
xPos + (xSize - normal.getXSize()) / 2,
yPos + (ySize - normal.getYSize()) / 2,
normal.getXSize(),
normal.getYSize(),
xMouse,
yMouse);
}
}
@@ -1,23 +1,21 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.JecaGui.Font.HALF;
import static me.towdium.jecalculation.gui.Resource.WGT_SLOT;
import codechicken.lib.gui.GuiDraw;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.Timer;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import static me.towdium.jecalculation.gui.JecaGui.Font.HALF;
import static me.towdium.jecalculation.gui.Resource.WGT_SLOT;
/**
* Author: towdium
* Date: 17-8-17.
@@ -54,8 +52,7 @@ public class WLabel implements IWidget {
public WLabel setLabel(ILabel label, boolean notify) {
this.label = label;
if (notify)
notifyUpdate();
if (notify) notifyUpdate();
return this;
}
@@ -64,22 +61,23 @@ public class WLabel implements IWidget {
gui.drawResourceContinuous(WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
label.drawLabel(gui, xPos + xSize / 2, yPos + ySize / 2, true);
String s = fmtAmount.apply(label);
gui.drawText(xPos + xSize / 2.0f + 8 - HALF.getTextWidth(s), yPos + ySize / 2.0f + 8.5f - HALF.getTextHeight(),
HALF, s);
gui.drawText(
xPos + xSize / 2.0f + 8 - HALF.getTextWidth(s),
yPos + ySize / 2.0f + 8.5f - HALF.getTextHeight(),
HALF,
s);
if (accept) {
timer.setState(gui.hand != ILabel.EMPTY);
int color = 0xFFFFFF + (int) ((-Math.cos(timer.getTime() * Math.PI / 1500) + 1) * 0x40) * 0x1000000;
GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, color);
}
if (mouseIn(xMouse, yMouse))
GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
if (mouseIn(xMouse, yMouse)) GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
return false;
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (!mouseIn(xMouse, yMouse))
return false;
if (!mouseIn(xMouse, yMouse)) return false;
if (label != ILabel.EMPTY) {
tooltip.add(label.getDisplayName());
tooltip.add(JecaGui.SEPARATOR);
@@ -93,37 +91,31 @@ public class WLabel implements IWidget {
if (mouseIn(xMouse, yMouse) && this.label != ILabel.EMPTY) {
label.value = this.label;
return true;
} else
return false;
} else return false;
}
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!mouseIn(xMouse, yMouse))
return false;
if (!mouseIn(xMouse, yMouse)) return false;
if (button == 1) {
notifyRightClick();
return true;
}
if (accept && gui.hand != ILabel.EMPTY) {
label = gui.hand;
gui.hand = label.EMPTY;
notifyUpdate();
} else
notifyLeftClick();
label = gui.hand;
gui.hand = label.EMPTY;
notifyUpdate();
} else notifyLeftClick();
return true;
}
@Override
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
if (scroll == null)
return false;
if (scroll == null) return false;
else if (mouseIn(xMouse, yMouse)) {
scroll.invoke(this, diff);
return true;
}
else
return false;
} else return false;
}
public WLabel setLsnrUpdate(ListenerValue<? super WLabel, ILabel> listener) {
@@ -163,17 +155,14 @@ public class WLabel implements IWidget {
}
private void notifyLeftClick() {
if (leftClick != null)
leftClick.invoke(this);
if (leftClick != null) leftClick.invoke(this);
}
private void notifyRightClick() {
if (rightClick != null)
rightClick.invoke(this);
if (rightClick != null) rightClick.invoke(this);
}
private void notifyUpdate() {
if (update != null)
update.invoke(this, label);
if (update != null) update.invoke(this, label);
}
}
@@ -2,16 +2,15 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
/**
* Author: towdium
@@ -33,17 +32,16 @@ public class WLabelGroup extends WContainer {
for (int j = 0; j < row; j++) {
int r = j;
IntStream.range(0, column).forEach(c -> {
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, accept).setLsnrUpdate(
(i, v) -> {
if (lsnrUpdate != null)
lsnrUpdate.invoke(this, r * column + c);
}).setLsnrLeftClick(i -> {
if (lsnrLeftClick != null)
lsnrLeftClick.invoke(this, r * column + c);
}).setLsnrRightClick(i -> {
if (lsnrRightClick != null)
lsnrRightClick.invoke(this, r * column + c);
});
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, accept)
.setLsnrUpdate((i, v) -> {
if (lsnrUpdate != null) lsnrUpdate.invoke(this, r * column + c);
})
.setLsnrLeftClick(i -> {
if (lsnrLeftClick != null) lsnrLeftClick.invoke(this, r * column + c);
})
.setLsnrRightClick(i -> {
if (lsnrRightClick != null) lsnrRightClick.invoke(this, r * column + c);
});
labels.add(l);
add(l);
});
@@ -63,8 +61,7 @@ public class WLabelGroup extends WContainer {
}
public void setLabel(List<ILabel> labels, int start) {
for (WLabel label : this.labels)
label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY);
for (WLabel label : this.labels) label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY);
}
public WLabelGroup setLsnrUpdate(ListenerValue<? super WLabelGroup, Integer> listener) {
@@ -96,4 +93,4 @@ public class WLabelGroup extends WContainer {
labels.forEach(i -> i.setFmtTooltip(f));
return this;
}
}
}
@@ -2,17 +2,16 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
/**
* Author: towdium
@@ -38,30 +37,31 @@ public class WLabelScroll extends WContainer implements ISearchable {
this.yPos = yPos;
this.column = column;
this.row = row;
labelGroup = new WLabelGroup(xPos, yPos, column, row, accept).setLsnrUpdate(this::onUpdate)
.setLsnrLeftClick(this::onLeftClick)
.setLsnrRightClick(this::onRightClick);
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setListener(i -> update(i.getCurrent()))
.setStep(Float.POSITIVE_INFINITY)
.setRatio(1);
labelGroup = new WLabelGroup(xPos, yPos, column, row, accept)
.setLsnrUpdate(this::onUpdate)
.setLsnrLeftClick(this::onLeftClick)
.setLsnrRightClick(this::onRightClick);
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18)
.setListener(i -> update(i.getCurrent()))
.setStep(Float.POSITIVE_INFINITY)
.setRatio(1);
add(labelGroup);
add(scroll);
add(new WRectangle(xPos + column * 18, yPos, 4, row * 18, JecaGui.COLOR_GUI_GREY));
}
public void update(float f) {
if (f < 0)
f = 0;
if (f > 1)
f = 1;
if (f < 0) f = 0;
if (f > 1) f = 1;
int amount = getAmountSteps();
current = (int) (amount * f);
if (current == amount)
current--;
if (current == amount) current--;
List<ILabel> ls = accept ? labels : filtered;
labelGroup.setLabel(ls, current * column);
float step = 1f / (amount - 1);
scroll.setRatio(Math.min(row / (float) getAmountRows(), 1f)).setCurrent(f).setStep(step);
scroll.setRatio(Math.min(row / (float) getAmountRows(), 1f))
.setCurrent(f)
.setStep(step);
}
public WLabel get(int index) {
@@ -70,10 +70,8 @@ public class WLabelScroll extends WContainer implements ISearchable {
public WLabelScroll setLabels(List<ILabel> labels) {
this.labels = labels;
if (accept)
update(0);
else
setFilter(filter);
if (accept) update(0);
else setFilter(filter);
return this;
}
@@ -83,11 +81,10 @@ public class WLabelScroll extends WContainer implements ISearchable {
}
public boolean setFilter(String str) {
if (accept)
throw new RuntimeException("Filtering not allowed when editing");
if (accept) throw new RuntimeException("Filtering not allowed when editing");
filtered = labels.stream()
.filter(l -> I18n.contains(l.getDisplayName().toLowerCase(), str.toLowerCase()))
.collect(Collectors.toList());
.filter(l -> I18n.contains(l.getDisplayName().toLowerCase(), str.toLowerCase()))
.collect(Collectors.toList());
update(0);
return filtered.size() != 0;
}
@@ -114,11 +111,9 @@ public class WLabelScroll extends WContainer implements ISearchable {
protected void onUpdate(WLabelGroup w, int index) {
ILabel l = w.get(index).getLabel();
int i = column * current + index;
while (labels.size() <= i)
labels.add(ILabel.EMPTY);
while (labels.size() <= i) labels.add(ILabel.EMPTY);
labels.set(i, l);
if (lsnrUpdate != null)
lsnrUpdate.invoke(this, i);
if (lsnrUpdate != null) lsnrUpdate.invoke(this, i);
if (index + 1 == row * column && l != ILabel.EMPTY && (row + current) * column == labels.size()) {
labels.add(ILabel.EMPTY);
@@ -129,13 +124,11 @@ public class WLabelScroll extends WContainer implements ISearchable {
}
protected void onLeftClick(WLabelGroup w, int index) {
if (hdlrLeftClick != null)
hdlrLeftClick.invoke(this, column * current + index);
if (hdlrLeftClick != null) hdlrLeftClick.invoke(this, column * current + index);
}
protected void onRightClick(WLabelGroup w, int index) {
if (hdlrRightClick != null)
hdlrRightClick.invoke(this, column * current + index);
if (hdlrRightClick != null) hdlrRightClick.invoke(this, column * current + index);
}
public WLabelScroll setLsnrScroll(ListenerValue<? super WLabel, Integer> hdlr) {
@@ -1,19 +1,17 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.data.structure.RecordMath.Operator;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
import javax.annotation.ParametersAreNonnullByDefault;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Objects;
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.structure.RecordMath.Operator;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
/**
* Author: Towdium
@@ -24,7 +22,6 @@ import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
public class WLcd implements IWidget {
static HashMap<Character, boolean[]> PATTERN = new HashMap<>();
public int yPos;
public String text = "";
public int dot = DOT_NONE;
@@ -32,22 +29,22 @@ public class WLcd implements IWidget {
public Operator operator = Operator.EQUALS;
static {
PATTERN.put('0', new boolean[]{true, true, true, true, true, true, false});
PATTERN.put('1', new boolean[]{false, true, true, false, false, false, false});
PATTERN.put('2', new boolean[]{true, true, false, true, true, false, true});
PATTERN.put('3', new boolean[]{true, true, true, true, false, false, true});
PATTERN.put('4', new boolean[]{false, true, true, false, false, true, true});
PATTERN.put('5', new boolean[]{true, false, true, true, false, true, true});
PATTERN.put('6', new boolean[]{true, false, true, true, true, true, true});
PATTERN.put('7', new boolean[]{true, true, true, false, false, false, false});
PATTERN.put('8', new boolean[]{true, true, true, true, true, true, true});
PATTERN.put('9', new boolean[]{true, true, true, true, false, true, true});
PATTERN.put('E', new boolean[]{true, false, false, true, true, true, true});
PATTERN.put('o', new boolean[]{false, false, true, true, true, false, true});
PATTERN.put('r', new boolean[]{false, false, false, false, true, false, true});
PATTERN.put('-', new boolean[]{false, false, false, false, false, false, true});
PATTERN.put(' ', new boolean[]{false, false, false, false, false, false, false});
//format.setMinimumIntegerDigits(0);
PATTERN.put('0', new boolean[] {true, true, true, true, true, true, false});
PATTERN.put('1', new boolean[] {false, true, true, false, false, false, false});
PATTERN.put('2', new boolean[] {true, true, false, true, true, false, true});
PATTERN.put('3', new boolean[] {true, true, true, true, false, false, true});
PATTERN.put('4', new boolean[] {false, true, true, false, false, true, true});
PATTERN.put('5', new boolean[] {true, false, true, true, false, true, true});
PATTERN.put('6', new boolean[] {true, false, true, true, true, true, true});
PATTERN.put('7', new boolean[] {true, true, true, false, false, false, false});
PATTERN.put('8', new boolean[] {true, true, true, true, true, true, true});
PATTERN.put('9', new boolean[] {true, true, true, true, false, true, true});
PATTERN.put('E', new boolean[] {true, false, false, true, true, true, true});
PATTERN.put('o', new boolean[] {false, false, true, true, true, false, true});
PATTERN.put('r', new boolean[] {false, false, false, false, true, false, true});
PATTERN.put('-', new boolean[] {false, false, false, false, false, false, true});
PATTERN.put(' ', new boolean[] {false, false, false, false, false, false, false});
// format.setMinimumIntegerDigits(0);
}
public WLcd(int yPos) {
@@ -58,8 +55,7 @@ public class WLcd implements IWidget {
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
drawBackground(gui);
drawStr(gui, text);
if (dot != DOT_NONE)
drawDot(gui, 6 - dot);
if (dot != DOT_NONE) drawDot(gui, 6 - dot);
drawOperator(gui, operator);
return false;
}
@@ -85,26 +81,18 @@ public class WLcd implements IWidget {
protected void drawChar(JecaGui gui, char ch, int index) {
boolean[] pattern = PATTERN.get(ch);
Objects.requireNonNull(pattern, "Unsupported char: " + ch + ".");
if (pattern[0])
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 14);
if (pattern[1])
gui.drawResource(Resource.WGT_LCD_UR_F, 30 + index * 21, yPos + 14);
if (pattern[2])
gui.drawResource(Resource.WGT_LCD_LR_F, 30 + index * 21, yPos + 28);
if (pattern[3])
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 40);
if (pattern[4])
gui.drawResource(Resource.WGT_LCD_LL_F, 16 + index * 21, yPos + 28);
if (pattern[5])
gui.drawResource(Resource.WGT_LCD_UL_F, 16 + index * 21, yPos + 14);
if (pattern[6])
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 27);
if (pattern[0]) gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 14);
if (pattern[1]) gui.drawResource(Resource.WGT_LCD_UR_F, 30 + index * 21, yPos + 14);
if (pattern[2]) gui.drawResource(Resource.WGT_LCD_LR_F, 30 + index * 21, yPos + 28);
if (pattern[3]) gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 40);
if (pattern[4]) gui.drawResource(Resource.WGT_LCD_LL_F, 16 + index * 21, yPos + 28);
if (pattern[5]) gui.drawResource(Resource.WGT_LCD_UL_F, 16 + index * 21, yPos + 14);
if (pattern[6]) gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 27);
}
protected void drawStr(JecaGui gui, String str) {
int offset = 7 - str.length();
for (int i = offset; i < 7; i++)
drawChar(gui, str.charAt(i - offset), i);
for (int i = offset; i < 7; i++) drawChar(gui, str.charAt(i - offset), i);
}
protected void drawDot(JecaGui gui, int index) {
@@ -2,12 +2,11 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-18.
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.gui.widgets;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: Towdium
* Date: 16/02/19
@@ -1,18 +1,17 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.Resource.WGT_PAGER_F;
import static me.towdium.jecalculation.gui.Resource.WGT_PANEL_N;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel.RegistryEditor.Record;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.WGT_PAGER_F;
import static me.towdium.jecalculation.gui.Resource.WGT_PANEL_N;
/**
* Author: towdium
* Date: 17-9-16.
@@ -2,15 +2,14 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
/**
* Author: towdium
* Date: 17-9-15.
@@ -33,7 +32,6 @@ public class WPanel implements IWidget {
this(0, 0, 176, 166);
}
@Override
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_PANEL_F, xPos, yPos, xSize, ySize, 5, 5, 5, 5);
@@ -2,11 +2,10 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-22.
@@ -1,17 +1,16 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.Resource.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import org.lwjgl.input.Mouse;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
* Date: 17-8-19.
@@ -37,10 +36,8 @@ public class WScroll implements IWidget {
@Override
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
if (Mouse.isButtonDown(0) && active)
setCurrent(yMouse - yPos - height / 2, true);
else
active = false;
if (Mouse.isButtonDown(0) && active) setCurrent(yMouse - yPos - height / 2, true);
else active = false;
int offset = (int) (current * (ySize - height));
boolean in = mouseIn(xMouse, yMouse);
@@ -54,8 +51,7 @@ public class WScroll implements IWidget {
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
active = mouseIn(xMouse, yMouse);
if (active)
setCurrent(yMouse - yPos - height / 2, true);
if (active) setCurrent(yMouse - yPos - height / 2, true);
return active;
}
@@ -91,7 +87,7 @@ public class WScroll implements IWidget {
}
public WScroll setCurrent(float ratio, boolean notify) {
//setCurrent((int) ((ySize - height) * ratio), false);
// setCurrent((int) ((ySize - height) * ratio), false);
current = ratio;
if (current < 0) current = 0;
if (current > 1) current = 1;
@@ -1,14 +1,13 @@
package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-28.
@@ -32,9 +31,7 @@ public class WSearch extends WTextField {
public void refresh() {
boolean b = false;
for (ISearchable i : lss)
if (i.setFilter(textField.getText()))
b = true;
for (ISearchable i : lss) if (i.setFilter(textField.getText())) b = true;
setColor(b ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
}
}
@@ -1,24 +1,20 @@
package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.Circulator;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
import static me.towdium.jecalculation.gui.JecaGui.Font.SHADOW;
import static me.towdium.jecalculation.gui.Resource.WGT_ARR_L;
import static me.towdium.jecalculation.gui.Resource.WGT_ARR_R;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.Circulator;
/**
* Author: towdium
* Date: 17-8-19.
@@ -39,8 +35,11 @@ public class WSwitcher extends WContainer {
protected String temp;
public WSwitcher(int xPos, int yPos, int xSize, int total) {
this(xPos, yPos, xSize,
IntStream.rangeClosed(1, total).mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
this(
xPos,
yPos,
xSize,
IntStream.rangeClosed(1, total).mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
}
public WSwitcher(int xPos, int yPos, int xSize, List<String> keys) {
@@ -100,7 +99,6 @@ public class WSwitcher extends WContainer {
return keys;
}
public String getText() {
return temp == null ? keys.get(index.current()) : temp;
}
@@ -2,11 +2,10 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-21.
@@ -38,10 +37,8 @@ public class WText implements IWidget {
@Override
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
int x = xPos + (centred ? xSize / 2 - font.getTextWidth(key) / 2 : 0);
if (xSize == UNDEFINED)
gui.drawText(x, yPos, font, key);
else
gui.drawText(x, yPos, xSize, font, key);
if (xSize == UNDEFINED) gui.drawText(x, yPos, font, key);
else gui.drawText(x, yPos, xSize, font, key);
return false;
}
}
@@ -2,13 +2,12 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-18.
@@ -41,8 +40,7 @@ public class WTextField implements IWidget {
textField.setText("");
notifyLsnr();
return true;
} else
return false;
} else return false;
}
@Override
@@ -54,8 +52,7 @@ public class WTextField implements IWidget {
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
boolean ret = textField.textboxKeyTyped(ch, code);
if (ret)
notifyLsnr();
if (ret) notifyLsnr();
return ret;
}
@@ -80,7 +77,6 @@ public class WTextField implements IWidget {
}
protected void notifyLsnr() {
if (listener != null)
listener.invoke(this);
if (listener != null) listener.invoke(this);
}
}
}
@@ -1,16 +1,15 @@
package me.towdium.jecalculation.gui.widgets;
import static me.towdium.jecalculation.gui.Resource.*;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: Towdium
* Date: 18-12-7
@@ -24,7 +23,6 @@ public class WTick extends WContainer {
boolean disabled;
ListenerAction<? super WTick> listener;
public WTick(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
this.xPos = xPos;
this.yPos = yPos;
@@ -50,13 +48,10 @@ public class WTick extends WContainer {
}
public WTick setSelected(boolean selected) {
if (selected == selected())
return this;
if (selected == selected()) return this;
remove(button);
if (selected)
button = new Selected(xPos, yPos, xSize, ySize, name);
else
button = new Normal(xPos, yPos, xSize, ySize, name);
if (selected) button = new Selected(xPos, yPos, xSize, ySize, name);
else button = new Normal(xPos, yPos, xSize, ySize, name);
add(button);
return this;
}
@@ -1,21 +1,20 @@
package me.towdium.jecalculation.gui.widgets;
import static java.lang.String.join;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.I18n;
import me.towdium.jecalculation.utils.wrappers.Pair;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static java.lang.String.join;
/**
* Author: towdium
* Date: 17-9-16.
@@ -33,8 +32,7 @@ public abstract class WTooltip implements IWidget {
@Override
public boolean onDraw(JecaGui gui, int xMouse, int yMouse) {
if (name != null)
timer.setState(mouseIn(xMouse, yMouse));
if (name != null) timer.setState(mouseIn(xMouse, yMouse));
return false;
}
@@ -42,17 +40,14 @@ public abstract class WTooltip implements IWidget {
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (timer.getTime() > 500) {
List<Pair<String, Boolean>> suffix = getSuffix().stream()
.map(s -> I18n.search(s.isEmpty() ?
join(".", "gui", name) :
join(".", "gui", name, s)))
.collect(Collectors.toList());
.map(s -> I18n.search(s.isEmpty() ? join(".", "gui", name) : join(".", "gui", name, s)))
.collect(Collectors.toList());
String str = suffix.stream()
.filter(p -> p.two)
.findFirst()
.map(p -> p.one)
.orElse(JecaGui.ALWAYS_TOOLTIP ? suffix.get(0).one : null);
if (str != null)
Collections.addAll(tooltip, str.split("\n"));
.filter(p -> p.two)
.findFirst()
.map(p -> p.one)
.orElse(JecaGui.ALWAYS_TOOLTIP ? suffix.get(0).one : null);
if (str != null) Collections.addAll(tooltip, str.split("\n"));
}
return false;
}
@@ -3,14 +3,13 @@ package me.towdium.jecalculation.nei;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import cpw.mods.fml.common.Loader;
import java.util.ArrayList;
import java.util.List;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.nei.adapter.*;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class Adapter {
public static List<IAdapter> adapters = new ArrayList<>();
@@ -19,7 +18,7 @@ public class Adapter {
String modId = name.substring(0, name.indexOf(":"));
String itemId = name.substring(name.indexOf(":") + 1);
if (Loader.isModLoaded("gregtech")) {
if(GregTech6.isGT6()) {
if (GregTech6.isGT6()) {
return GregTech6.convertFluid(itemStack);
} else {
return GregTech.convertFluid(itemStack);
@@ -31,60 +30,65 @@ public class Adapter {
public static void init() {
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Start=====");
if (Loader.isModLoaded("Forestry")) {
JustEnoughCalculation.logger.info("Forestry installed");
JustEnoughCalculation.logger.info("Forestry detected");
adapters.add(new Forestry());
}
if (Loader.isModLoaded("appliedenergistics2")) {
JustEnoughCalculation.logger.info("ae2 not supported");
JustEnoughCalculation.logger.info("ae2 detected");
adapters.add(new AE2());
}
if (Loader.isModLoaded("gregtech")) {
if(GregTech6.isGT6()) {
JustEnoughCalculation.logger.info("gregtech6 installed");
if (GregTech6.isGT6()) {
JustEnoughCalculation.logger.info("gregtech6 detected");
adapters.add(new GregTech6());
} else {
JustEnoughCalculation.logger.info("gregtech5 installed");
JustEnoughCalculation.logger.info("gregtech5 detected");
adapters.add(new GregTech());
}
}
try {
if (Loader.isModLoaded("miscutils")) {
adapters.add(new GTPP());
JustEnoughCalculation.logger.info("gt++ installed");
JustEnoughCalculation.logger.info("gt++ detected");
}
} catch (Exception e) {
JustEnoughCalculation.logger.info("exception when installing gt++");
JustEnoughCalculation.logger.error("Init error with gt++");
e.printStackTrace();
}
if (Loader.isModLoaded("Avaritia")) {
JustEnoughCalculation.logger.info("Avaritia installed");
JustEnoughCalculation.logger.info("Avaritia detected");
adapters.add(new Avaritia());
}
if (Loader.isModLoaded("EnderIO")) {
JustEnoughCalculation.logger.info("EnderIO installed");
JustEnoughCalculation.logger.info("EnderIO detected");
adapters.add(new EnderIO());
}
if (Loader.isModLoaded("thaumcraftneiplugin")) {
adapters.add(new Thaum());
JustEnoughCalculation.logger.info("Thaumcraft installed");
JustEnoughCalculation.logger.info("Thaumcraft detected");
}
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Finish=====");
}
public static void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
// raw inputs
recipe.getIngredientStacks(index)
.stream()
.map((positionedStack) -> (Object[]) positionedStack.items)
.forEach(inputs::add);
recipe.getIngredientStacks(index).stream()
.map((positionedStack) -> (Object[]) positionedStack.items)
.forEach(inputs::add);
// raw outputs
PositionedStack resultStack = recipe.getResultStack(index);
if (resultStack != null)
outputs.add(resultStack.items);
if (resultStack != null) outputs.add(resultStack.items);
for (IAdapter adapter : adapters) {
adapter.handleRecipe(recipe, index, inputs, outputs);
try {
for (IAdapter adapter : adapters) {
adapter.handleRecipe(recipe, index, inputs, outputs);
}
} catch (Exception e) {
Utilities.addChatMessage(Utilities.ChatMessage.RECIPE_TRANSFER_ERROR);
JustEnoughCalculation.logger.error(
"Exception when handling recipe: " + recipe.getClass().getName());
e.printStackTrace();
}
}
}
@@ -7,6 +7,9 @@ import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.CostList;
import me.towdium.jecalculation.data.structure.Recipe;
@@ -16,10 +19,6 @@ import me.towdium.jecalculation.utils.wrappers.Trio;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import java.util.*;
import java.util.stream.Collectors;
@SideOnly(Side.CLIENT)
public class JecaOverlayHandler implements IOverlayHandler {
@Override
@@ -37,11 +36,10 @@ public class JecaOverlayHandler implements IOverlayHandler {
}
}
private static EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> convertRecipe(IRecipeHandler recipe,
int recipeIndex,
Class<?> context) {
EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> merged = new EnumMap<>(
Recipe.IO.class); // item disamb raw
private static EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> convertRecipe(
IRecipeHandler recipe, int recipeIndex, Class<?> context) {
// item disamb raw
EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> merged = new EnumMap<>(Recipe.IO.class);
// merge recipe input, output and catalysts
List<Object[]> recipeInputs = new ArrayList<>();
@@ -61,31 +59,32 @@ public class JecaOverlayHandler implements IOverlayHandler {
return merged;
}
private static void merge(EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> dst,
List<?> objs,
Class<?> context,
Recipe.IO type) {
private static void merge(
EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> dst,
List<?> objs,
Class<?> context,
Recipe.IO type) {
List<ILabel> list = objs.stream().map(ILabel.Converter::from).collect(Collectors.toList());
if (list.isEmpty())
return;
if (list.isEmpty()) return;
ILabel rep = list.get(0).copy();
if (type == Recipe.IO.INPUT && list.size() != 1)
rep = ILabel.CONVERTER.first(list, context);
if (type == Recipe.IO.INPUT && list.size() != 1) rep = ILabel.CONVERTER.first(list, context);
ILabel fin = rep;
dst.computeIfAbsent(type, i -> new ArrayList<>()).stream().filter(p -> {
CostList cl = new CostList(list);
if (p.three.equals(cl)) {
ILabel.MERGER.merge(p.one, fin).ifPresent(i -> p.one = i);
p.two = p.two.merge(cl, true, false);
return true;
} else
return false;
}).findAny().orElseGet(() -> {
Trio<ILabel, CostList, CostList> ret = new Trio<>(fin, new CostList(list), new CostList(list));
dst.get(type).add(ret);
return ret;
});
dst.computeIfAbsent(type, i -> new ArrayList<>()).stream()
.filter(p -> {
CostList cl = new CostList(list);
if (p.three.equals(cl)) {
ILabel.MERGER.merge(p.one, fin).ifPresent(i -> p.one = i);
p.two = CostList.merge(p.two, cl, true);
return true;
} else return false;
})
.findAny()
.orElseGet(() -> {
Trio<ILabel, CostList, CostList> ret = new Trio<>(fin, new CostList(list), new CostList(list));
dst.get(type).add(ret);
return ret;
});
}
private static Optional<ItemStack> getCatalyst(@Nonnull IRecipeHandler handler) {
@@ -107,5 +106,4 @@ public class JecaOverlayHandler implements IOverlayHandler {
ItemStack itemStack = info.getItemStack();
return Optional.ofNullable(itemStack);
}
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.nei;
import codechicken.nei.guihook.IContainerTooltipHandler;
import java.util.List;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import java.util.List;
public class JecaTooltipHandler implements IContainerTooltipHandler {
@Override
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
@@ -19,11 +18,8 @@ public class JecaTooltipHandler implements IContainerTooltipHandler {
}
@Override
public List<String> handleItemTooltip(GuiContainer gui,
ItemStack itemstack,
int mousex,
int mousey,
List<String> currenttip) {
public List<String> handleItemTooltip(
GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
if (gui instanceof JecaGui) {
NEIPlugin.setLabelUnderMouse(itemstack);
}
@@ -2,16 +2,15 @@ package me.towdium.jecalculation.nei;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.nei.adapter.IAdapter;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import me.towdium.jecalculation.Tags;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.nei.adapter.IAdapter;
public class NEICalculatorConfig implements IConfigureNEI {
@@ -19,26 +18,27 @@ public class NEICalculatorConfig implements IConfigureNEI {
public void loadConfig() {
Adapter.init();
/* null For the recipeHandlers which extend `TemplateRecipeHandler` without override the `getOverlayIdentifier` function */
Set<String> baseOverlayIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "smelting", "fuel", "brewing", null));
Set<String> baseOverlayIdentifiers =
new HashSet<>(Arrays.asList("crafting", "crafting2x2", "smelting", "fuel", "brewing", null));
Set<String> adapterIdentifiers = Adapter.adapters.stream()
.map(IAdapter::getAllOverlayIdentifier)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
.map(IAdapter::getAllOverlayIdentifier)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
Stream.concat(baseOverlayIdentifiers.stream(), adapterIdentifiers.stream()).forEach(ident -> {
API.registerGuiOverlay(JecaGui.class, ident);
API.registerGuiOverlayHandler(JecaGui.class, new JecaOverlayHandler(), ident);
});
Stream.concat(baseOverlayIdentifiers.stream(), adapterIdentifiers.stream())
.forEach(ident -> {
API.registerGuiOverlay(JecaGui.class, ident);
API.registerGuiOverlayHandler(JecaGui.class, new JecaOverlayHandler(), ident);
});
}
@Override
public String getName() {
return JustEnoughCalculation.Reference.MODNAME;
return Tags.MODNAME;
}
@Override
public String getVersion() {
return JustEnoughCalculation.Reference.VERSION;
return Tags.VERSION;
}
}
@@ -19,7 +19,8 @@ public class NEIPlugin {
public static void init() {
GuiContainerManager.addTooltipHandler(new JecaTooltipHandler());
// nei version check
String neiVersion = Loader.instance().getIndexedModList().get("NotEnoughItems").getVersion();
String neiVersion =
Loader.instance().getIndexedModList().get("NotEnoughItems").getVersion();
JustEnoughCalculation.logger.info("NEI version: " + neiVersion);
Version version = new Version(neiVersion);
if (version.isSuccess() && version.compareTo(CATALYST_NEI_VERSION) >= 0) {
@@ -37,8 +38,7 @@ public class NEIPlugin {
}
public static ILabel getLabelUnderMouse() {
if (NEIPlugin.currentItemStack == null)
return ILabel.EMPTY;
if (NEIPlugin.currentItemStack == null) return ILabel.EMPTY;
Object stack = Adapter.convertFluid(NEIPlugin.currentItemStack);
return ILabel.Converter.from(stack);
}
@@ -1,22 +1,19 @@
package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class AE2 implements IAdapter{
public class AE2 implements IAdapter {
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList("inscriber", "grindstone"));
}
@Override
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
}
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {}
}
@@ -1,7 +1,7 @@
package me.towdium.jecalculation.nei.adapter;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Optional;
import javax.annotation.ParametersAreNonnullByDefault;
@SuppressWarnings("rawtypes")
@ParametersAreNonnullByDefault
@@ -14,5 +14,4 @@ public class AdapterUtil {
return Optional.empty();
}
}
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class Avaritia implements IAdapter {
@@ -17,7 +16,5 @@ public class Avaritia implements IAdapter {
}
@Override
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
}
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {}
}
@@ -2,32 +2,35 @@ package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
@ParametersAreNonnullByDefault
public class EnderIO implements IAdapter {
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(
Arrays.asList("EnderIOAlloySmelter", "EIOEnchanter", "EnderIOSagMill", "EnderIOSliceAndSplice",
"EnderIOSoulBinder", "EnderIOVat"));
return new HashSet<>(Arrays.asList(
"EnderIOAlloySmelter",
"EIOEnchanter",
"EnderIOSagMill",
"EnderIOSliceAndSplice",
"EnderIOSoulBinder",
"EnderIOVat"));
}
private final static Set<Class<?>> defaultHandlers;
private final static Class<?> vat;
private static final Set<Class<?>> defaultHandlers;
private static final Class<?> vat;
static {
List<String> handlers = Stream.of("SagMillRecipeHandler")
.map(name -> "crazypants.enderio.nei." + name)
.collect(Collectors.toList());
.map(name -> "crazypants.enderio.nei." + name)
.collect(Collectors.toList());
defaultHandlers = new HashSet<>();
for (String handler : handlers) {
try {
@@ -48,10 +51,9 @@ public class EnderIO implements IAdapter {
@Override
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
if (defaultHandlers.stream().anyMatch(aClass -> aClass.isInstance(recipe))) {
List<ItemStack[]> otherStacks = recipe.getOtherStacks(index)
.stream()
.map(positionedStack -> positionedStack.items)
.collect(Collectors.toList());
List<ItemStack[]> otherStacks = recipe.getOtherStacks(index).stream()
.map(positionedStack -> positionedStack.items)
.collect(Collectors.toList());
outputs.addAll(otherStacks);
} else {
try {
@@ -60,8 +62,8 @@ public class EnderIO implements IAdapter {
Field arecipes = vat.getField("arecipes");
@SuppressWarnings("unchecked")
TemplateRecipeHandler.CachedRecipe cachedRecipe = ((ArrayList<TemplateRecipeHandler.CachedRecipe>) arecipes
.get(recipe)).get(index);
TemplateRecipeHandler.CachedRecipe cachedRecipe =
((ArrayList<TemplateRecipeHandler.CachedRecipe>) arecipes.get(recipe)).get(index);
Field resultField = vatInnerRecipe.getDeclaredField("result");
Field inFluidField = vatInnerRecipe.getDeclaredField("inFluid");
@@ -70,8 +72,8 @@ public class EnderIO implements IAdapter {
FluidStack result = (FluidStack) resultField.get(cachedRecipe);
FluidStack inFluid = (FluidStack) inFluidField.get(cachedRecipe);
inputs.add(new Object[]{inFluid});
outputs.add(new Object[]{result});
inputs.add(new Object[] {inFluid});
outputs.add(new Object[] {result});
resultField.setAccessible(false);
inFluidField.setAccessible(false);
}
@@ -5,14 +5,13 @@ import codechicken.nei.recipe.IRecipeHandler;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.recipes.nei.*;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
@ParametersAreNonnullByDefault
public class Forestry implements IAdapter {
@@ -34,16 +33,14 @@ public class Forestry implements IAdapter {
private void bottler(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
if (recipe instanceof NEIHandlerBottler) {
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
if (fluids.size() >= 1)
inputs.add(fluids.get(0).toArray());
if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray());
}
}
private void carpenter(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
if (recipe instanceof NEIHandlerCarpenter) {
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
if (fluids.size() >= 1)
inputs.add(fluids.get(0).toArray());
if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray());
}
}
@@ -57,8 +54,7 @@ public class Forestry implements IAdapter {
private void fabricator(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
if (recipe instanceof NEIHandlerFabricator) {
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
if (fluids.size() >= 1)
inputs.add(fluids.get(0).toArray());
if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray());
}
}
@@ -66,7 +62,8 @@ public class Forestry implements IAdapter {
if (recipe instanceof NEIHandlerFermenter) {
List<PositionedFluidTank> tanks = getTanks(recipe, recipeIndex);
tanks.forEach(tank -> {
Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
Object[] fluids =
Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
if (tank.position.x == 30) {
// source
inputs.add(fluids);
@@ -81,8 +78,7 @@ public class Forestry implements IAdapter {
private void moistener(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
if (recipe instanceof NEIHandlerMoistener) {
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
if (fluids.size() >= 1)
inputs.add(fluids.get(0).toArray());
if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray());
List<PositionedStack> otherStacks = recipe.getOtherStacks(recipeIndex);
otherStacks.forEach(positionedStack -> {
ItemStack[] items = positionedStack.items;
@@ -100,15 +96,15 @@ public class Forestry implements IAdapter {
private void squeezer(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
if (recipe instanceof NEIHandlerSqueezer) {
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
if (fluids.size() >= 1)
outputs.add(fluids.get(0).toArray());
if (fluids.size() >= 1) outputs.add(fluids.get(0).toArray());
}
}
private void still(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
if (recipe instanceof NEIHandlerStill) {
getTanks(recipe, recipeIndex).forEach(tank -> {
Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
Object[] fluids =
Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
if (tank.position.x == 30) {
// input
inputs.add(fluids);
@@ -128,19 +124,15 @@ public class Forestry implements IAdapter {
* @return fluid tanks
*/
private List<List<FluidStack>> getFluids(RecipeHandlerBase recipe, int recipeIndex) {
return ((RecipeHandlerBase.CachedBaseRecipe) recipe.arecipes.get(recipeIndex)).getFluidTanks()
.stream()
.map(positionedFluidTank -> Arrays
.stream(positionedFluidTank.tanks)
.map(FluidTank::getFluid)
.collect(
Collectors.toList()))
.collect(Collectors.toList());
return ((RecipeHandlerBase.CachedBaseRecipe) recipe.arecipes.get(recipeIndex))
.getFluidTanks().stream()
.map(positionedFluidTank -> Arrays.stream(positionedFluidTank.tanks)
.map(FluidTank::getFluid)
.collect(Collectors.toList()))
.collect(Collectors.toList());
}
private List<PositionedFluidTank> getTanks(RecipeHandlerBase recipe, int recipeIndex) {
return ((RecipeHandlerBase.CachedBaseRecipe) recipe.arecipes.get(recipeIndex)).getFluidTanks();
}
}
@@ -1,14 +1,12 @@
package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* don't work, why?
@@ -16,18 +14,27 @@ import java.util.stream.Stream;
@ParametersAreNonnullByDefault
public class GTPP extends GregTech {
private final static Set<Class<?>> defaultHandlers;
private static final Set<Class<?>> defaultHandlers;
static {
List<String> handlers = Stream.of(
// gtpp after 2020/5/30
"GTPP_NEI_DefaultHandler", "GT_NEI_VacFurnace", "GT_NEI_RFPP", "GT_NEI_multiCentriElectroFreezer",
"GT_NEI_MillingMachine", "GT_NEI_FluidReactor", "GT_NEI_FlotationCell", "DecayableRecipeHandler",
// gtpp before 2020/5/30
"GT_NEI_DefaultHandler", "GT_NEI_Dehydrator", "GT_NEI_MultiBlockHandler", "GTPP_NEI_CustomMapHandler",
"GTPP_NEI_DefaultHandlerEx"
).map(name -> "gtPlusPlus.nei." + name).collect(Collectors.toList());
// gtpp after 2020/5/30
"GTPP_NEI_DefaultHandler",
"GT_NEI_VacFurnace",
"GT_NEI_RFPP",
"GT_NEI_multiCentriElectroFreezer",
"GT_NEI_MillingMachine",
"GT_NEI_FluidReactor",
"GT_NEI_FlotationCell",
"DecayableRecipeHandler",
// gtpp before 2020/5/30
"GT_NEI_DefaultHandler",
"GT_NEI_Dehydrator",
"GT_NEI_MultiBlockHandler",
"GTPP_NEI_CustomMapHandler",
"GTPP_NEI_DefaultHandlerEx")
.map(name -> "gtPlusPlus.nei." + name)
.collect(Collectors.toList());
defaultHandlers = new HashSet<>();
for (String handler : handlers) {
@@ -44,12 +51,11 @@ public class GTPP extends GregTech {
Set<String> recipeNames = new HashSet<>();
try {
// add as many recipe as possible
recipeNames.addAll(
this.reflectGetRecipeMapNEIName("gregtech.api.util.GTPP_Recipe$GTPP_Recipe_Map", "sMappings"));
recipeNames.addAll(this.reflectGetRecipeMapNEIName("gregtech.api.util.GTPP_Recipe$GTPP_Recipe_Map_Internal",
"sMappingsEx"));
recipeNames.addAll(this.reflectGetRecipeMapNEIName(
"gregtech.api.util.GTPP_Recipe$GTPP_Recipe_Map_Internal", "sMappingsEx"));
} catch (Exception e) {
e.printStackTrace();
}
@@ -62,7 +68,7 @@ public class GTPP extends GregTech {
@Override
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
if (defaultHandlers.stream().anyMatch(aClass -> aClass.isInstance(recipe))) {
handleDefault(recipe, index, inputs, outputs);
handleDefault(recipe, index, inputs, outputs, true);
}
}
}
@@ -2,18 +2,17 @@ package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@ParametersAreNonnullByDefault
public class GregTech implements IAdapter {
@@ -30,13 +29,16 @@ public class GregTech implements IAdapter {
Field mNEINameField = gtRecipeMapClz.getField("mNEIName");
Collection sMappings = (Collection) sMappingsField.get(null);
return (Set<String>) sMappings.stream().map(sMapping -> {
try {
return mNEINameField.get(sMapping);
} catch (IllegalAccessException e) {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
return (Set<String>) sMappings.stream()
.map(sMapping -> {
try {
return mNEINameField.get(sMapping);
} catch (IllegalAccessException e) {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
return new HashSet<>();
@@ -66,15 +68,32 @@ public class GregTech implements IAdapter {
}
protected void handleDefault(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
for (int i = 0; i < inputs.size(); i++) {
Object[] objects = Arrays.stream(inputs.get(i)).map(o -> GregTech.convertFluid((ItemStack) o)).toArray();
inputs.set(i, objects);
handleDefault(recipe, index, inputs, outputs, false);
}
protected void handleDefault(
IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs, boolean clearOutput) {
inputs.replaceAll(ts -> Arrays.stream(ts)
.map(o -> {
if (o instanceof ItemStack) {
return GregTech.convertFluid((ItemStack) o);
} else if (o instanceof FluidStack) {
return o;
} else {
throw new IllegalArgumentException(
"Shall get ItemStack or FluidStack, but get: " + o.getClass());
}
})
.toArray());
if (clearOutput) {
outputs.clear();
}
List<PositionedStack> otherStacks = recipe.getOtherStacks(index);
outputs.addAll(otherStacks.stream()
.map(positionedStack -> positionedStack.items)
.map(itemStacks -> Arrays.stream(itemStacks).map(GregTech::convertFluid).toArray())
.collect(Collectors.toList()));
.map(positionedStack -> positionedStack.items)
.map(itemStacks ->
Arrays.stream(itemStacks).map(GregTech::convertFluid).toArray())
.collect(Collectors.toList()));
}
public static Object convertFluid(ItemStack itemStack) {
@@ -93,19 +112,23 @@ public class GregTech implements IAdapter {
Enum display_fluid = Enum.valueOf(itemListClz, "Display_Fluid");
Method getItem = itemListClz.getMethod("getItem");
Item displayFluidItem = (Item) getItem.invoke(display_fluid);
if (!isStackValid(aDisplayStack) || aDisplayStack.getItem() != displayFluidItem ||
!aDisplayStack.hasTagCompound())
return null;
if (!isStackValid(aDisplayStack)
|| aDisplayStack.getItem() != displayFluidItem
|| !aDisplayStack.hasTagCompound()) return null;
Fluid tFluid = FluidRegistry.getFluid(displayFluidItem.getDamage(aDisplayStack));
return new FluidStack(tFluid, (int) aDisplayStack.getTagCompound().getLong("mFluidDisplayAmount"));
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
} catch (ClassNotFoundException
| NoSuchMethodException
| IllegalAccessException
| InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
private static boolean isStackValid(Object aStack) {
return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null &&
((ItemStack) aStack).stackSize >= 0;
return (aStack instanceof ItemStack)
&& ((ItemStack) aStack).getItem() != null
&& ((ItemStack) aStack).stackSize >= 0;
}
}
@@ -1,18 +1,16 @@
package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
@ParametersAreNonnullByDefault
public class GregTech6 implements IAdapter {
@@ -71,7 +69,7 @@ public class GregTech6 implements IAdapter {
@Override
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
if (gtRecipeMap.isInstance(recipe)) {
TemplateRecipeHandler a = (TemplateRecipeHandler)recipe;
TemplateRecipeHandler a = (TemplateRecipeHandler) recipe;
TemplateRecipeHandler.CachedRecipe cachedRecipe = a.arecipes.get(index);
try {
Field mRecipe = gtRecipeMapCachedRecipe.getDeclaredField("mRecipe");
@@ -80,27 +78,32 @@ public class GregTech6 implements IAdapter {
Field mOutputs = gtRecipe.getDeclaredField("mOutputs");
Field mFluidInputs = gtRecipe.getDeclaredField("mFluidInputs");
Field mFluidOutputs = gtRecipe.getDeclaredField("mFluidOutputs");
ItemStack[] input =(ItemStack[]) mInputs.get(re);
ItemStack[] input = (ItemStack[]) mInputs.get(re);
ItemStack[] output = (ItemStack[]) mOutputs.get(re);
FluidStack[] fluidInputs = (FluidStack[]) mFluidInputs.get(re);
FluidStack[] fluidOutputs = (FluidStack[]) mFluidOutputs.get(re);
inputs.clear();
inputs.addAll(Stream.concat(Arrays.stream(input), Arrays.stream(fluidInputs)).map(i -> new Object[] {i}).collect(Collectors.toList()));
inputs.addAll(Stream.concat(Arrays.stream(input), Arrays.stream(fluidInputs))
.map(i -> new Object[] {i})
.collect(Collectors.toList()));
outputs.clear();
outputs.addAll(Stream.concat(Arrays.stream(output), Arrays.stream(fluidOutputs)).map(o -> new Object[] {o}).collect(Collectors.toList()));
outputs.addAll(Stream.concat(Arrays.stream(output), Arrays.stream(fluidOutputs))
.map(o -> new Object[] {o})
.collect(Collectors.toList()));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
// for (int i = 0; i < inputs.size(); i++) {
// Object[] objects = Arrays.stream(inputs.get(i)).map(o -> GregTech6.convertFluid((ItemStack) o)).toArray();
// inputs.set(i, objects);
// }
// List<PositionedStack> otherStacks = recipe.getOtherStacks(index);
// outputs.addAll(otherStacks
// .stream()
// .map(stack -> stack.items)
// .map(is -> Arrays.stream(is).map(GregTech6::convertFluid).toArray())
// .collect(Collectors.toList()));
// for (int i = 0; i < inputs.size(); i++) {
// Object[] objects = Arrays.stream(inputs.get(i)).map(o ->
// GregTech6.convertFluid((ItemStack) o)).toArray();
// inputs.set(i, objects);
// }
// List<PositionedStack> otherStacks = recipe.getOtherStacks(index);
// outputs.addAll(otherStacks
// .stream()
// .map(stack -> stack.items)
// .map(is -> Arrays.stream(is).map(GregTech6::convertFluid).toArray())
// .collect(Collectors.toList()));
}
}
@@ -114,7 +117,10 @@ public class GregTech6 implements IAdapter {
Class<?> itemListClz = Class.forName("gregapi.data.FL");
Method getFluidMethod = itemListClz.getDeclaredMethod("getFluid", ItemStack.class, boolean.class);
return (FluidStack) getFluidMethod.invoke(null, aDisplayStack, true);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
} catch (ClassNotFoundException
| NoSuchMethodException
| IllegalAccessException
| InvocationTargetException e) {
e.printStackTrace();
return null;
}
@@ -1,17 +1,17 @@
package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public interface IAdapter {
default Set<String> getAllOverlayIdentifier() {
return Collections.emptySet();
};
}
;
void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs);
}
@@ -2,29 +2,35 @@ package me.towdium.jecalculation.nei.adapter;
import codechicken.nei.recipe.IRecipeHandler;
import cpw.mods.fml.common.registry.GameData;
import net.minecraft.item.ItemStack;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.ItemStack;
@ParametersAreNonnullByDefault
public class Thaum implements IAdapter {
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(
Arrays.asList("arcaneshapedrecipes", "arcaneshapelessrecipes", "aspectsRecipe", "cruciblerecipe",
"infusionCrafting"));
return new HashSet<>(Arrays.asList(
"arcaneshapedrecipes",
"arcaneshapelessrecipes",
"aspectsRecipe",
"cruciblerecipe",
"infusionCrafting"));
}
private final static Set<Class<?>> defaultHandlers;
private static final Set<Class<?>> defaultHandlers;
static {
List<String> handlers = Stream.of("ArcaneShapedRecipeHandler", "ArcaneShapelessRecipeHandler",
"AspectRecipeHandler", "CrucibleRecipeHandler", "InfusionRecipeHandler")
.map(name -> "com.djgiannuzz.thaumcraftneiplugin.nei.recipehandler." + name)
.collect(Collectors.toList());
List<String> handlers = Stream.of(
"ArcaneShapedRecipeHandler",
"ArcaneShapelessRecipeHandler",
"AspectRecipeHandler",
"CrucibleRecipeHandler",
"InfusionRecipeHandler")
.map(name -> "com.djgiannuzz.thaumcraftneiplugin.nei.recipehandler." + name)
.collect(Collectors.toList());
defaultHandlers = new HashSet<>();
for (String handler : handlers) {
try {
@@ -52,7 +58,6 @@ public class Thaum implements IAdapter {
}
}
}
}
}
}
@@ -1,33 +0,0 @@
package me.towdium.jecalculation.network;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.command.JecaCommand;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.event.Handlers;
import net.minecraftforge.client.ClientCommandHandler;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiCraft;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiMath;
@SideOnly(Side.CLIENT)
public class ClientHandler {
public void initPre() {
Handlers.register();
}
public void initPost() {
ILabel.initServer();
ClientCommandHandler.instance.registerCommand(new JecaCommand());
ILabel.initClient();
Controller.loadFromLocal();
}
public void init() {
ClientRegistry.registerKeyBinding(keyOpenGuiCraft);
ClientRegistry.registerKeyBinding(keyOpenGuiMath);
}
}
@@ -0,0 +1,58 @@
package me.towdium.jecalculation.network;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiCraft;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiMath;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.event.*;
import me.towdium.jecalculation.JecaConfig;
import me.towdium.jecalculation.command.JecaCommand;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.event.Handlers;
import me.towdium.jecalculation.nei.NEIPlugin;
import net.minecraftforge.client.ClientCommandHandler;
@SuppressWarnings("unused")
public class ClientProxy extends CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
JecaConfig.preInit(event);
Handlers.register();
}
public void init(FMLInitializationEvent event) {
ClientRegistry.registerKeyBinding(keyOpenGuiCraft);
ClientRegistry.registerKeyBinding(keyOpenGuiMath);
}
public void postInit(FMLPostInitializationEvent event) {
ILabel.initServer();
ClientCommandHandler.instance.registerCommand(new JecaCommand());
ILabel.initClient();
Controller.loadFromLocal();
NEIPlugin.init();
}
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
super.serverAboutToStart(event);
}
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {
super.serverStarting(event);
}
public void serverStarted(FMLServerStartedEvent event) {
super.serverStarted(event);
}
public void serverStopping(FMLServerStoppingEvent event) {
super.serverStopping(event);
}
public void serverStopped(FMLServerStoppedEvent event) {
super.serverStopped(event);
}
}
@@ -0,0 +1,27 @@
package me.towdium.jecalculation.network;
import cpw.mods.fml.common.event.*;
public class CommonProxy {
// preInit "Run before anything else. Read your config, create blocks, items,
// etc, and register them with the GameRegistry."
public void preInit(FMLPreInitializationEvent event) {}
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
public void init(FMLInitializationEvent event) {}
// postInit "Handle interaction with other mods, complete your setup based on this."
public void postInit(FMLPostInitializationEvent event) {}
public void serverAboutToStart(FMLServerAboutToStartEvent event) {}
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {}
public void serverStarted(FMLServerStartedEvent event) {}
public void serverStopping(FMLServerStoppingEvent event) {}
public void serverStopped(FMLServerStoppedEvent event) {}
}
@@ -1,11 +1,11 @@
package me.towdium.jecalculation.polyfill;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
/**
* This annotation can be applied to a package, class or method to indicate that
@@ -23,5 +23,4 @@ import java.lang.annotation.RetentionPolicy;
@TypeQualifierDefault(ElementType.METHOD)
// Note: This is a copy of javax.annotation.ParametersAreNonnullByDefault with target changed to METHOD
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodsReturnNonnullByDefault {
}
public @interface MethodsReturnNonnullByDefault {}
@@ -1,18 +1,14 @@
package me.towdium.jecalculation.polyfill;
import me.towdium.jecalculation.utils.ItemStackHelper;
import me.towdium.jecalculation.utils.ReflectionHelper;
import net.minecraft.item.Item;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
@ParametersAreNonnullByDefault
public class NBTHelper {
/**
@@ -55,5 +51,4 @@ public class NBTHelper {
stack.writeToNBT(ret);
return ret;
}
}
@@ -1,14 +1,14 @@
package me.towdium.jecalculation.polyfill.google.common.collect;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class Streams {
public interface FunctionWithIndex<T, R> {
@@ -38,8 +38,7 @@ public class Streams {
* <p>The order of the resulting stream is defined if and only if the order of the original stream
* was defined.
*/
public static <T, R> Stream<R> mapWithIndex(
Stream<T> stream, FunctionWithIndex<? super T, ? extends R> function) {
public static <T, R> Stream<R> mapWithIndex(Stream<T> stream, FunctionWithIndex<? super T, ? extends R> function) {
checkNotNull(stream);
checkNotNull(function);
boolean isParallel = stream.isParallel();
@@ -98,7 +97,7 @@ public class Streams {
}
private abstract static class MapWithIndexSpliterator<
F extends Spliterator<?>, R, S extends MapWithIndexSpliterator<F, R, S>>
F extends Spliterator<?>, R, S extends MapWithIndexSpliterator<F, R, S>>
implements Spliterator<R> {
final F fromSpliterator;
long index;
@@ -129,8 +128,7 @@ public class Streams {
@Override
public int characteristics() {
return fromSpliterator.characteristics()
& (Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED);
return fromSpliterator.characteristics() & (Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED);
}
}
}
File diff suppressed because it is too large. Load diff
@@ -1,6 +1,5 @@
package me.towdium.jecalculation.polyfill.mc.util;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
@@ -9,81 +8,64 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
public class NonNullList<E> extends AbstractList<E>
{
public class NonNullList<E> extends AbstractList<E> {
private final List<E> delegate;
private final E defaultElement;
public static <E> NonNullList<E> create()
{
public static <E> NonNullList<E> create() {
return new NonNullList<E>();
}
public static <E> NonNullList<E> withSize(int size, E fill)
{
public static <E> NonNullList<E> withSize(int size, E fill) {
Validate.notNull(fill);
Object[] aobject = new Object[size];
Arrays.fill(aobject, fill);
return new NonNullList<E>(Arrays.asList((E[])aobject), fill);
return new NonNullList<E>(Arrays.asList((E[]) aobject), fill);
}
public static <E> NonNullList<E> from(E defaultElementIn, E... elements)
{
public static <E> NonNullList<E> from(E defaultElementIn, E... elements) {
return new NonNullList<E>(Arrays.asList(elements), defaultElementIn);
}
protected NonNullList()
{
protected NonNullList() {
this(new ArrayList(), null);
}
protected NonNullList(List<E> delegateIn, @Nullable E listType)
{
protected NonNullList(List<E> delegateIn, @Nullable E listType) {
this.delegate = delegateIn;
this.defaultElement = listType;
}
@Nonnull
public E get(int p_get_1_)
{
public E get(int p_get_1_) {
return this.delegate.get(p_get_1_);
}
public E set(int p_set_1_, E p_set_2_)
{
public E set(int p_set_1_, E p_set_2_) {
Validate.notNull(p_set_2_);
return this.delegate.set(p_set_1_, p_set_2_);
}
public void add(int p_add_1_, E p_add_2_)
{
public void add(int p_add_1_, E p_add_2_) {
Validate.notNull(p_add_2_);
this.delegate.add(p_add_1_, p_add_2_);
}
public E remove(int p_remove_1_)
{
public E remove(int p_remove_1_) {
return this.delegate.remove(p_remove_1_);
}
public int size()
{
public int size() {
return this.delegate.size();
}
public void clear()
{
if (this.defaultElement == null)
{
public void clear() {
if (this.defaultElement == null) {
super.clear();
}
else
{
for (int i = 0; i < this.size(); ++i)
{
} else {
for (int i = 0; i < this.size(); ++i) {
this.set(i, this.defaultElement);
}
}
}
}
Loaded 100 of 116 files, more files were not shown because too many files have changed in this diff. Show more