mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: start records
This commit is contained in:
1 parent
aba34b6acd
commit
c5bda741a2
31 files changed
+305
-267
No files matched your search
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.client.config.GuiUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
|
||||
@@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.client.gui.drawables;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -5,15 +5,13 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
|
||||
@@ -10,7 +10,7 @@ import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WPage;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WPanel;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -4,7 +4,7 @@ import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
@@ -83,6 +83,8 @@ public class GuiRecipe extends WContainer {
|
||||
|
||||
|
||||
List<ILabel> raw = new ArrayList<>();
|
||||
|
||||
// input
|
||||
List<ItemStack> itemStacks = recipe.getIngredientStacks(recipeIndex).stream()
|
||||
.map((positionedStack) -> positionedStack.item).collect(Collectors.toList());
|
||||
|
||||
@@ -94,8 +96,9 @@ public class GuiRecipe extends WContainer {
|
||||
|
||||
buf.add(itemStacks);
|
||||
|
||||
// output
|
||||
ItemStack outputStack = recipe.getResultStack(recipeIndex).item;
|
||||
output.add(ILabel.CONVERTER_ITEM.toLabel(outputStack));
|
||||
merge.accept(output, ILabel.CONVERTER_ITEM.toLabel(outputStack));
|
||||
buf.add(Collections.singletonList(outputStack));
|
||||
|
||||
groupInput.setLabel(input, 0);
|
||||
|
||||
@@ -5,9 +5,9 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelOreDict;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.stream.Collectors;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PickerSimple extends IWPicker.Simple {
|
||||
/**
|
||||
* @param labels labels to be displayed for selection
|
||||
* @param labels label to be displayed for selection
|
||||
* @param l18nKey localization key for help string,
|
||||
* entire key should be "gui.l18nKey.help.tooltip"
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelUniversal;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelUniversal;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,143 +1,69 @@
|
||||
package me.towdium.jecalculation.core;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.function.TriConsumer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.Polyfill;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-10-6.
|
||||
*/
|
||||
public class Recipe {
|
||||
ItemStack[] output;
|
||||
ItemStack[] catalyst;
|
||||
ItemStack[] input;
|
||||
public static final String KEY_INPUT = "input";
|
||||
public static final String KEY_CATALYST = "catalyst";
|
||||
public static final String KEY_OUTPUT = "output";
|
||||
static final ILabel[] EMPTY_ARRAY = new ILabel[0];
|
||||
ILabel[] input;
|
||||
ILabel[] catalyst;
|
||||
ILabel[] output;
|
||||
|
||||
enum EnumStackIOType {
|
||||
OUTPUT, CATALYST, INPUT;
|
||||
|
||||
public int getLength() {
|
||||
switch (this) {
|
||||
case OUTPUT:
|
||||
return 4;
|
||||
case CATALYST:
|
||||
return 4;
|
||||
case INPUT:
|
||||
return 12;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public Recipe(NBTTagCompound nbt) {
|
||||
this(readNbtList(nbt.getTagList(KEY_INPUT, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
|
||||
}
|
||||
|
||||
public Recipe(ItemStack[] output, ItemStack[] catalyst, ItemStack[] input) {
|
||||
BiFunction<ItemStack[], Integer, Boolean> checkArray = (itemStackIn, amount) -> {
|
||||
if (itemStackIn.length != amount)
|
||||
return false;
|
||||
for (ItemStack itemStack : itemStackIn) {
|
||||
if (!ItemStackHelper.isItemStackJEC(itemStack))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
public Recipe(List<ILabel> input, List<ILabel> catalyst, List<ILabel> output) {
|
||||
this(input.toArray(EMPTY_ARRAY), catalyst.toArray(EMPTY_ARRAY), output.toArray(EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
public Recipe(ILabel[] input, ILabel[] catalyst, ILabel[] output) {
|
||||
BiFunction<ILabel[], Integer, ILabel[]> convert = (ls, i) -> {
|
||||
ILabel[] ret = new ILabel[i];
|
||||
if (ls.length > i) throw new RuntimeException("Too many labels");
|
||||
System.arraycopy(ls, 0, this.input, 0, Math.min(i, ls.length));
|
||||
return ret;
|
||||
};
|
||||
Function<ItemStack[], ItemStack[]> copyArray = itemStacks -> {
|
||||
ItemStack[] buffer = new ItemStack[itemStacks.length];
|
||||
int count = -1;
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
buffer[++count] = itemStack.copy();
|
||||
}
|
||||
return buffer;
|
||||
this.input = convert.apply(input, 16);
|
||||
this.catalyst = convert.apply(catalyst, 8);
|
||||
this.output = convert.apply(output, 8);
|
||||
}
|
||||
|
||||
static private List<ILabel> readNbtList(NBTTagList list) {
|
||||
return StreamSupport.stream(Polyfill.spliterator(list), false)
|
||||
.filter(n -> n instanceof NBTTagCompound)
|
||||
.map(n -> ILabel.DESERIALIZER.deserialize((NBTTagCompound) n))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
Function<ILabel[], NBTTagList> convert = (ls) -> {
|
||||
NBTTagList r = new NBTTagList();
|
||||
Arrays.stream(ls).forEach(l -> r.appendTag(ILabel.DESERIALIZER.serialize(l)));
|
||||
return r;
|
||||
};
|
||||
if (!checkArray.apply(output, 4) || !checkArray.apply(catalyst, 4) || !checkArray.apply(input, 12)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.output = copyArray.apply(output);
|
||||
this.catalyst = copyArray.apply(catalyst);
|
||||
this.input = copyArray.apply(input);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItemStackInput(ItemStack itemStack) {
|
||||
return getItemSack(input, itemStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItemStackCatalyst(ItemStack itemStack) {
|
||||
return getItemSack(catalyst, itemStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItemStackOutput(ItemStack itemStack) {
|
||||
return getItemSack(output, itemStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
ItemStack getItemSack(ItemStack[] itemStacks, ItemStack itemStackIn) {
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
if (ItemStackHelper.isTypeEqual(itemStack, itemStackIn)) {
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class IOUtl {
|
||||
public static Recipe fromByte(ByteBuf buf) {
|
||||
return fromContainer((enumStackIOType, integer) -> ByteBufUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
public static Recipe fromNbt(NBTTagCompound tagCompound) {
|
||||
return fromContainer((enumStackIOType, integer) -> {
|
||||
NBTTagCompound temp = tagCompound.getCompoundTag(String.valueOf(enumStackIOType.ordinal()));
|
||||
temp = temp.getCompoundTag(String.valueOf(integer));
|
||||
return ItemStack.loadItemStackFromNBT(temp);
|
||||
});
|
||||
}
|
||||
|
||||
public static void toByte(ByteBuf buf, Recipe recipe) {
|
||||
toContainer((enumStackIOType, integer, itemStack) -> ByteBufUtils.writeItemStack(buf, itemStack), recipe);
|
||||
}
|
||||
|
||||
public static void toNbt(Recipe recipe) {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
toContainer((enumStackIOType, integer, itemStack) -> {
|
||||
NBTTagCompound stackInfo = new NBTTagCompound();
|
||||
itemStack.writeToNBT(stackInfo);
|
||||
String temp = String.valueOf(enumStackIOType.ordinal());
|
||||
if (integer == 0) {
|
||||
tagCompound.setTag(temp, new NBTTagCompound());
|
||||
}
|
||||
tagCompound.getCompoundTag(temp).setTag(String.valueOf(integer), stackInfo);
|
||||
}, recipe);
|
||||
}
|
||||
|
||||
static Recipe fromContainer(BiFunction<EnumStackIOType, Integer, ItemStack> func) {
|
||||
Function<EnumStackIOType, ItemStack[]> readArray = (type) -> {
|
||||
int len = type.getLength();
|
||||
ItemStack[] buffer = new ItemStack[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
buffer[i] = func.apply(type, i);
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
return new Recipe(readArray.apply(EnumStackIOType.OUTPUT), readArray.apply(EnumStackIOType.CATALYST),
|
||||
readArray.apply(EnumStackIOType.INPUT));
|
||||
}
|
||||
|
||||
static void toContainer(TriConsumer<EnumStackIOType, Integer, ItemStack> func, Recipe recipe) {
|
||||
BiConsumer<EnumStackIOType, ItemStack[]> writeArray = ((type, itemStacks) -> {
|
||||
int len = type.getLength();
|
||||
for (int i = 0; i < len; i++) {
|
||||
func.accept(type, i, itemStacks[i]);
|
||||
}
|
||||
});
|
||||
writeArray.accept(EnumStackIOType.OUTPUT, recipe.output);
|
||||
writeArray.accept(EnumStackIOType.CATALYST, recipe.catalyst);
|
||||
writeArray.accept(EnumStackIOType.INPUT, recipe.input);
|
||||
}
|
||||
ret.setTag(KEY_INPUT, convert.apply(input));
|
||||
ret.setTag(KEY_CATALYST, convert.apply(catalyst));
|
||||
ret.setTag(KEY_OUTPUT, convert.apply(output));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package me.towdium.jecalculation.core;
|
||||
|
||||
import me.towdium.jecalculation.polyfill.Polyfill;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-10-6.
|
||||
*/
|
||||
public class Record {
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
|
||||
ArrayList<Pair<String, ArrayList<Recipe>>> record = new ArrayList<>();
|
||||
HashMap<String, Integer> index = new HashMap<>();
|
||||
|
||||
public Record(NBTTagList nbt) {
|
||||
StreamSupport.stream(Polyfill.spliterator(nbt), false).filter(g -> g instanceof NBTTagCompound).forEach(g -> {
|
||||
NBTTagCompound group = (NBTTagCompound) g;
|
||||
String name = group.getString(KEY_NAME);
|
||||
NBTTagList recipes = group.getTagList(KEY_CONTENT, 10);
|
||||
StreamSupport.stream(Polyfill.spliterator(recipes), false).filter(r -> r instanceof NBTTagCompound)
|
||||
.map(r -> (NBTTagCompound) r).forEach(r -> add(name, new Recipe(r)));
|
||||
});
|
||||
}
|
||||
|
||||
public void add(String group, Recipe recipe) {
|
||||
Integer i = index.get(group);
|
||||
if (i == null) {
|
||||
record.add(new Pair<>(group, new ArrayList<>()));
|
||||
i = record.size() - 1;
|
||||
}
|
||||
record.get(i).two.add(recipe);
|
||||
}
|
||||
|
||||
public void set(String group, int index, Recipe recipe) {
|
||||
Integer i = this.index.get(group);
|
||||
if (i == null) throw new RuntimeException("Group not found: " + group + ".");
|
||||
record.get(i).two.set(index, recipe);
|
||||
}
|
||||
|
||||
public void foreach(BiConsumer<String, List<Recipe>> consumer) {
|
||||
record.forEach(p -> consumer.accept(p.one, p.two));
|
||||
}
|
||||
|
||||
public NBTTagList serialize() {
|
||||
NBTTagList ret = new NBTTagList();
|
||||
foreach((n, rs) -> {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString(KEY_NAME, n);
|
||||
NBTTagList l = new NBTTagList();
|
||||
rs.forEach(r -> l.appendTag(r.serialize()));
|
||||
nbt.setTag(KEY_CONTENT, l);
|
||||
ret.appendTag(nbt);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
+16
-8
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.core.labels;
|
||||
package me.towdium.jecalculation.core.label;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -7,19 +7,19 @@ import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerSimple;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerUniversal;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelItemStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelUniversal;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelFluidStack;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelItemStack;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.core.label.labels.LabelUniversal;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -29,6 +29,7 @@ import java.util.stream.Collectors;
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface ILabel {
|
||||
RegistryMerger MERGER = RegistryMerger.INSTANCE;
|
||||
RegistryDeserializer DESERIALIZER = RegistryDeserializer.INSTANCE;
|
||||
@@ -140,7 +141,7 @@ public interface ILabel {
|
||||
Optional<ILabel> ret = functions.get(ILabel.getIdentifier(a), ILabel.getIdentifier(b))
|
||||
.orElse((x, y, f) -> Optional.empty()).merge(a, b, add);
|
||||
if (ret.isPresent() && (ret.get() == a || ret.get() == b))
|
||||
throw new RuntimeException("Merger should not modify the given labels.");
|
||||
throw new RuntimeException("Merger should not modify the given label.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -197,12 +198,19 @@ public interface ILabel {
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
public ILabel deserialization(NBTTagCompound nbt) {
|
||||
public ILabel deserialize(NBTTagCompound nbt) {
|
||||
String s = nbt.getString(KEY_IDENTIFIER);
|
||||
ILabel e = idToData.get(s).apply(nbt.getCompoundTag(KEY_CONTENT));
|
||||
if (e != ILabel.EMPTY) return e;
|
||||
else throw new RuntimeException("Fail to deserialize label type: " + s);
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize(ILabel label) {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setString(KEY_CONTENT, ILabel.getIdentifier(label));
|
||||
ret.setTag(KEY_CONTENT, label.toNBTTagCompound());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RegistryConverter<T> {
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
package me.towdium.jecalculation.core.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
package me.towdium.jecalculation.core.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
+2
-3
@@ -1,12 +1,11 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
package me.towdium.jecalculation.core.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WText;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
package me.towdium.jecalculation.core.label.labels;
|
||||
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
package me.towdium.jecalculation.core.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -29,6 +29,7 @@ public class InputEventHandler {
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onMouseClick(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if (event.gui instanceof JecGui) {
|
||||
JustEnoughCalculation.logger.info("on mouse click in gui screen event");
|
||||
JecGui gui = (JecGui) event.gui;
|
||||
event.setCanceled(gui.handleMouseEvent());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package me.towdium.jecalculation.item;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class ItemCalculator extends Item {
|
||||
public static ItemCalculator INSTANCE = new ItemCalculator();
|
||||
|
||||
public static final String CRAFTING_NAME = "item_calculator_crafting";
|
||||
public static final String MATH_NAME = "item_calculator_math";
|
||||
|
||||
private IIcon mathIcon;
|
||||
|
||||
private ItemCalculator() {
|
||||
setHasSubtypes(true);
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(CreativeTabs.tabTools);
|
||||
setUnlocalizedName("item_calculator");
|
||||
setMaxDamage(1);
|
||||
}
|
||||
|
||||
public static void registerItems() {
|
||||
GameRegistry.registerItem(INSTANCE, INSTANCE.getUnlocalizedName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List items) {
|
||||
if (tab == CreativeTabs.tabAllSearch || tab == CreativeTabs.tabTools) {
|
||||
items.add(new ItemStack(this, 1, 0));
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int meta) {
|
||||
return meta == 1 ? this.mathIcon : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
this.itemIcon = iconRegister.registerIcon(JustEnoughCalculation.Reference.MODID + ":" + CRAFTING_NAME);
|
||||
this.mathIcon = iconRegister.registerIcon(JustEnoughCalculation.Reference.MODID + ":" + MATH_NAME);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
static void setModelLocation(Item item, int meta, String id) {
|
||||
item.setTextureName(JustEnoughCalculation.Reference.MODID + ":" + id);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
static void setModelLocation(Item item) {
|
||||
if (item.getHasSubtypes()) {
|
||||
NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
item.getSubItems(item, CreativeTabs.tabAllSearch, stacks);
|
||||
for (ItemStack s : stacks) {
|
||||
setModelLocation(item, s.getItemDamage(), item.getUnlocalizedName(s).substring(5));
|
||||
}
|
||||
} else {
|
||||
setModelLocation(item, 0, item.getUnlocalizedName().substring(5));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
switch (stack.getItemDamage()) {
|
||||
case 0:
|
||||
return "item.item_calculator_crafting";
|
||||
case 1:
|
||||
return "item.item_calculator_math";
|
||||
default:
|
||||
throw new IllegalPositionException(String.format("item damage %d", stack.getItemDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World worldIn, EntityPlayer playerIn) {
|
||||
if (JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER)
|
||||
JustEnoughCalculation.proxy.displayCalculator();
|
||||
return super.onItemRightClick(itemStack, worldIn, playerIn);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package me.towdium.jecalculation.item;
|
||||
|
||||
import me.towdium.jecalculation.item.items.ItemCalculator;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Items {
|
||||
public static final ArrayList<JecaItem> items;
|
||||
public static final ItemCalculator itemCalculator = new ItemCalculator();
|
||||
|
||||
static {
|
||||
items = new ArrayList<>();
|
||||
items.add(itemCalculator);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package me.towdium.jecalculation.item;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class JecaItem extends Item {
|
||||
public static final String CRAFTING_NAME = "item_calculator_crafting";
|
||||
public static final String MATH_NAME = "item_calculator_math";
|
||||
|
||||
public String getUnlocalizedName(int meta) {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
return getUnlocalizedName(stack.getItemDamage());
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package me.towdium.jecalculation.item.items;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.item.JecaItem;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemCalculator extends JecaItem {
|
||||
public ItemCalculator() {
|
||||
setHasSubtypes(true);
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(CreativeTabs.tabTools);
|
||||
setUnlocalizedName("item_calculator");
|
||||
setTextureName(JustEnoughCalculation.Reference.MODID + ":" + CRAFTING_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(int meta) {
|
||||
switch (meta) {
|
||||
case 0:
|
||||
return "item.item_calculator_crafting";
|
||||
case 1:
|
||||
return "item.item_calculator_math";
|
||||
default:
|
||||
throw new IllegalPositionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List items) {
|
||||
if (tab == CreativeTabs.tabAllSearch || tab == CreativeTabs.tabTools) {
|
||||
items.add(new ItemStack(this, 1, 0));
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) {
|
||||
if (JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER) {
|
||||
JecGui.displayGui(new GuiCalculator());
|
||||
}
|
||||
return super.onItemRightClick(p_77659_1_, p_77659_2_, p_77659_3_);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,14 @@ package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiRecipe;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class JecaOverlayHandler implements IOverlayHandler {
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.core.label.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class NEIPlugin {
|
||||
|
||||
@@ -2,6 +2,8 @@ package me.towdium.jecalculation.network;
|
||||
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.command.JecaCommand;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
@@ -17,6 +19,7 @@ public class ProxyClient extends ProxyCommon{
|
||||
super.initPost();
|
||||
JustEnoughCalculation.logger.info("client proxy init post");
|
||||
ClientCommandHandler.instance.registerCommand(new JecaCommand());
|
||||
new JecGui(null, new GuiCalculator());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,4 +28,10 @@ public class ProxyClient extends ProxyCommon{
|
||||
JustEnoughCalculation.logger.info("client proxy init");
|
||||
ClientRegistry.registerKeyBinding(keyOpenGui);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void displayCalculator() {
|
||||
JecGui.displayGui(new GuiCalculator());
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,12 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.event.Handlers;
|
||||
import me.towdium.jecalculation.item.Items;
|
||||
import me.towdium.jecalculation.item.JecaItem;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
|
||||
public class ProxyCommon {
|
||||
public void initPre() {
|
||||
JustEnoughCalculation.logger.info("common proxy init pre");
|
||||
for (JecaItem item : Items.items) {
|
||||
GameRegistry.registerItem(item, item.getUnlocalizedName());
|
||||
}
|
||||
GameRegistry.registerItem(ItemCalculator.INSTANCE, ItemCalculator.INSTANCE.getUnlocalizedName());
|
||||
Handlers.handlers.forEach(FMLCommonHandler.instance().bus()::register);
|
||||
}
|
||||
|
||||
@@ -24,4 +20,7 @@ public class ProxyCommon {
|
||||
public void initPost() {
|
||||
JustEnoughCalculation.logger.info("common proxy init post");
|
||||
}
|
||||
|
||||
public void displayCalculator() {
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package me.towdium.jecalculation.polyfill;
|
||||
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.ReflectionHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
|
||||
public class Polyfill {
|
||||
/**
|
||||
@@ -26,4 +33,9 @@ public class Polyfill {
|
||||
}
|
||||
}
|
||||
|
||||
public static Spliterator<NBTBase> spliterator(NBTTagList list) {
|
||||
List tagList = (List) ReflectionHelper.get(list, "tagList");
|
||||
return Spliterators.spliteratorUnknownSize(((List<NBTBase>)tagList).iterator(), 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,4 +5,11 @@ package me.towdium.jecalculation.utils;
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
public class IllegalPositionException extends RuntimeException {
|
||||
public IllegalPositionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IllegalPositionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user