mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 00:37:46 +00:00
Spotless
This commit is contained in:
1 parent
dfe94d1549
commit
d15ceed3d9
95 files changed
+1756
-2338
No files matched your search
@@ -3,9 +3,9 @@ name: Build and test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, main ]
|
||||
branches: [ 1.7.10 ]
|
||||
push:
|
||||
branches: [ master, main ]
|
||||
branches: [ 1.7.10, 1.7.10-dev ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
|
||||
@@ -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,7 +130,9 @@ public class JecaConfig {
|
||||
}
|
||||
|
||||
public enum EnumType {
|
||||
Boolean, ListString, Error
|
||||
Boolean,
|
||||
ListString,
|
||||
Error
|
||||
}
|
||||
|
||||
public static Object empty;
|
||||
@@ -140,7 +144,6 @@ public class JecaConfig {
|
||||
config.save();
|
||||
}
|
||||
|
||||
|
||||
public static void handleInit() {
|
||||
for (EnumItems item : EnumItems.values()) {
|
||||
item.init();
|
||||
|
||||
@@ -6,24 +6,19 @@ 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 javax.annotation.ParametersAreNonnullByDefault;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.network.ClientHandler;
|
||||
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 = Tags.MODID,
|
||||
name = Tags.MODNAME,
|
||||
version = Tags.VERSION,
|
||||
dependencies = "required-after:NotEnoughItems")
|
||||
@Mod(modid = Tags.MODID, name = Tags.MODNAME, version = Tags.VERSION, dependencies = "required-after:NotEnoughItems")
|
||||
public class JustEnoughCalculation {
|
||||
@Mod.Instance(Tags.MODID)
|
||||
public static JustEnoughCalculation INSTANCE;
|
||||
@@ -48,5 +43,4 @@ public class JustEnoughCalculation {
|
||||
handler.initPost();
|
||||
NEIPlugin.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,5 +6,4 @@ public class Tags {
|
||||
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,6 +2,13 @@ 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.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;
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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.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;
|
||||
|
||||
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) {
|
||||
@@ -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,18 +1,17 @@
|
||||
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 javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.towdium.jecalculation.utils.Utilities.stream;
|
||||
|
||||
// positive => generate; negative => require
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
@@ -83,8 +82,7 @@ public class CostList {
|
||||
CostList c = (CostList) obj;
|
||||
CostList m = c.copy().multiply(-1);
|
||||
return CostList.merge(this, m, true).labels.isEmpty();
|
||||
} else
|
||||
return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public CostList copy() {
|
||||
@@ -93,7 +91,6 @@ public class CostList {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEmpty() {
|
||||
return labels.isEmpty();
|
||||
}
|
||||
@@ -102,7 +99,6 @@ public class CostList {
|
||||
return labels;
|
||||
}
|
||||
|
||||
|
||||
public Calculator calculate() {
|
||||
return new Calculator();
|
||||
}
|
||||
@@ -110,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;
|
||||
}
|
||||
|
||||
@@ -131,14 +126,12 @@ public class CostList {
|
||||
int count = 0;
|
||||
while (next != null) {
|
||||
CostList original = getCurrent();
|
||||
List<ILabel> outL = next.one.getOutput()
|
||||
.stream()
|
||||
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.getInput()
|
||||
.stream()
|
||||
List<ILabel> inL = next.one.getInput().stream()
|
||||
.filter(i -> i != ILabel.EMPTY)
|
||||
.collect(Collectors.toList());
|
||||
CostList inC = new CostList(inL);
|
||||
@@ -175,14 +168,12 @@ public class CostList {
|
||||
for (; index < labels.size(); index++) {
|
||||
ILabel label = labels.get(index);
|
||||
// Only negative label is required to calculate
|
||||
if (label.getAmount() >= 0)
|
||||
continue;
|
||||
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();
|
||||
}
|
||||
@@ -190,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() {
|
||||
|
||||
@@ -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,15 +69,11 @@ 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);
|
||||
@@ -115,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;
|
||||
}
|
||||
|
||||
@@ -144,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,11 +2,10 @@ package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import me.towdium.jecalculation.Tags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
@@ -14,8 +13,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Resource {
|
||||
public static final ResourceLocation location = new ResourceLocation(
|
||||
Tags.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);
|
||||
@@ -39,7 +38,7 @@ public class Adapter {
|
||||
adapters.add(new AE2());
|
||||
}
|
||||
if (Loader.isModLoaded("gregtech")) {
|
||||
if(GregTech6.isGT6()) {
|
||||
if (GregTech6.isGT6()) {
|
||||
JustEnoughCalculation.logger.info("gregtech6 detected");
|
||||
adapters.add(new GregTech6());
|
||||
} else {
|
||||
@@ -73,15 +72,13 @@ public class Adapter {
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
for (IAdapter adapter : adapters) {
|
||||
@@ -89,7 +86,8 @@ public class Adapter {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Utilities.addChatMessage(Utilities.ChatMessage.RECIPE_TRANSFER_ERROR);
|
||||
JustEnoughCalculation.logger.error("Exception when handling recipe: " + recipe.getClass().getName());
|
||||
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,9 +36,8 @@ public class JecaOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumMap<Recipe.IO, List<Trio<ILabel, CostList, CostList>>> convertRecipe(IRecipeHandler recipe,
|
||||
int recipeIndex,
|
||||
Class<?> context) {
|
||||
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);
|
||||
|
||||
@@ -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 = 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;
|
||||
});
|
||||
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.Tags;
|
||||
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,17 +18,18 @@ 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
|
||||
|
||||
@@ -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) {
|
||||
@@ -47,8 +54,8 @@ public class GTPP extends GregTech {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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<>();
|
||||
@@ -69,23 +71,28 @@ public class GregTech implements IAdapter {
|
||||
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());
|
||||
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())
|
||||
.map(itemStacks ->
|
||||
Arrays.stream(itemStacks).map(GregTech::convertFluid).toArray())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@@ -105,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,5 +1,8 @@
|
||||
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.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -9,9 +12,6 @@ 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 {
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+282
-456
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package me.towdium.jecalculation.polyfill.mc.util.math;
|
||||
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MathHelper
|
||||
{
|
||||
public class MathHelper {
|
||||
public static final float SQRT_2 = sqrt(2.0F);
|
||||
private static final float[] SIN_TABLE = new float[65536];
|
||||
private static final Random RANDOM = new Random();
|
||||
@@ -17,135 +14,103 @@ public class MathHelper
|
||||
private static final double[] ASINE_TAB;
|
||||
private static final double[] COS_TAB;
|
||||
|
||||
public static float sin(float value)
|
||||
{
|
||||
return SIN_TABLE[(int)(value * 10430.378F) & 65535];
|
||||
public static float sin(float value) {
|
||||
return SIN_TABLE[(int) (value * 10430.378F) & 65535];
|
||||
}
|
||||
|
||||
public static float cos(float value)
|
||||
{
|
||||
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
|
||||
public static float cos(float value) {
|
||||
return SIN_TABLE[(int) (value * 10430.378F + 16384.0F) & 65535];
|
||||
}
|
||||
|
||||
public static float sqrt(float value)
|
||||
{
|
||||
return (float)Math.sqrt((double)value);
|
||||
public static float sqrt(float value) {
|
||||
return (float) Math.sqrt((double) value);
|
||||
}
|
||||
|
||||
public static float sqrt(double value)
|
||||
{
|
||||
return (float)Math.sqrt(value);
|
||||
public static float sqrt(double value) {
|
||||
return (float) Math.sqrt(value);
|
||||
}
|
||||
|
||||
public static int floor(float value)
|
||||
{
|
||||
int i = (int)value;
|
||||
return value < (float)i ? i - 1 : i;
|
||||
public static int floor(float value) {
|
||||
int i = (int) value;
|
||||
return value < (float) i ? i - 1 : i;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int fastFloor(double value)
|
||||
{
|
||||
return (int)(value + 1024.0D) - 1024;
|
||||
public static int fastFloor(double value) {
|
||||
return (int) (value + 1024.0D) - 1024;
|
||||
}
|
||||
|
||||
public static int floor(double value)
|
||||
{
|
||||
int i = (int)value;
|
||||
return value < (double)i ? i - 1 : i;
|
||||
public static int floor(double value) {
|
||||
int i = (int) value;
|
||||
return value < (double) i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static long lfloor(double value)
|
||||
{
|
||||
long i = (long)value;
|
||||
return value < (double)i ? i - 1L : i;
|
||||
public static long lfloor(double value) {
|
||||
long i = (long) value;
|
||||
return value < (double) i ? i - 1L : i;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int absFloor(double value)
|
||||
{
|
||||
return (int)(value >= 0.0D ? value : -value + 1.0D);
|
||||
public static int absFloor(double value) {
|
||||
return (int) (value >= 0.0D ? value : -value + 1.0D);
|
||||
}
|
||||
|
||||
public static float abs(float value)
|
||||
{
|
||||
public static float abs(float value) {
|
||||
return value >= 0.0F ? value : -value;
|
||||
}
|
||||
|
||||
public static int abs(int value)
|
||||
{
|
||||
public static int abs(int value) {
|
||||
return value >= 0 ? value : -value;
|
||||
}
|
||||
|
||||
public static int ceil(float value)
|
||||
{
|
||||
int i = (int)value;
|
||||
return value > (float)i ? i + 1 : i;
|
||||
public static int ceil(float value) {
|
||||
int i = (int) value;
|
||||
return value > (float) i ? i + 1 : i;
|
||||
}
|
||||
|
||||
public static int ceil(double value)
|
||||
{
|
||||
int i = (int)value;
|
||||
return value > (double)i ? i + 1 : i;
|
||||
public static int ceil(double value) {
|
||||
int i = (int) value;
|
||||
return value > (double) i ? i + 1 : i;
|
||||
}
|
||||
|
||||
public static int clamp(int num, int min, int max)
|
||||
{
|
||||
if (num < min)
|
||||
{
|
||||
public static int clamp(int num, int min, int max) {
|
||||
if (num < min) {
|
||||
return min;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return num > max ? max : num;
|
||||
}
|
||||
}
|
||||
|
||||
public static float clamp(float num, float min, float max)
|
||||
{
|
||||
if (num < min)
|
||||
{
|
||||
public static float clamp(float num, float min, float max) {
|
||||
if (num < min) {
|
||||
return min;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return num > max ? max : num;
|
||||
}
|
||||
}
|
||||
|
||||
public static double clamp(double num, double min, double max)
|
||||
{
|
||||
if (num < min)
|
||||
{
|
||||
public static double clamp(double num, double min, double max) {
|
||||
if (num < min) {
|
||||
return min;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return num > max ? max : num;
|
||||
}
|
||||
}
|
||||
|
||||
public static double clampedLerp(double lowerBnd, double upperBnd, double slide)
|
||||
{
|
||||
if (slide < 0.0D)
|
||||
{
|
||||
public static double clampedLerp(double lowerBnd, double upperBnd, double slide) {
|
||||
if (slide < 0.0D) {
|
||||
return lowerBnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return slide > 1.0D ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide;
|
||||
}
|
||||
}
|
||||
|
||||
public static double absMax(double p_76132_0_, double p_76132_2_)
|
||||
{
|
||||
if (p_76132_0_ < 0.0D)
|
||||
{
|
||||
public static double absMax(double p_76132_0_, double p_76132_2_) {
|
||||
if (p_76132_0_ < 0.0D) {
|
||||
p_76132_0_ = -p_76132_0_;
|
||||
}
|
||||
|
||||
if (p_76132_2_ < 0.0D)
|
||||
{
|
||||
if (p_76132_2_ < 0.0D) {
|
||||
p_76132_2_ = -p_76132_2_;
|
||||
}
|
||||
|
||||
@@ -153,149 +118,119 @@ public class MathHelper
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int intFloorDiv(int p_76137_0_, int p_76137_1_)
|
||||
{
|
||||
public static int intFloorDiv(int p_76137_0_, int p_76137_1_) {
|
||||
return p_76137_0_ < 0 ? -((-p_76137_0_ - 1) / p_76137_1_) - 1 : p_76137_0_ / p_76137_1_;
|
||||
}
|
||||
|
||||
public static int getInt(Random random, int minimum, int maximum)
|
||||
{
|
||||
public static int getInt(Random random, int minimum, int maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextInt(maximum - minimum + 1) + minimum;
|
||||
}
|
||||
|
||||
public static float nextFloat(Random random, float minimum, float maximum)
|
||||
{
|
||||
public static float nextFloat(Random random, float minimum, float maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextFloat() * (maximum - minimum) + minimum;
|
||||
}
|
||||
|
||||
public static double nextDouble(Random random, double minimum, double maximum)
|
||||
{
|
||||
public static double nextDouble(Random random, double minimum, double maximum) {
|
||||
return minimum >= maximum ? minimum : random.nextDouble() * (maximum - minimum) + minimum;
|
||||
}
|
||||
|
||||
public static double average(long[] values)
|
||||
{
|
||||
public static double average(long[] values) {
|
||||
long i = 0L;
|
||||
|
||||
for (long j : values)
|
||||
{
|
||||
for (long j : values) {
|
||||
i += j;
|
||||
}
|
||||
|
||||
return (double)i / (double)values.length;
|
||||
return (double) i / (double) values.length;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static boolean epsilonEquals(float p_180185_0_, float p_180185_1_)
|
||||
{
|
||||
public static boolean epsilonEquals(float p_180185_0_, float p_180185_1_) {
|
||||
return abs(p_180185_1_ - p_180185_0_) < 1.0E-5F;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int normalizeAngle(int p_180184_0_, int p_180184_1_)
|
||||
{
|
||||
public static int normalizeAngle(int p_180184_0_, int p_180184_1_) {
|
||||
return (p_180184_0_ % p_180184_1_ + p_180184_1_) % p_180184_1_;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static float positiveModulo(float numerator, float denominator)
|
||||
{
|
||||
public static float positiveModulo(float numerator, float denominator) {
|
||||
return (numerator % denominator + denominator) % denominator;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static double positiveModulo(double numerator, double denominator)
|
||||
{
|
||||
public static double positiveModulo(double numerator, double denominator) {
|
||||
return (numerator % denominator + denominator) % denominator;
|
||||
}
|
||||
|
||||
public static float wrapDegrees(float value)
|
||||
{
|
||||
public static float wrapDegrees(float value) {
|
||||
value = value % 360.0F;
|
||||
|
||||
if (value >= 180.0F)
|
||||
{
|
||||
if (value >= 180.0F) {
|
||||
value -= 360.0F;
|
||||
}
|
||||
|
||||
if (value < -180.0F)
|
||||
{
|
||||
if (value < -180.0F) {
|
||||
value += 360.0F;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double wrapDegrees(double value)
|
||||
{
|
||||
public static double wrapDegrees(double value) {
|
||||
value = value % 360.0D;
|
||||
|
||||
if (value >= 180.0D)
|
||||
{
|
||||
if (value >= 180.0D) {
|
||||
value -= 360.0D;
|
||||
}
|
||||
|
||||
if (value < -180.0D)
|
||||
{
|
||||
if (value < -180.0D) {
|
||||
value += 360.0D;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int wrapDegrees(int angle)
|
||||
{
|
||||
public static int wrapDegrees(int angle) {
|
||||
angle = angle % 360;
|
||||
|
||||
if (angle >= 180)
|
||||
{
|
||||
if (angle >= 180) {
|
||||
angle -= 360;
|
||||
}
|
||||
|
||||
if (angle < -180)
|
||||
{
|
||||
if (angle < -180) {
|
||||
angle += 360;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static int getInt(String value, int defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static int getInt(String value, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (Throwable var3)
|
||||
{
|
||||
} catch (Throwable var3) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(String value, int defaultValue, int max)
|
||||
{
|
||||
public static int getInt(String value, int defaultValue, int max) {
|
||||
return Math.max(max, getInt(value, defaultValue));
|
||||
}
|
||||
|
||||
public static double getDouble(String value, double defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static double getDouble(String value, double defaultValue) {
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
catch (Throwable var4)
|
||||
{
|
||||
} catch (Throwable var4) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(String value, double defaultValue, double max)
|
||||
{
|
||||
public static double getDouble(String value, double defaultValue, double max) {
|
||||
return Math.max(max, getDouble(value, defaultValue));
|
||||
}
|
||||
|
||||
public static int smallestEncompassingPowerOfTwo(int value)
|
||||
{
|
||||
public static int smallestEncompassingPowerOfTwo(int value) {
|
||||
int i = value - 1;
|
||||
i = i | i >> 1;
|
||||
i = i | i >> 2;
|
||||
@@ -305,36 +240,26 @@ public class MathHelper
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
private static boolean isPowerOfTwo(int value)
|
||||
{
|
||||
private static boolean isPowerOfTwo(int value) {
|
||||
return value != 0 && (value & value - 1) == 0;
|
||||
}
|
||||
|
||||
public static int log2DeBruijn(int value)
|
||||
{
|
||||
public static int log2DeBruijn(int value) {
|
||||
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)value * 125613361L >> 27) & 31];
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) ((long) value * 125613361L >> 27) & 31];
|
||||
}
|
||||
|
||||
public static int log2(int value)
|
||||
{
|
||||
public static int log2(int value) {
|
||||
return log2DeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
|
||||
}
|
||||
|
||||
public static int roundUp(int number, int interval)
|
||||
{
|
||||
if (interval == 0)
|
||||
{
|
||||
public static int roundUp(int number, int interval) {
|
||||
if (interval == 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (number == 0)
|
||||
{
|
||||
} else if (number == 0) {
|
||||
return interval;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (number < 0)
|
||||
{
|
||||
} else {
|
||||
if (number < 0) {
|
||||
interval *= -1;
|
||||
}
|
||||
|
||||
@@ -343,99 +268,83 @@ public class MathHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static long getCoordinateRandom(int x, int y, int z)
|
||||
{
|
||||
long i = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y;
|
||||
public static long getCoordinateRandom(int x, int y, int z) {
|
||||
long i = (long) (x * 3129871) ^ (long) z * 116129781L ^ (long) y;
|
||||
i = i * i * 42317861L + i * 11L;
|
||||
return i;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int rgb(float rIn, float gIn, float bIn)
|
||||
{
|
||||
public static int rgb(float rIn, float gIn, float bIn) {
|
||||
return rgb(floor(rIn * 255.0F), floor(gIn * 255.0F), floor(bIn * 255.0F));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int rgb(int rIn, int gIn, int bIn)
|
||||
{
|
||||
public static int rgb(int rIn, int gIn, int bIn) {
|
||||
int lvt_3_1_ = (rIn << 8) + gIn;
|
||||
lvt_3_1_ = (lvt_3_1_ << 8) + bIn;
|
||||
return lvt_3_1_;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int multiplyColor(int p_180188_0_, int p_180188_1_)
|
||||
{
|
||||
public static int multiplyColor(int p_180188_0_, int p_180188_1_) {
|
||||
int i = (p_180188_0_ & 16711680) >> 16;
|
||||
int j = (p_180188_1_ & 16711680) >> 16;
|
||||
int k = (p_180188_0_ & 65280) >> 8;
|
||||
int l = (p_180188_1_ & 65280) >> 8;
|
||||
int i1 = (p_180188_0_ & 255) >> 0;
|
||||
int j1 = (p_180188_1_ & 255) >> 0;
|
||||
int k1 = (int)((float)i * (float)j / 255.0F);
|
||||
int l1 = (int)((float)k * (float)l / 255.0F);
|
||||
int i2 = (int)((float)i1 * (float)j1 / 255.0F);
|
||||
int k1 = (int) ((float) i * (float) j / 255.0F);
|
||||
int l1 = (int) ((float) k * (float) l / 255.0F);
|
||||
int i2 = (int) ((float) i1 * (float) j1 / 255.0F);
|
||||
return p_180188_0_ & -16777216 | k1 << 16 | l1 << 8 | i2;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static double frac(double number)
|
||||
{
|
||||
public static double frac(double number) {
|
||||
return number - Math.floor(number);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static long getPositionRandom(Vec3i pos)
|
||||
{
|
||||
public static long getPositionRandom(Vec3i pos) {
|
||||
return getCoordinateRandom(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static UUID getRandomUUID(Random rand)
|
||||
{
|
||||
public static UUID getRandomUUID(Random rand) {
|
||||
long i = rand.nextLong() & -61441L | 16384L;
|
||||
long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
|
||||
return new UUID(i, j);
|
||||
}
|
||||
|
||||
public static UUID getRandomUUID()
|
||||
{
|
||||
public static UUID getRandomUUID() {
|
||||
return getRandomUUID(RANDOM);
|
||||
}
|
||||
|
||||
public static double pct(double p_181160_0_, double p_181160_2_, double p_181160_4_)
|
||||
{
|
||||
public static double pct(double p_181160_0_, double p_181160_2_, double p_181160_4_) {
|
||||
return (p_181160_0_ - p_181160_2_) / (p_181160_4_ - p_181160_2_);
|
||||
}
|
||||
|
||||
public static double atan2(double p_181159_0_, double p_181159_2_)
|
||||
{
|
||||
public static double atan2(double p_181159_0_, double p_181159_2_) {
|
||||
double d0 = p_181159_2_ * p_181159_2_ + p_181159_0_ * p_181159_0_;
|
||||
|
||||
if (Double.isNaN(d0))
|
||||
{
|
||||
if (Double.isNaN(d0)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
boolean flag = p_181159_0_ < 0.0D;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if (flag) {
|
||||
p_181159_0_ = -p_181159_0_;
|
||||
}
|
||||
|
||||
boolean flag1 = p_181159_2_ < 0.0D;
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
if (flag1) {
|
||||
p_181159_2_ = -p_181159_2_;
|
||||
}
|
||||
|
||||
boolean flag2 = p_181159_0_ > p_181159_2_;
|
||||
|
||||
if (flag2)
|
||||
{
|
||||
if (flag2) {
|
||||
double d1 = p_181159_2_;
|
||||
p_181159_2_ = p_181159_0_;
|
||||
p_181159_0_ = d1;
|
||||
@@ -445,7 +354,7 @@ public class MathHelper
|
||||
p_181159_2_ = p_181159_2_ * d9;
|
||||
p_181159_0_ = p_181159_0_ * d9;
|
||||
double d2 = FRAC_BIAS + p_181159_0_;
|
||||
int i = (int)Double.doubleToRawLongBits(d2);
|
||||
int i = (int) Double.doubleToRawLongBits(d2);
|
||||
double d3 = ASINE_TAB[i];
|
||||
double d4 = COS_TAB[i];
|
||||
double d5 = d2 - FRAC_BIAS;
|
||||
@@ -453,18 +362,15 @@ public class MathHelper
|
||||
double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D;
|
||||
double d8 = d3 + d7;
|
||||
|
||||
if (flag2)
|
||||
{
|
||||
if (flag2) {
|
||||
d8 = (Math.PI / 2D) - d8;
|
||||
}
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
if (flag1) {
|
||||
d8 = Math.PI - d8;
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if (flag) {
|
||||
d8 = -d8;
|
||||
}
|
||||
|
||||
@@ -472,8 +378,7 @@ public class MathHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static double fastInvSqrt(double p_181161_0_)
|
||||
{
|
||||
public static double fastInvSqrt(double p_181161_0_) {
|
||||
double d0 = 0.5D * p_181161_0_;
|
||||
long i = Double.doubleToRawLongBits(p_181161_0_);
|
||||
i = 6910469410427058090L - (i >> 1);
|
||||
@@ -483,10 +388,9 @@ public class MathHelper
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int hsvToRGB(float hue, float saturation, float value)
|
||||
{
|
||||
int i = (int)(hue * 6.0F) % 6;
|
||||
float f = hue * 6.0F - (float)i;
|
||||
public static int hsvToRGB(float hue, float saturation, float value) {
|
||||
int i = (int) (hue * 6.0F) % 6;
|
||||
float f = hue * 6.0F - (float) i;
|
||||
float f1 = value * (1.0F - saturation);
|
||||
float f2 = value * (1.0F - f * saturation);
|
||||
float f3 = value * (1.0F - (1.0F - f) * saturation);
|
||||
@@ -494,8 +398,7 @@ public class MathHelper
|
||||
float f5;
|
||||
float f6;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
switch (i) {
|
||||
case 0:
|
||||
f4 = value;
|
||||
f5 = f3;
|
||||
@@ -527,17 +430,17 @@ public class MathHelper
|
||||
f6 = f2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue
|
||||
+ ", " + saturation + ", " + value);
|
||||
}
|
||||
|
||||
int j = clamp((int)(f4 * 255.0F), 0, 255);
|
||||
int k = clamp((int)(f5 * 255.0F), 0, 255);
|
||||
int l = clamp((int)(f6 * 255.0F), 0, 255);
|
||||
int j = clamp((int) (f4 * 255.0F), 0, 255);
|
||||
int k = clamp((int) (f5 * 255.0F), 0, 255);
|
||||
int l = clamp((int) (f6 * 255.0F), 0, 255);
|
||||
return j << 16 | k << 8 | l;
|
||||
}
|
||||
|
||||
public static int hash(int p_188208_0_)
|
||||
{
|
||||
public static int hash(int p_188208_0_) {
|
||||
p_188208_0_ = p_188208_0_ ^ p_188208_0_ >>> 16;
|
||||
p_188208_0_ = p_188208_0_ * -2048144789;
|
||||
p_188208_0_ = p_188208_0_ ^ p_188208_0_ >>> 13;
|
||||
@@ -546,21 +449,21 @@ public class MathHelper
|
||||
return p_188208_0_;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for (int i = 0; i < 65536; ++i)
|
||||
{
|
||||
SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D);
|
||||
static {
|
||||
for (int i = 0; i < 65536; ++i) {
|
||||
SIN_TABLE[i] = (float) Math.sin((double) i * Math.PI * 2.0D / 65536.0D);
|
||||
}
|
||||
|
||||
MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] {
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11,
|
||||
5, 10, 9
|
||||
};
|
||||
FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
ASINE_TAB = new double[257];
|
||||
COS_TAB = new double[257];
|
||||
|
||||
for (int j = 0; j < 257; ++j)
|
||||
{
|
||||
double d0 = (double)j / 256.0D;
|
||||
for (int j = 0; j < 257; ++j) {
|
||||
double d0 = (double) j / 256.0D;
|
||||
double d1 = Math.asin(d0);
|
||||
COS_TAB[j] = Math.cos(d1);
|
||||
ASINE_TAB[j] = d1;
|
||||
|
||||
@@ -1,126 +1,106 @@
|
||||
package me.towdium.jecalculation.polyfill.mc.util.math;
|
||||
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
public class Vec3i implements Comparable<Vec3i>
|
||||
{
|
||||
public class Vec3i implements Comparable<Vec3i> {
|
||||
public static final Vec3i NULL_VECTOR = new Vec3i(0, 0, 0);
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public Vec3i(int xIn, int yIn, int zIn)
|
||||
{
|
||||
public Vec3i(int xIn, int yIn, int zIn) {
|
||||
this.x = xIn;
|
||||
this.y = yIn;
|
||||
this.z = zIn;
|
||||
}
|
||||
|
||||
public Vec3i(double xIn, double yIn, double zIn)
|
||||
{
|
||||
public Vec3i(double xIn, double yIn, double zIn) {
|
||||
this(MathHelper.floor(xIn), MathHelper.floor(yIn), MathHelper.floor(zIn));
|
||||
}
|
||||
|
||||
public boolean equals(Object p_equals_1_)
|
||||
{
|
||||
if (this == p_equals_1_)
|
||||
{
|
||||
public boolean equals(Object p_equals_1_) {
|
||||
if (this == p_equals_1_) {
|
||||
return true;
|
||||
}
|
||||
else if (!(p_equals_1_ instanceof Vec3i))
|
||||
{
|
||||
} else if (!(p_equals_1_ instanceof Vec3i)) {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3i vec3i = (Vec3i)p_equals_1_;
|
||||
} else {
|
||||
Vec3i vec3i = (Vec3i) p_equals_1_;
|
||||
|
||||
if (this.getX() != vec3i.getX())
|
||||
{
|
||||
if (this.getX() != vec3i.getX()) {
|
||||
return false;
|
||||
}
|
||||
else if (this.getY() != vec3i.getY())
|
||||
{
|
||||
} else if (this.getY() != vec3i.getY()) {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return this.getZ() == vec3i.getZ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
||||
}
|
||||
|
||||
public int compareTo(Vec3i p_compareTo_1_)
|
||||
{
|
||||
if (this.getY() == p_compareTo_1_.getY())
|
||||
{
|
||||
return this.getZ() == p_compareTo_1_.getZ() ? this.getX() - p_compareTo_1_.getX() : this.getZ() - p_compareTo_1_.getZ();
|
||||
}
|
||||
else
|
||||
{
|
||||
public int compareTo(Vec3i p_compareTo_1_) {
|
||||
if (this.getY() == p_compareTo_1_.getY()) {
|
||||
return this.getZ() == p_compareTo_1_.getZ()
|
||||
? this.getX() - p_compareTo_1_.getX()
|
||||
: this.getZ() - p_compareTo_1_.getZ();
|
||||
} else {
|
||||
return this.getY() - p_compareTo_1_.getY();
|
||||
}
|
||||
}
|
||||
|
||||
public int getX()
|
||||
{
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY()
|
||||
{
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ()
|
||||
{
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public Vec3i crossProduct(Vec3i vec)
|
||||
{
|
||||
return new Vec3i(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX());
|
||||
public Vec3i crossProduct(Vec3i vec) {
|
||||
return new Vec3i(
|
||||
this.getY() * vec.getZ() - this.getZ() * vec.getY(),
|
||||
this.getZ() * vec.getX() - this.getX() * vec.getZ(),
|
||||
this.getX() * vec.getY() - this.getY() * vec.getX());
|
||||
}
|
||||
|
||||
public double getDistance(int xIn, int yIn, int zIn)
|
||||
{
|
||||
double d0 = (double)(this.getX() - xIn);
|
||||
double d1 = (double)(this.getY() - yIn);
|
||||
double d2 = (double)(this.getZ() - zIn);
|
||||
public double getDistance(int xIn, int yIn, int zIn) {
|
||||
double d0 = (double) (this.getX() - xIn);
|
||||
double d1 = (double) (this.getY() - yIn);
|
||||
double d2 = (double) (this.getZ() - zIn);
|
||||
return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
||||
}
|
||||
|
||||
public double distanceSq(double toX, double toY, double toZ)
|
||||
{
|
||||
double d0 = (double)this.getX() - toX;
|
||||
double d1 = (double)this.getY() - toY;
|
||||
double d2 = (double)this.getZ() - toZ;
|
||||
public double distanceSq(double toX, double toY, double toZ) {
|
||||
double d0 = (double) this.getX() - toX;
|
||||
double d1 = (double) this.getY() - toY;
|
||||
double d2 = (double) this.getZ() - toZ;
|
||||
return d0 * d0 + d1 * d1 + d2 * d2;
|
||||
}
|
||||
|
||||
public double distanceSqToCenter(double xIn, double yIn, double zIn)
|
||||
{
|
||||
double d0 = (double)this.getX() + 0.5D - xIn;
|
||||
double d1 = (double)this.getY() + 0.5D - yIn;
|
||||
double d2 = (double)this.getZ() + 0.5D - zIn;
|
||||
public double distanceSqToCenter(double xIn, double yIn, double zIn) {
|
||||
double d0 = (double) this.getX() + 0.5D - xIn;
|
||||
double d1 = (double) this.getY() + 0.5D - yIn;
|
||||
double d2 = (double) this.getZ() + 0.5D - zIn;
|
||||
return d0 * d0 + d1 * d1 + d2 * d2;
|
||||
}
|
||||
|
||||
public double distanceSq(Vec3i to)
|
||||
{
|
||||
return this.distanceSq((double)to.getX(), (double)to.getY(), (double)to.getZ());
|
||||
public double distanceSq(Vec3i to) {
|
||||
return this.distanceSq((double) to.getX(), (double) to.getY(), (double) to.getZ());
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("x", this.getX())
|
||||
.add("y", this.getY())
|
||||
.add("z", this.getZ())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ public class ClientUtils {
|
||||
|
||||
public static void playClickSound(float pitchIn) {
|
||||
try {
|
||||
mc().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), pitchIn));
|
||||
mc().getSoundHandler()
|
||||
.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), pitchIn));
|
||||
} catch (Exception e) {
|
||||
// why may crash ??
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemStackHelper {
|
||||
public static final Item EMPTY_ITEM = null;
|
||||
public static final ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null);
|
||||
public static final ItemStack EMPTY_ITEM_STACK = new ItemStack((Item) null);
|
||||
|
||||
public static boolean isEmpty(ItemStack stack) {
|
||||
return stack == null || stack == EMPTY_ITEM_STACK || stack.getItem() == EMPTY_ITEM;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -10,6 +8,7 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.IntStream;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
public class NBTJson {
|
||||
private static final Pattern numberPattern = Pattern.compile("^([-+]?[\\d]+\\.?[0-9]*)([bBsSlLfFdD]?)$");
|
||||
@@ -20,16 +19,16 @@ public class NBTJson {
|
||||
final String jsonString = toJsonObject(tag).toString();
|
||||
return gson.toJson(parser.parse(jsonString));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static JsonElement toJsonObject(NBTBase nbt) {
|
||||
if (nbt instanceof NBTTagCompound) {
|
||||
// NBTTagCompound
|
||||
final NBTTagCompound nbtTagCompound = (NBTTagCompound) nbt;
|
||||
final Map<String, NBTBase> tagMap = (Map<String, NBTBase>)nbtTagCompound.tagMap;
|
||||
|
||||
final Map<String, NBTBase> tagMap = (Map<String, NBTBase>) nbtTagCompound.tagMap;
|
||||
|
||||
JsonObject root = new JsonObject();
|
||||
for (Map.Entry<String, NBTBase> nbtEntry : tagMap.entrySet() ) {
|
||||
for (Map.Entry<String, NBTBase> nbtEntry : tagMap.entrySet()) {
|
||||
root.add(nbtEntry.getKey(), toJsonObject(nbtEntry.getValue()));
|
||||
}
|
||||
return root;
|
||||
@@ -38,7 +37,7 @@ public class NBTJson {
|
||||
return new JsonPrimitive(((NBTBase.NBTPrimitive) nbt).func_150286_g());
|
||||
} else if (nbt instanceof NBTTagString) {
|
||||
// String
|
||||
return new JsonPrimitive(((NBTTagString) nbt).func_150285_a_());
|
||||
return new JsonPrimitive(((NBTTagString) nbt).func_150285_a_());
|
||||
} else if (nbt instanceof NBTTagList) {
|
||||
// Tag List
|
||||
JsonArray arr = new JsonArray();
|
||||
@@ -47,14 +46,14 @@ public class NBTJson {
|
||||
} else if (nbt instanceof NBTTagIntArray) {
|
||||
// Int Array
|
||||
JsonArray arr = new JsonArray();
|
||||
for(int i : ((NBTTagIntArray) nbt).func_150302_c()) {
|
||||
for (int i : ((NBTTagIntArray) nbt).func_150302_c()) {
|
||||
arr.add(new JsonPrimitive(i));
|
||||
}
|
||||
return arr;
|
||||
} else if (nbt instanceof NBTTagByteArray) {
|
||||
// Byte Array
|
||||
JsonArray arr = new JsonArray();
|
||||
for(int i : ((NBTTagByteArray) nbt).func_150292_c()) {
|
||||
for (int i : ((NBTTagByteArray) nbt).func_150292_c()) {
|
||||
arr.add(new JsonPrimitive(i));
|
||||
}
|
||||
return arr;
|
||||
@@ -62,19 +61,19 @@ public class NBTJson {
|
||||
throw new IllegalArgumentException("Unsupported NBT Tag: " + NBTBase.NBTTypes[nbt.getId()] + " - " + nbt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static NBTBase toNbt(JsonElement jsonElement) {
|
||||
if (jsonElement instanceof JsonPrimitive) {
|
||||
// Number or String
|
||||
final JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
|
||||
final String jsonString = jsonPrimitive.getAsString();
|
||||
final Matcher m = numberPattern.matcher(jsonString);
|
||||
if(m.find()) {
|
||||
if (m.find()) {
|
||||
// Number
|
||||
final String numberString = m.group(1);
|
||||
if (m.groupCount() == 2 && m.group(2).length() > 0) {
|
||||
final char numberType = m.group(2).charAt(0);
|
||||
switch(numberType) {
|
||||
switch (numberType) {
|
||||
case 'b':
|
||||
case 'B':
|
||||
return new NBTTagByte(Byte.parseByte(numberString));
|
||||
@@ -92,34 +91,34 @@ public class NBTJson {
|
||||
return new NBTTagDouble(Double.parseDouble(numberString));
|
||||
}
|
||||
} else {
|
||||
if (numberString.contains("."))
|
||||
return new NBTTagDouble(Double.parseDouble(numberString));
|
||||
else
|
||||
return new NBTTagInt(Integer.parseInt(numberString));
|
||||
if (numberString.contains(".")) return new NBTTagDouble(Double.parseDouble(numberString));
|
||||
else return new NBTTagInt(Integer.parseInt(numberString));
|
||||
}
|
||||
} else {
|
||||
// String
|
||||
return new NBTTagString(jsonString);
|
||||
}
|
||||
} else if (jsonElement instanceof JsonArray) {
|
||||
} else if (jsonElement instanceof JsonArray) {
|
||||
// NBTTagIntArray or NBTTagList
|
||||
final JsonArray jsonArray = (JsonArray) jsonElement;
|
||||
final List<NBTBase> nbtList = new ArrayList<>();
|
||||
|
||||
|
||||
for (JsonElement element : jsonArray) {
|
||||
nbtList.add(toNbt(element));
|
||||
}
|
||||
|
||||
|
||||
if (nbtList.stream().allMatch(n -> n instanceof NBTTagInt)) {
|
||||
return new NBTTagIntArray(nbtList.stream().mapToInt(i -> ((NBTTagInt)i).func_150287_d() ).toArray());
|
||||
return new NBTTagIntArray(nbtList.stream()
|
||||
.mapToInt(i -> ((NBTTagInt) i).func_150287_d())
|
||||
.toArray());
|
||||
} else if (nbtList.stream().allMatch(n -> n instanceof NBTTagByte)) {
|
||||
return new NBTTagByteArray(toByteArray(nbtList.stream().mapToInt(i -> ((NBTTagInt)i).func_150287_d() )));
|
||||
return new NBTTagByteArray(
|
||||
toByteArray(nbtList.stream().mapToInt(i -> ((NBTTagInt) i).func_150287_d())));
|
||||
} else {
|
||||
NBTTagList nbtTagList = new NBTTagList();
|
||||
nbtList.forEach(nbtTagList::appendTag);
|
||||
|
||||
return nbtTagList;
|
||||
|
||||
}
|
||||
} else if (jsonElement instanceof JsonObject) {
|
||||
// NBTTagCompound
|
||||
@@ -130,12 +129,15 @@ public class NBTJson {
|
||||
}
|
||||
return nbtTagCompound;
|
||||
}
|
||||
|
||||
|
||||
throw new IllegalArgumentException("Unhandled element " + jsonElement);
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(IntStream stream) {
|
||||
return stream.collect(ByteArrayOutputStream::new, (baos, i) -> baos.write((byte) i), (baos1, baos2) -> baos1.write(baos2.toByteArray(), 0, baos2.size()))
|
||||
.toByteArray();
|
||||
return stream.collect(
|
||||
ByteArrayOutputStream::new,
|
||||
(baos, i) -> baos.write((byte) i),
|
||||
(baos1, baos2) -> baos1.write(baos2.toByteArray(), 0, baos2.size()))
|
||||
.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@ import java.lang.reflect.Field;
|
||||
*/
|
||||
public class ReflectionHelper {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, C> T getField(C o, String... names){
|
||||
public static <T, C> T getField(C o, String... names) {
|
||||
Field field = null;
|
||||
boolean flag = false;
|
||||
for(String name : names){
|
||||
for (String name : names) {
|
||||
try {
|
||||
field = o.getClass().getDeclaredField(name);
|
||||
} catch (NoSuchFieldException e) {
|
||||
@@ -20,10 +20,10 @@ public class ReflectionHelper {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if(!flag){
|
||||
StringBuilder buffer = new StringBuilder(
|
||||
"Field not found in class " + o.getClass().getCanonicalName() + ":");
|
||||
for(String s : names){
|
||||
if (!flag) {
|
||||
StringBuilder buffer =
|
||||
new StringBuilder("Field not found in class " + o.getClass().getCanonicalName() + ":");
|
||||
for (String s : names) {
|
||||
buffer.append(" ");
|
||||
buffer.append(s);
|
||||
}
|
||||
@@ -37,7 +37,6 @@ public class ReflectionHelper {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T, C> T get(C o, String name) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import static net.minecraft.client.resources.I18n.format;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
@@ -8,6 +10,21 @@ import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.BreakIterator;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.Tags;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
@@ -24,24 +41,6 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.BreakIterator;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static net.minecraft.client.resources.I18n.format;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 2016/6/25.
|
||||
@@ -50,20 +49,20 @@ import static net.minecraft.client.resources.I18n.format;
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Utilities {
|
||||
// FLOAT FORMATTING
|
||||
public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T', 'P'};
|
||||
public static DecimalFormat[] format = new DecimalFormat[]{new DecimalFormat("#."),
|
||||
new DecimalFormat("#.#"),
|
||||
new DecimalFormat("#.##"),
|
||||
new DecimalFormat("#.###"),
|
||||
new DecimalFormat("#.####")};
|
||||
public static char[] suffix = new char[] {'K', 'M', 'B', 'G', 'T', 'P'};
|
||||
public static DecimalFormat[] format = new DecimalFormat[] {
|
||||
new DecimalFormat("#."),
|
||||
new DecimalFormat("#.#"),
|
||||
new DecimalFormat("#.##"),
|
||||
new DecimalFormat("#.###"),
|
||||
new DecimalFormat("#.####")
|
||||
};
|
||||
|
||||
public static String cutNumber(float f, int size) {
|
||||
BiFunction<Float, Integer, String> form = (fl, len) -> format[len - 1 - (int) Math.log10(fl)].format(fl);
|
||||
int scale = (int) Math.log10(f) / 3;
|
||||
if (scale == 0)
|
||||
return form.apply(f, size);
|
||||
else
|
||||
return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1];
|
||||
if (scale == 0) return form.apply(f, size);
|
||||
else return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1];
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
@@ -80,8 +79,7 @@ public class Utilities {
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++)
|
||||
sb.append(s);
|
||||
for (int i = 0; i < n; i++) sb.append(s);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -90,7 +88,9 @@ public class Utilities {
|
||||
public static String getModName(Item item) {
|
||||
String name = getName(item);
|
||||
String id = name.substring(0, name.indexOf(":"));
|
||||
return id.equals("minecraft") ? "Minecraft" : Loader.instance().getIndexedModList().get(id).getName();
|
||||
return id.equals("minecraft")
|
||||
? "Minecraft"
|
||||
: Loader.instance().getIndexedModList().get(id).getName();
|
||||
}
|
||||
|
||||
public static String getName(Item item) {
|
||||
@@ -113,8 +113,7 @@ public class Utilities {
|
||||
*/
|
||||
public static String getModName(Fluid fluid) {
|
||||
String name = fluid.getName();
|
||||
if (name.equals("lava") || name.equals("water"))
|
||||
return "Minecraft";
|
||||
if (name.equals("lava") || name.equals("water")) return "Minecraft";
|
||||
else {
|
||||
IIcon icon = getFluidIcon(fluid);
|
||||
if (icon == null) {
|
||||
@@ -136,7 +135,6 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static IIcon getFluidIcon(Fluid fluid) {
|
||||
IIcon icon = fluid.getFlowingIcon();
|
||||
if (icon == null) {
|
||||
@@ -155,12 +153,12 @@ public class Utilities {
|
||||
|
||||
public static void addChatMessage(ChatMessage cm) {
|
||||
EntityClientPlayerMP player = Utilities.getPlayer();
|
||||
if (player != null)
|
||||
player.addChatMessage(new ChatComponentTranslation(cm.get()));
|
||||
if (player != null) player.addChatMessage(new ChatComponentTranslation(cm.get()));
|
||||
}
|
||||
|
||||
public enum ChatMessage {
|
||||
MAX_LOOP, RECIPE_TRANSFER_ERROR;
|
||||
MAX_LOOP,
|
||||
RECIPE_TRANSFER_ERROR;
|
||||
|
||||
private String get() {
|
||||
switch (this) {
|
||||
@@ -174,7 +172,6 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Relation<K, V> {
|
||||
public HashMap<Pair<K, K>, V> data = new HashMap<>();
|
||||
|
||||
@@ -187,8 +184,7 @@ public class Utilities {
|
||||
@Nullable
|
||||
public V get(K a, K b) {
|
||||
V ret = data.get(new Pair<>(a, b));
|
||||
if (ret == null)
|
||||
ret = data.get(new Pair<>(b, a));
|
||||
if (ret == null) ret = data.get(new Pair<>(b, a));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -198,8 +194,7 @@ public class Utilities {
|
||||
boolean running = false;
|
||||
|
||||
public void setState(boolean b) {
|
||||
if (!b && running)
|
||||
running = false;
|
||||
if (!b && running) running = false;
|
||||
if (b && !running) {
|
||||
running = true;
|
||||
time = System.currentTimeMillis();
|
||||
@@ -234,10 +229,8 @@ public class Utilities {
|
||||
|
||||
public Circulator move(int steps) {
|
||||
current += steps;
|
||||
if (current < 0)
|
||||
current += (total - current - 1) / total * total;
|
||||
else
|
||||
current = current % total;
|
||||
if (current < 0) current += (total - current - 1) / total * total;
|
||||
else current = current % total;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -246,10 +239,8 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public Circulator set(int index) {
|
||||
if (index >= 0 && index < total)
|
||||
current = index;
|
||||
else
|
||||
throw new RuntimeException(String.format("Expected: [0, %d), given: %d.", total, index));
|
||||
if (index >= 0 && index < total) current = index;
|
||||
else throw new RuntimeException(String.format("Expected: [0, %d), given: %d.", total, index));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -266,8 +257,7 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public ReversedIterator(ListIterator<T> i) {
|
||||
while (i.hasNext())
|
||||
i.next();
|
||||
while (i.hasNext()) i.next();
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
@@ -307,9 +297,15 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static List<String> wrap(String s, int width) {
|
||||
return new TextWrapper().wrap(s,
|
||||
ClientUtils.mc().getLanguageManager().getCurrentLanguage().getLanguageCode(),
|
||||
i -> TextWrapper.renderer.getCharWidth(i), width);
|
||||
return new TextWrapper()
|
||||
.wrap(
|
||||
s,
|
||||
ClientUtils.mc()
|
||||
.getLanguageManager()
|
||||
.getCurrentLanguage()
|
||||
.getLanguageCode(),
|
||||
i -> TextWrapper.renderer.getCharWidth(i),
|
||||
width);
|
||||
}
|
||||
|
||||
static class TextWrapper {
|
||||
@@ -323,11 +319,9 @@ public class Utilities {
|
||||
|
||||
private void cut() {
|
||||
char c = str.charAt(cursor);
|
||||
if (c == '\f')
|
||||
cursor++;
|
||||
if (c == '\f') cursor++;
|
||||
temp.add(str.substring(start, cursor));
|
||||
if (c == ' ' || c == ' ' || c == '\n')
|
||||
cursor++;
|
||||
if (c == ' ' || c == ' ' || c == '\n') cursor++;
|
||||
start = cursor;
|
||||
end = cursor;
|
||||
space = width;
|
||||
@@ -356,13 +350,10 @@ public class Utilities {
|
||||
for (cursor = end; cursor < i; cursor++) {
|
||||
char ch = str.charAt(cursor);
|
||||
section += func.apply(str.charAt(cursor));
|
||||
if (ch == '\n' || ch == '\f')
|
||||
cut();
|
||||
if (ch == '\n' || ch == '\f') cut();
|
||||
else if (section > space) {
|
||||
if (start == end)
|
||||
cut();
|
||||
else
|
||||
move();
|
||||
if (start == end) cut();
|
||||
else move();
|
||||
}
|
||||
}
|
||||
space -= section;
|
||||
@@ -390,12 +381,10 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public boolean push(T obj, boolean replace) {
|
||||
if (replace)
|
||||
data.pop();
|
||||
if (replace) data.pop();
|
||||
boolean ret = data.removeIf(t -> tester != null ? tester.test(t, obj) : t.equals(obj));
|
||||
data.addFirst(obj);
|
||||
if (data.size() > limit)
|
||||
data.removeLast();
|
||||
if (data.size() > limit) data.removeLast();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -462,12 +451,10 @@ public class Utilities {
|
||||
|
||||
public static Locale getLocaleFromString(String languageCode) {
|
||||
String[] parts = languageCode.split("_", -1);
|
||||
if (parts.length == 1)
|
||||
return new Locale(parts[0]);
|
||||
if (parts.length == 1) return new Locale(parts[0]);
|
||||
else if (parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#")))
|
||||
return new Locale(parts[0], parts[1]);
|
||||
else
|
||||
return new Locale(parts[0], parts[1], parts[2]);
|
||||
else return new Locale(parts[0], parts[1], parts[2]);
|
||||
}
|
||||
|
||||
public static String[] mergeStringArrays(String[]... arrays) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@@ -29,8 +27,7 @@ public class Version implements Comparable<Version> {
|
||||
success1 = false;
|
||||
} else {
|
||||
String[] versions = split[0].split("\\.");
|
||||
if (versions.length != 3)
|
||||
success1 = false;
|
||||
if (versions.length != 3) success1 = false;
|
||||
else {
|
||||
try {
|
||||
major = Integer.parseInt(versions[0]);
|
||||
@@ -53,12 +50,9 @@ public class Version implements Comparable<Version> {
|
||||
public int compareTo(Version o) {
|
||||
assert this.isSuccess();
|
||||
assert o.isSuccess();
|
||||
if (this.getMajor() != o.getMajor())
|
||||
return this.getMajor() < o.getMajor() ? -1 : 1;
|
||||
if (this.getMinor() != o.getMinor())
|
||||
return this.getMinor() < o.getMinor() ? -1 : 1;
|
||||
if (this.getPatch() != o.getPatch())
|
||||
return this.getPatch() < o.getPatch() ? -1 : 1;
|
||||
if (this.getMajor() != o.getMajor()) return this.getMajor() < o.getMajor() ? -1 : 1;
|
||||
if (this.getMinor() != o.getMinor()) return this.getMinor() < o.getMinor() ? -1 : 1;
|
||||
if (this.getPatch() != o.getPatch()) return this.getPatch() < o.getPatch() ? -1 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.utils.wrappers;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
@@ -19,8 +19,7 @@ public class Wrapper<T> {
|
||||
}
|
||||
|
||||
public Wrapper<T> push(@Nullable T value) {
|
||||
if (value != null && predicate.test(value))
|
||||
this.value = value;
|
||||
if (value != null && predicate.test(value)) this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -34,14 +33,12 @@ public class Wrapper<T> {
|
||||
}
|
||||
|
||||
public Wrapper<T> ifPresent(Consumer<T> c) {
|
||||
if (value != null)
|
||||
c.accept(value);
|
||||
if (value != null) c.accept(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper<T> ifPresentNot(Runnable r) {
|
||||
if (value == null)
|
||||
r.run();
|
||||
if (value == null) r.run();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Please use IDEA test instead Gradle. (In settings 'Gradle -> Run Tests Using')
|
||||
@@ -35,7 +34,6 @@ class VersionTest {
|
||||
assertEquals(new Version("2.0.0").compareTo(new Version("1.0.0")), 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void compareTo_withSameVersion_isEqual() {
|
||||
assertEquals(new Version("2.0.0").compareTo(new Version("2.0.0")), 0);
|
||||
@@ -56,4 +54,4 @@ class VersionTest {
|
||||
Version version = new Version("1.0.6c");
|
||||
assert !version.isSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user