chore: update

This commit is contained in:
Discreater committed 2021-05-01 01:00:16 +08:00
1 parent 37a94075c7
commit 5d86a1e2ad
16 files changed
+191 -55

No files matched your search

@@ -2,16 +2,12 @@ package me.towdium.jecalculation.data.label;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.labels.*;
import me.towdium.jecalculation.gui.IWPicker;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.guis.pickers.PickerSimple;
import me.towdium.jecalculation.gui.guis.pickers.PickerUniversal;
import me.towdium.jecalculation.data.label.labels.LFluidStack;
import me.towdium.jecalculation.data.label.labels.LItemStack;
import me.towdium.jecalculation.data.label.labels.LOreDict;
import me.towdium.jecalculation.data.label.labels.LString;
import me.towdium.jecalculation.gui.guis.pickers.PickerPlaceholder;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.ItemStackHelper;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.Relation;
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
@@ -60,7 +56,7 @@ public interface ILabel {
CONVERTER.register(LOreDict::guess);
EDITOR.register(PickerSimple.FluidStack::new, "fluid_stack", new LFluidStack(1000, FluidRegistry.WATER));
EDITOR.register(PickerSimple.OreDict::new, "ore_dict", new LOreDict("ingotIron"));
EDITOR.register(PickerUniversal::new, "string", new LString("example", 1));
EDITOR.register(PickerPlaceholder::new, "placeholder", new LPlaceholder("example", 1, true));
MERGER.register("itemStack", "itemStack", LItemStack::merge);
MERGER.register("oreDict", "oreDict", LOreDict::mergeOreDict);
}
@@ -69,7 +65,7 @@ public interface ILabel {
DESERIALIZER.register(LFluidStack.IDENTIFIER, LFluidStack::new);
DESERIALIZER.register(LItemStack.IDENTIFIER, LItemStack::new);
DESERIALIZER.register(LOreDict.IDENTIFIER, LOreDict::new);
DESERIALIZER.register(LString.IDENTIFIER, LString::new);
DESERIALIZER.register(LPlaceholder.IDENTIFIER, LPlaceholder::new);
DESERIALIZER.register(LEmpty.IDENTIFIER, i -> EMPTY);
}
@@ -0,0 +1,108 @@
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.stream.Collectors;
/**
* Author: towdium
* Date: 17-9-28.
*/
@ParametersAreNonnullByDefault
public class LPlaceholder extends ILabel.Impl {
public static final String KEY_NAME = "name";
public static final String IDENTIFIER = "string";
static Utilities.Recent<LPlaceholder> recentClient = new Utilities.Recent<>(100);
static Utilities.Recent<LPlaceholder> recentServer = new Utilities.Recent<>(100);
String name;
public LPlaceholder(NBTTagCompound tag) {
this(tag.getString(KEY_NAME), tag.getInteger(KEY_AMOUNT));
}
public LPlaceholder(String name, int amount) {
this(name, amount, false);
}
public LPlaceholder(String name, int amount, boolean silent) {
super(amount);
this.name = name;
if (!silent) getRecord().push(new LPlaceholder(name, 1, true));
}
public LPlaceholder(LPlaceholder label) {
super(label);
name = label.name;
}
public static void onLogOut() {
recentServer.clear();
}
@Override
public String getIdentifier() {
return "string";
}
public static List<ILabel> getRecent() {
return getRecord().toList().stream().map(LPlaceholder::copy).collect(Collectors.toList());
}
private static Utilities.Recent<LPlaceholder> getRecord() {
return JustEnoughCalculation.side == JustEnoughCalculation.enumSide.CLIENT
? recentClient : recentServer;
}
@Override
public NBTTagCompound toNBTTagCompound() {
NBTTagCompound nbt = super.toNBTTagCompound();
nbt.setString(KEY_NAME, name);
return nbt;
}
@Override
@SideOnly(Side.CLIENT)
public void drawLabel(JecaGui gui) {
gui.drawResource(Resource.LBL_UNIV_B, 0, 0);
gui.drawResource(Resource.LBL_UNIV_F, 0, 0, (name.hashCode() * 0x131723) & 0xFFFFFF);
}
@Override
public int hashCode() {
return name.hashCode() ^ amount;
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.I18n.format("label.placeholder.name", name);
}
@Override
public boolean matches(Object l) {
return l instanceof LPlaceholder && name.equals(((LPlaceholder) l).name);
}
@Override
public ILabel copy() {
return new LPlaceholder(this);
}
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
return existing;
}
}
@@ -1,15 +1,26 @@
package me.towdium.jecalculation.event;
import me.towdium.jecalculation.event.handlers.InputEventHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import me.towdium.jecalculation.event.handlers.EBEventHandler;
import me.towdium.jecalculation.event.handlers.FMLBusEventHandler;
import net.minecraftforge.common.MinecraftForge;
import java.util.ArrayList;
public class Handlers {
public static final ArrayList<Object> handlers;
public static final ArrayList<Object> fmlHandlers;
public static final ArrayList<Object> ebHandlers;
static {
handlers = new ArrayList<>();
fmlHandlers = new ArrayList<>();
fmlHandlers.add(new FMLBusEventHandler());
handlers.add(new InputEventHandler());
ebHandlers = new ArrayList<>();
ebHandlers.add(new EBEventHandler());
}
public static void register() {
Handlers.fmlHandlers.forEach(FMLCommonHandler.instance().bus()::register);
Handlers.ebHandlers.forEach(MinecraftForge.EVENT_BUS::register);
}
}
@@ -0,0 +1,25 @@
package me.towdium.jecalculation.event.handlers;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraftforge.client.event.GuiScreenEvent;
/**
* register to MinecraftForge.EVENT_BUS
*/
public class EBEventHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onMouseClick(GuiScreenEvent.ActionPerformedEvent.Pre event) {
JustEnoughCalculation.logger.info("on gui screen event action performed event pre");
if (event.gui instanceof JecaGui) {
JustEnoughCalculation.logger.info("on mouse click in gui screen event");
JecaGui gui = (JecaGui) event.gui;
event.setCanceled(gui.handleMouseEvent());
}
}
}
@@ -1,6 +1,5 @@
package me.towdium.jecalculation.event.handlers;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
@@ -8,36 +7,27 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.guis.GuiCalculator;
import me.towdium.jecalculation.network.ClientHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.client.event.GuiScreenEvent;
/**
* Author: towdium
* Date: 8/13/17.
*/
@SuppressWarnings("unused")
public class InputEventHandler {
public class FMLBusEventHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled = true)
public void onKey(InputEvent.KeyInputEvent event) {
if (ClientHandler.keyOpenGui.isPressed()) {
if (JustEnoughCalculation.side == JustEnoughCalculation.enumSide.CLIENT) JecaGui.displayGui(new GuiCalculator());
else Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("chat.server_mode"));
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onMouseClick(GuiScreenEvent.ActionPerformedEvent.Pre event) {
JustEnoughCalculation.logger.info("on gui screen event action performed event pre");
if (event.gui instanceof JecaGui) {
JustEnoughCalculation.logger.info("on mouse click in gui screen event");
JecaGui gui = (JecaGui) event.gui;
event.setCanceled(gui.handleMouseEvent());
if (JustEnoughCalculation.side == JustEnoughCalculation.enumSide.CLIENT)
JecaGui.displayGui(new GuiCalculator());
else
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("chat.server_mode"));
}
}
@@ -45,7 +35,7 @@ public class InputEventHandler {
public void onLogout(PlayerEvent.PlayerLoggedOutEvent event) {
JustEnoughCalculation.logger.info("on log out event");
Controller.writeToLocal();;
LPlaceholder.onLogOut();
}
}
@@ -18,7 +18,7 @@ import java.util.function.Consumer;
public interface IWPicker extends IWidget {
IWPicker setCallback(Consumer<ILabel> callback);
class Simple extends WContainer implements IWPicker {
class Impl extends WContainer implements IWPicker {
protected Consumer<ILabel> callback;
@Override
@@ -71,6 +71,8 @@ public class Resource {
public static final Resource ICN_STACK_F = new Resource(98, 28, 14, 14);
public static final Resource ICN_TEXT_N = new Resource(112, 42, 14, 14);
public static final Resource ICN_TEXT_F = new Resource(112, 28, 14, 14);
public static final Resource ICN_MULTI_N = new Resource(126, 42, 14, 14);
public static final Resource ICN_MULTI_F = new Resource(126, 28, 14, 14);
public static final Resource LBL_ORE_DICT = new Resource(0, 56, 16, 16);
public static final Resource LBL_FLUID = new Resource(16, 56, 16, 16);
public static final Resource LBL_UNIV_B = new Resource(32, 56, 16, 16);
@@ -16,7 +16,7 @@ import java.util.List;
*/
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiDisambiguation extends IWPicker.Simple {
public class GuiDisambiguation extends IWPicker.Impl {
protected WLabelScroll lsUp;
protected WLabelScroll lsDown;
protected WSwitcher switcher;
@@ -2,14 +2,13 @@ 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.IWPicker;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.drawables.*;
import me.towdium.jecalculation.data.label.labels.LString;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
/**
* Author: towdium
@@ -17,22 +16,22 @@ import java.util.ArrayList;
*/
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerUniversal extends IWPicker.Simple {
public PickerUniversal() {
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.enumMode.PICKER, true).setLabels(new ArrayList<>());
WTextField search = new WTextField(25, 45, 90);
WTextField create = new WTextField(25, 7, 70);
public class PickerPlaceholder extends IWPicker.Impl {
public PickerPlaceholder() {
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.enumMode.PICKER, true)
.setLabels(LPlaceholder.getRecent());
WTextField search = new WTextField(26, 45, 90);
WTextField create = new WTextField(26, 7, 69);
create.setLsnrText(s -> create.setColor(s.equals("") ? JecaGui.COLOR_TEXT_RED : JecaGui.COLOR_TEXT_WHITE));
add(new WSearch(l -> callback.accept(l), search, scroll));
add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_universal.help_search"));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_universal.help_create"));
add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_universal.text_search"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_universal.text_create"));
add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_placeholder.help_search"));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_placeholder.help_create"));
add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_placeholder.text_search"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_placeholder.text_create"));
add(new WLine(36));
add(new WButtonIcon(95, 7, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F).setListenerLeft(() -> {
if (!create.getText().equals("")) callback.accept(new LString(create.getText(), 1));
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
}));
add(create);
}
}
@@ -22,7 +22,7 @@ import java.util.stream.Collectors;
*/
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerSimple extends IWPicker.Simple {
public class PickerSimple extends IWPicker.Impl {
/**
* @param labels label to be displayed for selection
* @param l18nKey localization key for help string,
@@ -30,7 +30,7 @@ public class PickerSimple extends IWPicker.Simple {
*/
public PickerSimple(List<ILabel> labels, String l18nKey) {
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true).setLabels(labels);
WTextField tf = new WTextField(25, 7, 90);
WTextField tf = new WTextField(26, 7, 90);
add(new WSearch(l -> callback.accept(l), tf, ls));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, l18nKey + ".help"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, l18nKey + ".text"));
@@ -1,11 +1,10 @@
package me.towdium.jecalculation.network;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.event.Handlers;
import me.towdium.jecalculation.command.JecaCommand;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.event.Handlers;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
@@ -13,11 +12,10 @@ import net.minecraftforge.client.ClientCommandHandler;
import org.lwjgl.input.Keyboard;
public class ClientHandler {
public static final KeyBinding keyOpenGui =
new KeyBinding("key.open_gui", Keyboard.KEY_NONE, "key.category");
public static final KeyBinding keyOpenGui = new KeyBinding("key.open_gui", Keyboard.KEY_NONE, "key.category");
public void initPre() {
Handlers.handlers.forEach(FMLCommonHandler.instance().bus()::register);
Handlers.register();
}
public void initPost() {
@@ -9,6 +9,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated
public @interface Event {
/**
@@ -16,6 +17,7 @@ public @interface Event {
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated
@interface EventBusSubscriber {
Side[] value() default {Side.CLIENT, Side.SERVER};
@@ -15,6 +15,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@Deprecated
public class Loader {
public static void subscribeToEventBus() {
@@ -271,5 +271,9 @@ public class Utilities {
//noinspection unchecked
return (List<T>) data.clone();
}
public void clear() {
data.clear();
}
}
}