From 5baeb82eb71b914f90e92b7a420a49e8bcfe21f5 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 29 Jan 2023 21:50:25 -0800 Subject: [PATCH] [ci skip] spotlessApply with the new settings --- src/main/java/wanion/lib/Reference.java | 24 ++- src/main/java/wanion/lib/WanionLib.java | 89 +++++---- .../wanion/lib/client/ClientTickHandler.java | 52 +++--- .../lib/client/animation/Animation.java | 47 +++-- .../client/animation/ComplexAnimation.java | 50 +++-- .../animation/ComplexHalfAnimation.java | 42 ++--- .../lib/client/animation/SimpleAnimation.java | 42 ++--- .../client/animation/SimpleHalfAnimation.java | 42 ++--- .../java/wanion/lib/common/Dependencies.java | 116 ++++++------ .../java/wanion/lib/common/FixedSizeList.java | 154 +++++++-------- .../java/wanion/lib/common/IRemovable.java | 19 +- .../java/wanion/lib/common/Instantiator.java | 18 +- src/main/java/wanion/lib/common/MetaItem.java | 167 ++++++++--------- .../wanion/lib/common/MineTweakerHelper.java | 97 +++++----- src/main/java/wanion/lib/common/Util.java | 70 +++---- .../wanion/lib/module/AbstractModule.java | 157 ++++++++-------- .../lib/module/AbstractModuleThread.java | 23 +-- .../java/wanion/lib/module/LoadStage.java | 46 ++--- .../java/wanion/lib/module/ModuleHandler.java | 65 +++---- .../wanion/lib/module/SpecifiedLoadStage.java | 21 +-- .../java/wanion/lib/recipe/RecipeHelper.java | 155 +++++++--------- .../advanced/AbstractRecipeRegistry.java | 175 ++++++++---------- .../lib/recipe/advanced/IAdvancedRecipe.java | 33 ++-- 23 files changed, 787 insertions(+), 917 deletions(-) diff --git a/src/main/java/wanion/lib/Reference.java b/src/main/java/wanion/lib/Reference.java index 25fb0cb..29ffd3f 100644 --- a/src/main/java/wanion/lib/Reference.java +++ b/src/main/java/wanion/lib/Reference.java @@ -1,19 +1,17 @@ package wanion.lib; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -public final class Reference -{ - public static final String MOD_ID = "wanionlib"; - public static final String MOD_NAME = "WanionLib"; - public static final String MOD_VERSION = "GRADLETOKEN_VERSION"; - public static final String ACCEPTED_MINECRAFT = "[1.7.10]"; +public final class Reference { - private Reference() {} -} \ No newline at end of file + public static final String MOD_ID = "wanionlib"; + public static final String MOD_NAME = "WanionLib"; + public static final String MOD_VERSION = "GRADLETOKEN_VERSION"; + public static final String ACCEPTED_MINECRAFT = "[1.7.10]"; + + private Reference() {} +} diff --git a/src/main/java/wanion/lib/WanionLib.java b/src/main/java/wanion/lib/WanionLib.java index 795580d..f197fac 100644 --- a/src/main/java/wanion/lib/WanionLib.java +++ b/src/main/java/wanion/lib/WanionLib.java @@ -1,67 +1,62 @@ package wanion.lib; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ +import static wanion.lib.Reference.*; + +import java.util.Map; + +import org.apache.logging.log4j.Logger; + +import wanion.lib.client.ClientTickHandler; +import wanion.lib.common.Dependencies; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import org.apache.logging.log4j.Logger; -import wanion.lib.client.ClientTickHandler; -import wanion.lib.common.Dependencies; - -import java.util.Map; - -import static wanion.lib.Reference.*; @Mod(modid = MOD_ID, name = MOD_NAME, version = MOD_VERSION, acceptedMinecraftVersions = ACCEPTED_MINECRAFT) -public final class WanionLib -{ - @Mod.Instance(MOD_ID) - public static WanionLib instance; +public final class WanionLib { - private Dependencies dependencies = new Dependencies<>(); - private Logger logger; + @Mod.Instance(MOD_ID) + public static WanionLib instance; - public static Dependencies getDependencies() - { - return instance.dependencies; - } + private Dependencies dependencies = new Dependencies<>(); + private Logger logger; - public static Logger getLogger() - { - return instance.logger; - } + public static Dependencies getDependencies() { + return instance.dependencies; + } - @SideOnly(Side.CLIENT) - public static ClientTickHandler getClientTickHandler() - { - return instance.dependencies.get(ClientTickHandler.class); - } + public static Logger getLogger() { + return instance.logger; + } - @Mod.EventHandler - public void preInit(final FMLPreInitializationEvent event) - { - logger = event.getModLog(); - } + @SideOnly(Side.CLIENT) + public static ClientTickHandler getClientTickHandler() { + return instance.dependencies.get(ClientTickHandler.class); + } - @Mod.EventHandler - public void loadComplete(final FMLLoadCompleteEvent event) - { - dependencies = null; - } + @Mod.EventHandler + public void preInit(final FMLPreInitializationEvent event) { + logger = event.getModLog(); + } - public boolean matchModVersions(final Map remoteVersions, final Side side) - { - return side == Side.CLIENT ? remoteVersions.containsKey(MOD_ID) : !remoteVersions.containsKey(MOD_ID) || remoteVersions.get(MOD_ID).equals(MOD_VERSION); - } + @Mod.EventHandler + public void loadComplete(final FMLLoadCompleteEvent event) { + dependencies = null; + } - public interface IDependency {} -} \ No newline at end of file + public boolean matchModVersions(final Map remoteVersions, final Side side) { + return side == Side.CLIENT ? remoteVersions.containsKey(MOD_ID) + : !remoteVersions.containsKey(MOD_ID) || remoteVersions.get(MOD_ID).equals(MOD_VERSION); + } + + public interface IDependency { + } +} diff --git a/src/main/java/wanion/lib/client/ClientTickHandler.java b/src/main/java/wanion/lib/client/ClientTickHandler.java index b252d3b..cff278a 100644 --- a/src/main/java/wanion/lib/client/ClientTickHandler.java +++ b/src/main/java/wanion/lib/client/ClientTickHandler.java @@ -1,43 +1,39 @@ package wanion.lib.client; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nonnull; + +import wanion.lib.WanionLib; +import wanion.lib.client.animation.Animation; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import wanion.lib.WanionLib; -import wanion.lib.client.animation.Animation; - -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.List; @SideOnly(Side.CLIENT) -public final class ClientTickHandler implements WanionLib.IDependency -{ - private final List registeredAnimations = new ArrayList<>(); +public final class ClientTickHandler implements WanionLib.IDependency { - private ClientTickHandler() - { - FMLCommonHandler.instance().bus().register(this); - } + private final List registeredAnimations = new ArrayList<>(); - public void registerAnimation(@Nonnull final Animation animation) - { - registeredAnimations.add(animation); - } + private ClientTickHandler() { + FMLCommonHandler.instance().bus().register(this); + } - @SubscribeEvent - public void tickEvent(final TickEvent.ClientTickEvent event) - { - registeredAnimations.forEach(Animation::updateAnimation); - } -} \ No newline at end of file + public void registerAnimation(@Nonnull final Animation animation) { + registeredAnimations.add(animation); + } + + @SubscribeEvent + public void tickEvent(final TickEvent.ClientTickEvent event) { + registeredAnimations.forEach(Animation::updateAnimation); + } +} diff --git a/src/main/java/wanion/lib/client/animation/Animation.java b/src/main/java/wanion/lib/client/animation/Animation.java index 93276d4..dae8f2c 100644 --- a/src/main/java/wanion/lib/client/animation/Animation.java +++ b/src/main/java/wanion/lib/client/animation/Animation.java @@ -1,36 +1,33 @@ package wanion.lib.client.animation; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.ResourceLocation; - import javax.annotation.Nonnull; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) -public abstract class Animation -{ - private final ResourceLocation[] frames; - protected final int lastFrameIndex; - protected int currentFrame = 0; +public abstract class Animation { - public Animation(@Nonnull final ResourceLocation[] frames) - { - if ((lastFrameIndex = (this.frames = frames).length) - 1 == -1) - throw new RuntimeException("What is an Animation with no frames?"); - } + private final ResourceLocation[] frames; + protected final int lastFrameIndex; + protected int currentFrame = 0; - public abstract void updateAnimation(); + public Animation(@Nonnull final ResourceLocation[] frames) { + if ((lastFrameIndex = (this.frames = frames).length) - 1 == -1) + throw new RuntimeException("What is an Animation with no frames?"); + } - public final ResourceLocation getCurrentFrame() - { - return frames[currentFrame]; - } -} \ No newline at end of file + public abstract void updateAnimation(); + + public final ResourceLocation getCurrentFrame() { + return frames[currentFrame]; + } +} diff --git a/src/main/java/wanion/lib/client/animation/ComplexAnimation.java b/src/main/java/wanion/lib/client/animation/ComplexAnimation.java index 0dce10a..492efee 100644 --- a/src/main/java/wanion/lib/client/animation/ComplexAnimation.java +++ b/src/main/java/wanion/lib/client/animation/ComplexAnimation.java @@ -1,37 +1,33 @@ package wanion.lib.client.animation; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.ResourceLocation; - import javax.annotation.Nonnull; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) -public class ComplexAnimation extends Animation -{ - private final int[] animationStages; - private final int lastStageIndex; - private int currentStage = 0; +public class ComplexAnimation extends Animation { - public ComplexAnimation(@Nonnull final ResourceLocation[] frames, final int[] animationStages) - { - super(frames); - lastStageIndex = (this.animationStages = animationStages).length - 1; - } + private final int[] animationStages; + private final int lastStageIndex; + private int currentStage = 0; - @Override - public void updateAnimation() - { - if (++currentStage > lastStageIndex) - currentStage = 0; - currentFrame = animationStages[currentStage]; - } -} \ No newline at end of file + public ComplexAnimation(@Nonnull final ResourceLocation[] frames, final int[] animationStages) { + super(frames); + lastStageIndex = (this.animationStages = animationStages).length - 1; + } + + @Override + public void updateAnimation() { + if (++currentStage > lastStageIndex) currentStage = 0; + currentFrame = animationStages[currentStage]; + } +} diff --git a/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java b/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java index 89afa09..a122240 100644 --- a/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java +++ b/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java @@ -1,33 +1,29 @@ package wanion.lib.client.animation; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.ResourceLocation; - import javax.annotation.Nonnull; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) -public final class ComplexHalfAnimation extends ComplexAnimation -{ - private boolean half; +public final class ComplexHalfAnimation extends ComplexAnimation { - public ComplexHalfAnimation(@Nonnull final ResourceLocation[] frames, final int[] stages) - { - super(frames, stages); - } + private boolean half; - @Override - public void updateAnimation() - { - if (half ^= true) - super.updateAnimation(); - } -} \ No newline at end of file + public ComplexHalfAnimation(@Nonnull final ResourceLocation[] frames, final int[] stages) { + super(frames, stages); + } + + @Override + public void updateAnimation() { + if (half ^= true) super.updateAnimation(); + } +} diff --git a/src/main/java/wanion/lib/client/animation/SimpleAnimation.java b/src/main/java/wanion/lib/client/animation/SimpleAnimation.java index f13d82d..cc47bae 100644 --- a/src/main/java/wanion/lib/client/animation/SimpleAnimation.java +++ b/src/main/java/wanion/lib/client/animation/SimpleAnimation.java @@ -1,31 +1,27 @@ package wanion.lib.client.animation; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.ResourceLocation; - import javax.annotation.Nonnull; -@SideOnly(Side.CLIENT) -public class SimpleAnimation extends Animation -{ - public SimpleAnimation(@Nonnull final ResourceLocation[] frames) - { - super(frames); - } +import net.minecraft.util.ResourceLocation; - @Override - public void updateAnimation() - { - if (++currentFrame > lastFrameIndex) - currentFrame = 0; - } -} \ No newline at end of file +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class SimpleAnimation extends Animation { + + public SimpleAnimation(@Nonnull final ResourceLocation[] frames) { + super(frames); + } + + @Override + public void updateAnimation() { + if (++currentFrame > lastFrameIndex) currentFrame = 0; + } +} diff --git a/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java b/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java index 4a7d7ee..145f4ce 100644 --- a/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java +++ b/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java @@ -1,33 +1,29 @@ package wanion.lib.client.animation; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.ResourceLocation; - import javax.annotation.Nonnull; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) -public final class SimpleHalfAnimation extends SimpleAnimation -{ - private boolean half; +public final class SimpleHalfAnimation extends SimpleAnimation { - public SimpleHalfAnimation(@Nonnull final ResourceLocation[] frames) - { - super(frames); - } + private boolean half; - @Override - public void updateAnimation() - { - if (half ^= true) - super.updateAnimation(); - } -} \ No newline at end of file + public SimpleHalfAnimation(@Nonnull final ResourceLocation[] frames) { + super(frames); + } + + @Override + public void updateAnimation() { + if (half ^= true) super.updateAnimation(); + } +} diff --git a/src/main/java/wanion/lib/common/Dependencies.java b/src/main/java/wanion/lib/common/Dependencies.java index 33d8e81..d29b4ea 100644 --- a/src/main/java/wanion/lib/common/Dependencies.java +++ b/src/main/java/wanion/lib/common/Dependencies.java @@ -1,82 +1,74 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import javax.annotation.Nonnull; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; import java.util.IdentityHashMap; import java.util.Map; +import javax.annotation.Nonnull; + @SuppressWarnings("unchecked") -public class Dependencies -{ - private final Map dependencies = new IdentityHashMap<>(); - private final Map> dependenciesWatchers = new IdentityHashMap<>(); +public class Dependencies { - public final void add(final Class typeClass) - { - if (dependencies.containsKey(typeClass)) - return; - final DependenceWatcher dependenceWatcher = dependenciesWatchers.get(typeClass); - if (dependenceWatcher != null) { - add(dependenceWatcher.instantiate()); - return; - } - try { - final Constructor constructor = typeClass.getDeclaredConstructor(); - constructor.setAccessible(true); - add((I) constructor.newInstance()); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - } + private final Map dependencies = new IdentityHashMap<>(); + private final Map> dependenciesWatchers = new IdentityHashMap<>(); - public final void add(final I instance) - { - final Class typeClass = instance.getClass(); - if (dependencies.containsKey(typeClass)) - return; - dependencies.put(typeClass, instance); - } + public final void add(final Class typeClass) { + if (dependencies.containsKey(typeClass)) return; + final DependenceWatcher dependenceWatcher = dependenciesWatchers.get(typeClass); + if (dependenceWatcher != null) { + add(dependenceWatcher.instantiate()); + return; + } + try { + final Constructor constructor = typeClass.getDeclaredConstructor(); + constructor.setAccessible(true); + add((I) constructor.newInstance()); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException + | InvocationTargetException e) { + e.printStackTrace(); + } + } - public final I get(final Class typeClass) - { - final I instance = (I) dependencies.get(typeClass); - if (instance != null) - return instance; - add(typeClass); - return (I) dependencies.get(typeClass); - } + public final void add(final I instance) { + final Class typeClass = instance.getClass(); + if (dependencies.containsKey(typeClass)) return; + dependencies.put(typeClass, instance); + } - public final boolean contains(final Class typeClass) - { - return dependencies.containsKey(typeClass); - } + public final I get(final Class typeClass) { + final I instance = (I) dependencies.get(typeClass); + if (instance != null) return instance; + add(typeClass); + return (I) dependencies.get(typeClass); + } - public final void subscribe(final DependenceWatcher dependenceWatcher) - { - if (!dependenciesWatchers.containsKey(dependenceWatcher.dependenceClass)) - dependenciesWatchers.put(dependenceWatcher.dependenceClass, dependenceWatcher); - } + public final boolean contains(final Class typeClass) { + return dependencies.containsKey(typeClass); + } - public abstract class DependenceWatcher - { - private final Class dependenceClass; + public final void subscribe(final DependenceWatcher dependenceWatcher) { + if (!dependenciesWatchers.containsKey(dependenceWatcher.dependenceClass)) + dependenciesWatchers.put(dependenceWatcher.dependenceClass, dependenceWatcher); + } - protected DependenceWatcher() - { - this.dependenceClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - } + public abstract class DependenceWatcher { - @Nonnull - public abstract W instantiate(); - } -} \ No newline at end of file + private final Class dependenceClass; + + protected DependenceWatcher() { + this.dependenceClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + } + + @Nonnull + public abstract W instantiate(); + } +} diff --git a/src/main/java/wanion/lib/common/FixedSizeList.java b/src/main/java/wanion/lib/common/FixedSizeList.java index a64c26d..6505a35 100644 --- a/src/main/java/wanion/lib/common/FixedSizeList.java +++ b/src/main/java/wanion/lib/common/FixedSizeList.java @@ -1,107 +1,89 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import javax.annotation.Nonnull; import java.util.AbstractList; import java.util.Arrays; import java.util.Collection; +import javax.annotation.Nonnull; + @SuppressWarnings("unused") -public class FixedSizeList extends AbstractList -{ - private static final int DEFAULT_CAPACITY = 64; - private final E[] allTheData; - private final int capacity; - private int size; +public class FixedSizeList extends AbstractList { - @SuppressWarnings("unchecked") - public FixedSizeList() - { - allTheData = (E[]) new Object[capacity = DEFAULT_CAPACITY]; - } + private static final int DEFAULT_CAPACITY = 64; + private final E[] allTheData; + private final int capacity; + private int size; - @SuppressWarnings("unchecked") - public FixedSizeList(int capacity) - { - if (capacity <= 0) - capacity = DEFAULT_CAPACITY; - allTheData = (E[]) new Object[this.capacity = capacity]; - } + @SuppressWarnings("unchecked") + public FixedSizeList() { + allTheData = (E[]) new Object[capacity = DEFAULT_CAPACITY]; + } - @SuppressWarnings("unchecked") - private FixedSizeList(@Nonnull final Collection collection) - { - allTheData = (E[]) Arrays.copyOf(collection.toArray(), capacity = size = collection.size()); - } + @SuppressWarnings("unchecked") + public FixedSizeList(int capacity) { + if (capacity <= 0) capacity = DEFAULT_CAPACITY; + allTheData = (E[]) new Object[this.capacity = capacity]; + } - @Override - public int size() - { - return size; - } + @SuppressWarnings("unchecked") + private FixedSizeList(@Nonnull final Collection collection) { + allTheData = (E[]) Arrays.copyOf(collection.toArray(), capacity = size = collection.size()); + } - @Override - public boolean isEmpty() - { - return size == 0; - } + @Override + public int size() { + return size; + } - @Override - public boolean add(final E e) - { - if (size == capacity) - return false; - allTheData[size++] = e; - return true; - } + @Override + public boolean isEmpty() { + return size == 0; + } - @Override - public void add(final int index, E e) - { - allTheData[index] = e; - } + @Override + public boolean add(final E e) { + if (size == capacity) return false; + allTheData[size++] = e; + return true; + } - @Override - public E get(final int index) - { - if (index > size) - return null; - return allTheData[index]; - } + @Override + public void add(final int index, E e) { + allTheData[index] = e; + } - @Override - public E remove(final int index) - { - if (index >= size) - throw new IndexOutOfBoundsException(); - modCount++; - final E removed = allTheData[index]; - if (size != 1) - System.arraycopy(allTheData, index + 1, allTheData, index, size - index - 1); - allTheData[--size] = null; - return removed; - } + @Override + public E get(final int index) { + if (index > size) return null; + return allTheData[index]; + } - @Override - @Nonnull - public Object[] toArray() - { - return Arrays.copyOf(allTheData, size); - } + @Override + public E remove(final int index) { + if (index >= size) throw new IndexOutOfBoundsException(); + modCount++; + final E removed = allTheData[index]; + if (size != 1) System.arraycopy(allTheData, index + 1, allTheData, index, size - index - 1); + allTheData[--size] = null; + return removed; + } - @SuppressWarnings("unchecked") - @Override - public void clear() - { - modCount++; - while (size > 0) - allTheData[--size] = null; - } -} \ No newline at end of file + @Override + @Nonnull + public Object[] toArray() { + return Arrays.copyOf(allTheData, size); + } + + @SuppressWarnings("unchecked") + @Override + public void clear() { + modCount++; + while (size > 0) allTheData[--size] = null; + } +} diff --git a/src/main/java/wanion/lib/common/IRemovable.java b/src/main/java/wanion/lib/common/IRemovable.java index 8905c14..d44b58a 100644 --- a/src/main/java/wanion/lib/common/IRemovable.java +++ b/src/main/java/wanion/lib/common/IRemovable.java @@ -1,15 +1,14 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -public interface IRemovable -{ - boolean removed(); - void setRemoved(final boolean removed); -} \ No newline at end of file +public interface IRemovable { + + boolean removed(); + + void setRemoved(final boolean removed); +} diff --git a/src/main/java/wanion/lib/common/Instantiator.java b/src/main/java/wanion/lib/common/Instantiator.java index 0f54b57..a594e47 100644 --- a/src/main/java/wanion/lib/common/Instantiator.java +++ b/src/main/java/wanion/lib/common/Instantiator.java @@ -1,18 +1,16 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ import javax.annotation.Nonnull; @FunctionalInterface -public interface Instantiator -{ - @Nonnull - I instantiate(Class moduleThreadClass) throws InstantiationException, IllegalAccessException; -} \ No newline at end of file +public interface Instantiator { + + @Nonnull + I instantiate(Class moduleThreadClass) throws InstantiationException, IllegalAccessException; +} diff --git a/src/main/java/wanion/lib/common/MetaItem.java b/src/main/java/wanion/lib/common/MetaItem.java index a1b3c4b..e8db515 100644 --- a/src/main/java/wanion/lib/common/MetaItem.java +++ b/src/main/java/wanion/lib/common/MetaItem.java @@ -1,13 +1,19 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + import cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry; import cpw.mods.fml.common.registry.GameData; import gnu.trove.list.TIntList; @@ -18,102 +24,81 @@ import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.set.TIntSet; import gnu.trove.set.hash.TIntHashSet; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; - -import javax.annotation.Nonnull; -import java.util.Collection; @SuppressWarnings("unused") -public final class MetaItem -{ - public static final FMLControlledNamespacedRegistry itemRegistry = GameData.getItemRegistry(); +public final class MetaItem { - private MetaItem() {} + public static final FMLControlledNamespacedRegistry itemRegistry = GameData.getItemRegistry(); - public static int get(final ItemStack itemStack) - { - Item item; - if (itemStack == null || (item = itemStack.getItem()) == null) - return 0; - final int id = itemRegistry.getId(item); - return id > 0 ? item.getDamage(itemStack) == OreDictionary.WILDCARD_VALUE ? id : id | item.getDamage(itemStack) + 1 << 16 : 0; - } + private MetaItem() {} - public static int get(final Item item) - { - if (item == null) - return 0; - final int id = itemRegistry.getIDForObject(item); - return id > 0 ? id | 65536 : 0; - } + public static int get(final ItemStack itemStack) { + Item item; + if (itemStack == null || (item = itemStack.getItem()) == null) return 0; + final int id = itemRegistry.getId(item); + return id > 0 ? item.getDamage(itemStack) == OreDictionary.WILDCARD_VALUE ? id + : id | item.getDamage(itemStack) + 1 << 16 : 0; + } - public static ItemStack toItemStack(final int metaItemKey) - { - return metaItemKey > 0 ? new ItemStack(itemRegistry.getRaw(metaItemKey ^ (metaItemKey & 65536)), 0, metaItemKey >> 16) : null; - } + public static int get(final Item item) { + if (item == null) return 0; + final int id = itemRegistry.getIDForObject(item); + return id > 0 ? id | 65536 : 0; + } - public static int[] getArray(final Collection itemStackCollection) - { - return getList(itemStackCollection).toArray(); - } + public static ItemStack toItemStack(final int metaItemKey) { + return metaItemKey > 0 + ? new ItemStack(itemRegistry.getRaw(metaItemKey ^ (metaItemKey & 65536)), 0, metaItemKey >> 16) + : null; + } - public static TIntList getList(final Collection itemStackCollection) - { - final TIntList keys = new TIntArrayList(); - int hash; - for (final ItemStack itemStack : itemStackCollection) - if ((hash = get(itemStack)) != 0) - keys.add(hash); - return keys; - } + public static int[] getArray(final Collection itemStackCollection) { + return getList(itemStackCollection).toArray(); + } - public static TIntSet getSet(final Collection itemStackCollection) - { - return new TIntHashSet(getList(itemStackCollection)); - } + public static TIntList getList(final Collection itemStackCollection) { + final TIntList keys = new TIntArrayList(); + int hash; + for (final ItemStack itemStack : itemStackCollection) if ((hash = get(itemStack)) != 0) keys.add(hash); + return keys; + } - public static void populateMap(final Collection itemStackCollection, final TIntObjectMap map, final E defaultValue) - { - for (final int id : getArray(itemStackCollection)) - map.put(id, defaultValue); - } + public static TIntSet getSet(final Collection itemStackCollection) { + return new TIntHashSet(getList(itemStackCollection)); + } - public static void populateMap(final Collection itemStackCollection, final TIntLongMap map, long defaultValue) - { - for (final int id : getArray(itemStackCollection)) - map.put(id, defaultValue); - } + public static void populateMap(final Collection itemStackCollection, final TIntObjectMap map, + final E defaultValue) { + for (final int id : getArray(itemStackCollection)) map.put(id, defaultValue); + } - public static TIntIntMap getKeySizeMap(final int startIndex, final int endIndex, @Nonnull ItemStack[] itemStacks) - { - final TIntIntMap keySizeMap = new TIntIntHashMap(); - for (int i = startIndex; i < endIndex; i++) { - if (itemStacks[i] == null) - continue; - final int key = get(itemStacks[i]); - if (keySizeMap.containsKey(key)) - keySizeMap.put(key, keySizeMap.get(key) + 1); - else - keySizeMap.put(key, 1); - } - return keySizeMap; - } + public static void populateMap(final Collection itemStackCollection, final TIntLongMap map, + long defaultValue) { + for (final int id : getArray(itemStackCollection)) map.put(id, defaultValue); + } - public static TIntIntMap getSmartKeySizeMap(final int startIndex, final int endIndex, @Nonnull ItemStack[] itemStacks) - { - final TIntIntMap smartKeySizeMap = new TIntIntHashMap(); - for (int i = startIndex; i < endIndex; i++) { - final ItemStack itemStack = itemStacks[i]; - if (itemStack == null) - continue; - final int key = get(itemStack); - if (smartKeySizeMap.containsKey(key)) - smartKeySizeMap.put(key, smartKeySizeMap.get(key) + itemStack.stackSize); - else - smartKeySizeMap.put(key, itemStack.stackSize); - } - return smartKeySizeMap; - } -} \ No newline at end of file + public static TIntIntMap getKeySizeMap(final int startIndex, final int endIndex, @Nonnull ItemStack[] itemStacks) { + final TIntIntMap keySizeMap = new TIntIntHashMap(); + for (int i = startIndex; i < endIndex; i++) { + if (itemStacks[i] == null) continue; + final int key = get(itemStacks[i]); + if (keySizeMap.containsKey(key)) keySizeMap.put(key, keySizeMap.get(key) + 1); + else keySizeMap.put(key, 1); + } + return keySizeMap; + } + + public static TIntIntMap getSmartKeySizeMap(final int startIndex, final int endIndex, + @Nonnull ItemStack[] itemStacks) { + final TIntIntMap smartKeySizeMap = new TIntIntHashMap(); + for (int i = startIndex; i < endIndex; i++) { + final ItemStack itemStack = itemStacks[i]; + if (itemStack == null) continue; + final int key = get(itemStack); + if (smartKeySizeMap.containsKey(key)) + smartKeySizeMap.put(key, smartKeySizeMap.get(key) + itemStack.stackSize); + else smartKeySizeMap.put(key, itemStack.stackSize); + } + return smartKeySizeMap; + } +} diff --git a/src/main/java/wanion/lib/common/MineTweakerHelper.java b/src/main/java/wanion/lib/common/MineTweakerHelper.java index c52f663..30e8ac6 100644 --- a/src/main/java/wanion/lib/common/MineTweakerHelper.java +++ b/src/main/java/wanion/lib/common/MineTweakerHelper.java @@ -1,71 +1,62 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import minetweaker.api.oredict.IOreDictEntry; + import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @SuppressWarnings("unused") -public final class MineTweakerHelper -{ - private MineTweakerHelper() {} +public final class MineTweakerHelper { - public static ItemStack toStack(final IItemStack item) - { - if (item == null) - return null; - final Object internal = item.getInternal(); - if (internal == null || !(internal instanceof ItemStack)) - MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item); - return internal instanceof ItemStack ? (ItemStack) internal : null; - } + private MineTweakerHelper() {} - public static Object[] toObjects(final IIngredient[] list) - { - if (list == null) - return null; - Object[] ingredients = new Object[list.length]; - for (int x = 0; x < list.length; x++) { - ingredients[x] = toObject(list[x]); - } - return ingredients; - } + public static ItemStack toStack(final IItemStack item) { + if (item == null) return null; + final Object internal = item.getInternal(); + if (internal == null || !(internal instanceof ItemStack)) + MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item); + return internal instanceof ItemStack ? (ItemStack) internal : null; + } - public static Object toActualObject(final IIngredient ingredient) - { - if (ingredient == null) return null; - else { - if (ingredient instanceof IOreDictEntry) { - return OreDictionary.getOres(toString((IOreDictEntry) ingredient)); - } else if (ingredient instanceof IItemStack) { - return toStack((IItemStack) ingredient); - } else return null; - } - } + public static Object[] toObjects(final IIngredient[] list) { + if (list == null) return null; + Object[] ingredients = new Object[list.length]; + for (int x = 0; x < list.length; x++) { + ingredients[x] = toObject(list[x]); + } + return ingredients; + } - public static Object toObject(final IIngredient ingredient) - { - if (ingredient == null) - return null; - if (ingredient instanceof IOreDictEntry) { - return toString((IOreDictEntry) ingredient); - } else if (ingredient instanceof IItemStack) { - return toStack((IItemStack) ingredient); - } else return null; - } + public static Object toActualObject(final IIngredient ingredient) { + if (ingredient == null) return null; + else { + if (ingredient instanceof IOreDictEntry) { + return OreDictionary.getOres(toString((IOreDictEntry) ingredient)); + } else if (ingredient instanceof IItemStack) { + return toStack((IItemStack) ingredient); + } else return null; + } + } - public static String toString(final IOreDictEntry entry) - { - return entry.getName(); - } -} \ No newline at end of file + public static Object toObject(final IIngredient ingredient) { + if (ingredient == null) return null; + if (ingredient instanceof IOreDictEntry) { + return toString((IOreDictEntry) ingredient); + } else if (ingredient instanceof IItemStack) { + return toStack((IItemStack) ingredient); + } else return null; + } + + public static String toString(final IOreDictEntry entry) { + return entry.getName(); + } +} diff --git a/src/main/java/wanion/lib/common/Util.java b/src/main/java/wanion/lib/common/Util.java index 10d8188..62d9e15 100644 --- a/src/main/java/wanion/lib/common/Util.java +++ b/src/main/java/wanion/lib/common/Util.java @@ -1,45 +1,45 @@ package wanion.lib.common; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.common.registry.GameData; -import net.minecraft.item.ItemStack; - import java.lang.reflect.Field; -public final class Util -{ - private Util() {} +import net.minecraft.item.ItemStack; - @SuppressWarnings("unchecked") - public static E getField(Class clas, String name, Object instance, Class expectedClass) - { - try { - final Field field = clas.getDeclaredField(name); - field.setAccessible(true); - return (E) expectedClass.cast(field.get(instance)); - } catch (Exception e) { e.printStackTrace(); } - return null; - } +import cpw.mods.fml.common.registry.GameData; - public static void setField(Class clas, String name, Object instance, E newInstance) - { - try { - final Field field = clas.getDeclaredField(name); - field.setAccessible(true); - field.set(instance, newInstance); - } catch (Exception e) { e.printStackTrace(); } - } +public final class Util { - public static String getModName(final ItemStack itemStack) - { - String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem()); - return name.substring(0, name.indexOf(58)); - } -} \ No newline at end of file + private Util() {} + + @SuppressWarnings("unchecked") + public static E getField(Class clas, String name, Object instance, Class expectedClass) { + try { + final Field field = clas.getDeclaredField(name); + field.setAccessible(true); + return (E) expectedClass.cast(field.get(instance)); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static void setField(Class clas, String name, Object instance, E newInstance) { + try { + final Field field = clas.getDeclaredField(name); + field.setAccessible(true); + field.set(instance, newInstance); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String getModName(final ItemStack itemStack) { + String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem()); + return name.substring(0, name.indexOf(58)); + } +} diff --git a/src/main/java/wanion/lib/module/AbstractModule.java b/src/main/java/wanion/lib/module/AbstractModule.java index 470ff82..98f35e0 100644 --- a/src/main/java/wanion/lib/module/AbstractModule.java +++ b/src/main/java/wanion/lib/module/AbstractModule.java @@ -1,98 +1,99 @@ package wanion.lib.module; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import org.apache.logging.log4j.Logger; -import wanion.lib.WanionLib; -import wanion.lib.common.Instantiator; - -import javax.annotation.Nonnull; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -public abstract class AbstractModule -{ - protected final Manager manager; - private final String moduleName; +import javax.annotation.Nonnull; - protected AbstractModule(@Nonnull final String moduleName, @Nonnull final Instantiator moduleThreadInstantiator) - { - this.moduleName = moduleName; - manager = new Manager(moduleThreadInstantiator); - } +import org.apache.logging.log4j.Logger; - protected abstract void init(); +import wanion.lib.WanionLib; +import wanion.lib.common.Instantiator; - final void start(@Nonnull final LoadStage loadStage, @Nonnull final Manager manager) - { - final List threadList = manager.getInstances(loadStage); - if (threadList.isEmpty()) - return; - final ExecutorService moduleThreadExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - final Logger logger = WanionLib.getLogger(); - try { - final long initialTime = System.nanoTime(); - final List> futureOfThreads = moduleThreadExecutor.invokeAll(threadList); - final long took = System.nanoTime() - initialTime; - for (final Future threadModuleSay : futureOfThreads) - logger.info(threadModuleSay.get()); - logger.info("All " + threadList.size() + " " + moduleName + "s took " + took / 1000000 + "ms to finish. at load stage " + loadStage.name()); - } catch (InterruptedException | ExecutionException e) { - logger.error("Something really bad happened on " + moduleName + " at load stage " + loadStage.name()); - e.printStackTrace(); - } - } +public abstract class AbstractModule { - public static class Manager - { - private final Map>> loadStageMap; - private final Instantiator instantiator; + protected final Manager manager; + private final String moduleName; - public Manager(@Nonnull final Instantiator instantiator) - { - this.instantiator = instantiator; - loadStageMap = new EnumMap<>(LoadStage.class); - for (final LoadStage loadStage : LoadStage.values()) - loadStageMap.put(loadStage, new LinkedHashSet<>()); - } + protected AbstractModule(@Nonnull final String moduleName, + @Nonnull final Instantiator moduleThreadInstantiator) { + this.moduleName = moduleName; + manager = new Manager(moduleThreadInstantiator); + } - public boolean add(@Nonnull final Class moduleThreadClass) - { - final LoadStage loadStage = (moduleThreadClass.isAnnotationPresent(SpecifiedLoadStage.class)) ? moduleThreadClass.getAnnotation(SpecifiedLoadStage.class).stage() : LoadStage.POST_INIT; - final Set> classSet = loadStageMap.get(loadStage); - return !classSet.contains(moduleThreadClass) && classSet.add(moduleThreadClass); - } + protected abstract void init(); - public boolean isEmpty() - { - return loadStageMap.values().stream().allMatch(Set::isEmpty); - } + final void start(@Nonnull final LoadStage loadStage, @Nonnull final Manager manager) { + final List threadList = manager.getInstances(loadStage); + if (threadList.isEmpty()) return; + final ExecutorService moduleThreadExecutor = Executors + .newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + final Logger logger = WanionLib.getLogger(); + try { + final long initialTime = System.nanoTime(); + final List> futureOfThreads = moduleThreadExecutor.invokeAll(threadList); + final long took = System.nanoTime() - initialTime; + for (final Future threadModuleSay : futureOfThreads) logger.info(threadModuleSay.get()); + logger.info( + "All " + threadList.size() + + " " + + moduleName + + "s took " + + took / 1000000 + + "ms to finish. at load stage " + + loadStage.name()); + } catch (InterruptedException | ExecutionException e) { + logger.error("Something really bad happened on " + moduleName + " at load stage " + loadStage.name()); + e.printStackTrace(); + } + } - public boolean isEmpty(final LoadStage loadStage) - { - return loadStageMap.get(loadStage).isEmpty(); - } + public static class Manager { - public List getInstances(final LoadStage loadStage) - { - final List abstractModuleThreads = new ArrayList<>(); - loadStageMap.get(loadStage).forEach(t -> { - try { - abstractModuleThreads.add(instantiator.instantiate(t)); - } catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } - }); - return abstractModuleThreads; - } - } -} \ No newline at end of file + private final Map>> loadStageMap; + private final Instantiator instantiator; + + public Manager(@Nonnull final Instantiator instantiator) { + this.instantiator = instantiator; + loadStageMap = new EnumMap<>(LoadStage.class); + for (final LoadStage loadStage : LoadStage.values()) loadStageMap.put(loadStage, new LinkedHashSet<>()); + } + + public boolean add(@Nonnull final Class moduleThreadClass) { + final LoadStage loadStage = (moduleThreadClass.isAnnotationPresent(SpecifiedLoadStage.class)) + ? moduleThreadClass.getAnnotation(SpecifiedLoadStage.class).stage() + : LoadStage.POST_INIT; + final Set> classSet = loadStageMap.get(loadStage); + return !classSet.contains(moduleThreadClass) && classSet.add(moduleThreadClass); + } + + public boolean isEmpty() { + return loadStageMap.values().stream().allMatch(Set::isEmpty); + } + + public boolean isEmpty(final LoadStage loadStage) { + return loadStageMap.get(loadStage).isEmpty(); + } + + public List getInstances(final LoadStage loadStage) { + final List abstractModuleThreads = new ArrayList<>(); + loadStageMap.get(loadStage).forEach(t -> { + try { + abstractModuleThreads.add(instantiator.instantiate(t)); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + }); + return abstractModuleThreads; + } + } +} diff --git a/src/main/java/wanion/lib/module/AbstractModuleThread.java b/src/main/java/wanion/lib/module/AbstractModuleThread.java index 34e7c71..639fbba 100644 --- a/src/main/java/wanion/lib/module/AbstractModuleThread.java +++ b/src/main/java/wanion/lib/module/AbstractModuleThread.java @@ -1,21 +1,18 @@ package wanion.lib.module; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ import java.util.concurrent.Callable; -public abstract class AbstractModuleThread implements Callable -{ - protected final String threadName; +public abstract class AbstractModuleThread implements Callable { - public AbstractModuleThread(String threadName, String moduleName) - { - this.threadName = threadName + " " + moduleName + ": "; - } -} \ No newline at end of file + protected final String threadName; + + public AbstractModuleThread(String threadName, String moduleName) { + this.threadName = threadName + " " + moduleName + ": "; + } +} diff --git a/src/main/java/wanion/lib/module/LoadStage.java b/src/main/java/wanion/lib/module/LoadStage.java index 4f521f7..0ffbc7e 100644 --- a/src/main/java/wanion/lib/module/LoadStage.java +++ b/src/main/java/wanion/lib/module/LoadStage.java @@ -1,36 +1,30 @@ package wanion.lib.module; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.common.event.*; - import javax.annotation.Nonnull; -public enum LoadStage -{ - PRE_INIT(FMLPreInitializationEvent.class), - INIT(FMLInitializationEvent.class), - POST_INIT(FMLPostInitializationEvent.class), - LOAD_COMPLETE(FMLLoadCompleteEvent.class); +import cpw.mods.fml.common.event.*; - public final Class stage; +public enum LoadStage { - LoadStage(Class stage) - { - this.stage = stage; - } + PRE_INIT(FMLPreInitializationEvent.class), + INIT(FMLInitializationEvent.class), + POST_INIT(FMLPostInitializationEvent.class), + LOAD_COMPLETE(FMLLoadCompleteEvent.class); - public static LoadStage getStage(@Nonnull final Class stage) - { - for (final LoadStage loadStage : values()) - if (loadStage.stage == stage) - return loadStage; - return null; - } -} \ No newline at end of file + public final Class stage; + + LoadStage(Class stage) { + this.stage = stage; + } + + public static LoadStage getStage(@Nonnull final Class stage) { + for (final LoadStage loadStage : values()) if (loadStage.stage == stage) return loadStage; + return null; + } +} diff --git a/src/main/java/wanion/lib/module/ModuleHandler.java b/src/main/java/wanion/lib/module/ModuleHandler.java index b387255..af70167 100644 --- a/src/main/java/wanion/lib/module/ModuleHandler.java +++ b/src/main/java/wanion/lib/module/ModuleHandler.java @@ -1,48 +1,39 @@ package wanion.lib.module; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import cpw.mods.fml.common.event.FMLStateEvent; -import gnu.trove.map.hash.THashMap; - import java.util.HashSet; import java.util.Map; import java.util.Set; -public final class ModuleHandler -{ - private final Set> moduleClasses = new HashSet<>(); - private final Map modules = new THashMap<>(); +import cpw.mods.fml.common.event.FMLStateEvent; +import gnu.trove.map.hash.THashMap; - public void startModules(final FMLStateEvent event) - { - final LoadStage loadStage = (event != null) ? LoadStage.getStage(event.getClass()) : null; - if (modules.isEmpty() || loadStage == null) - return; - modules.entrySet().forEach(e -> { - final AbstractModule module = e.getKey(); - if (e.getValue() == null) - e.setValue(module.manager); - final AbstractModule.Manager manager = e.getValue(); - if (manager.isEmpty()) - module.init(); - if (!manager.isEmpty(loadStage)) - module.start(loadStage, manager); - }); - } +public final class ModuleHandler { - public void addModule(final AbstractModule module) - { - Class moduleClass = (module != null) ? module.getClass() : null; - if (moduleClass == null || moduleClasses.contains(moduleClass)) - return; - moduleClasses.add(moduleClass); - modules.put(module, null); - } -} \ No newline at end of file + private final Set> moduleClasses = new HashSet<>(); + private final Map modules = new THashMap<>(); + + public void startModules(final FMLStateEvent event) { + final LoadStage loadStage = (event != null) ? LoadStage.getStage(event.getClass()) : null; + if (modules.isEmpty() || loadStage == null) return; + modules.entrySet().forEach(e -> { + final AbstractModule module = e.getKey(); + if (e.getValue() == null) e.setValue(module.manager); + final AbstractModule.Manager manager = e.getValue(); + if (manager.isEmpty()) module.init(); + if (!manager.isEmpty(loadStage)) module.start(loadStage, manager); + }); + } + + public void addModule(final AbstractModule module) { + Class moduleClass = (module != null) ? module.getClass() : null; + if (moduleClass == null || moduleClasses.contains(moduleClass)) return; + moduleClasses.add(moduleClass); + modules.put(module, null); + } +} diff --git a/src/main/java/wanion/lib/module/SpecifiedLoadStage.java b/src/main/java/wanion/lib/module/SpecifiedLoadStage.java index 675d67d..3cd4554 100644 --- a/src/main/java/wanion/lib/module/SpecifiedLoadStage.java +++ b/src/main/java/wanion/lib/module/SpecifiedLoadStage.java @@ -1,23 +1,22 @@ package wanion.lib.module; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import javax.annotation.Nonnull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import javax.annotation.Nonnull; + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface SpecifiedLoadStage -{ - @Nonnull - LoadStage stage(); -} \ No newline at end of file +public @interface SpecifiedLoadStage { + + @Nonnull + LoadStage stage(); +} diff --git a/src/main/java/wanion/lib/recipe/RecipeHelper.java b/src/main/java/wanion/lib/recipe/RecipeHelper.java index ce8c5a2..fb9a07a 100644 --- a/src/main/java/wanion/lib/recipe/RecipeHelper.java +++ b/src/main/java/wanion/lib/recipe/RecipeHelper.java @@ -1,96 +1,85 @@ package wanion.lib.recipe; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ +import java.util.Map; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; + +import wanion.lib.common.MetaItem; import gnu.trove.map.TObjectCharMap; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TObjectCharHashMap; -import net.minecraft.item.ItemStack; -import wanion.lib.common.MetaItem; -import javax.annotation.Nonnull; -import java.util.Map; +public final class RecipeHelper { -public final class RecipeHelper -{ - private RecipeHelper() {} + private RecipeHelper() {} - @Nonnull - public static Object[] rawShapeToShape(@Nonnull final Object[] objects) - { - return rawShapeToShape(objects, 3); - } + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[] objects) { + return rawShapeToShape(objects, 3); + } - @Nonnull - public static Object[] rawShapeToShape(@Nonnull final Object[] objects, final int squareRoot) - { - int f = 1; - final char[][] almostTheShape = new char[squareRoot][squareRoot]; - final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); - final Map keyStackMap = new THashMap<>(); - boolean done = false; - for (int x = 0; x < squareRoot && !done; x++) { - for (int y = 0; y < squareRoot && !done; y++) { - final int index = y * squareRoot + x; - if ((done = !(index < objects.length)) || objects[index] == null) - continue; - final Object key = objects[index] instanceof ItemStack ? MetaItem.get((ItemStack) objects[index]) : objects[index]; - if (key instanceof Integer) - keyStackMap.put((Integer) key, (ItemStack) objects[index]); - if (thingToCharMap.containsKey(key)) - almostTheShape[y][x] = thingToCharMap.get(key); - else - thingToCharMap.put(key, almostTheShape[y][x] = (char) f++); - } - } - final Object[] shape = new Object[squareRoot + thingToCharMap.size() * 2]; - for (int i = 0; i < squareRoot; i++) - shape[i] = new String(almostTheShape[i]); - int i = 0; - for (final Object object : thingToCharMap.keySet()) { - shape[squareRoot + (2 * i)] = thingToCharMap.get(object); - shape[squareRoot + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; - } - return shape; - } + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[] objects, final int squareRoot) { + int f = 1; + final char[][] almostTheShape = new char[squareRoot][squareRoot]; + final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); + final Map keyStackMap = new THashMap<>(); + boolean done = false; + for (int x = 0; x < squareRoot && !done; x++) { + for (int y = 0; y < squareRoot && !done; y++) { + final int index = y * squareRoot + x; + if ((done = !(index < objects.length)) || objects[index] == null) continue; + final Object key = objects[index] instanceof ItemStack ? MetaItem.get((ItemStack) objects[index]) + : objects[index]; + if (key instanceof Integer) keyStackMap.put((Integer) key, (ItemStack) objects[index]); + if (thingToCharMap.containsKey(key)) almostTheShape[y][x] = thingToCharMap.get(key); + else thingToCharMap.put(key, almostTheShape[y][x] = (char) f++); + } + } + final Object[] shape = new Object[squareRoot + thingToCharMap.size() * 2]; + for (int i = 0; i < squareRoot; i++) shape[i] = new String(almostTheShape[i]); + int i = 0; + for (final Object object : thingToCharMap.keySet()) { + shape[squareRoot + (2 * i)] = thingToCharMap.get(object); + shape[squareRoot + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; + } + return shape; + } - @Nonnull - public static Object[] rawShapeToShape(@Nonnull final Object[][] objects, final int squareRoot) - { - int f = 1; - final char[][] almostTheShape = new char[objects.length][squareRoot]; - final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); - final Map keyStackMap = new THashMap<>(); - for (int y = 0; y < objects.length; y++) { - final Object[] inputArray = objects[y]; - if (inputArray == null) - continue; - for (int x = 0; x < inputArray.length; x++) { - final Object key = inputArray[x] instanceof ItemStack ? MetaItem.get((ItemStack) inputArray[x]) : inputArray[x]; - if (key == null) - continue; - else if (key instanceof Integer && !keyStackMap.containsKey(key)) - keyStackMap.put((Integer) key, (ItemStack) inputArray[x]); - if (thingToCharMap.containsKey(key)) - almostTheShape[y][x] = thingToCharMap.get(key); - else - thingToCharMap.put(key, almostTheShape[y][x] = (char) f++); - } - } - final Object[] shape = new Object[objects.length + thingToCharMap.size() * 2]; - for (int i = 0; i < objects.length; i++) - shape[i] = new String(almostTheShape[i]); - int i = 0; - for (final Object object : thingToCharMap.keySet()) { - shape[objects.length + (2 * i)] = thingToCharMap.get(object); - shape[objects.length + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; - } - return shape; - } -} \ No newline at end of file + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[][] objects, final int squareRoot) { + int f = 1; + final char[][] almostTheShape = new char[objects.length][squareRoot]; + final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); + final Map keyStackMap = new THashMap<>(); + for (int y = 0; y < objects.length; y++) { + final Object[] inputArray = objects[y]; + if (inputArray == null) continue; + for (int x = 0; x < inputArray.length; x++) { + final Object key = inputArray[x] instanceof ItemStack ? MetaItem.get((ItemStack) inputArray[x]) + : inputArray[x]; + if (key == null) continue; + else if (key instanceof Integer && !keyStackMap.containsKey(key)) + keyStackMap.put((Integer) key, (ItemStack) inputArray[x]); + if (thingToCharMap.containsKey(key)) almostTheShape[y][x] = thingToCharMap.get(key); + else thingToCharMap.put(key, almostTheShape[y][x] = (char) f++); + } + } + final Object[] shape = new Object[objects.length + thingToCharMap.size() * 2]; + for (int i = 0; i < objects.length; i++) shape[i] = new String(almostTheShape[i]); + int i = 0; + for (final Object object : thingToCharMap.keySet()) { + shape[objects.length + (2 * i)] = thingToCharMap.get(object); + shape[objects.length + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; + } + return shape; + } +} diff --git a/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java b/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java index 9e82a67..22ad633 100644 --- a/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java +++ b/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java @@ -1,107 +1,90 @@ package wanion.lib.recipe.advanced; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import gnu.trove.map.TShortObjectMap; -import gnu.trove.map.hash.TShortObjectHashMap; -import net.minecraft.inventory.InventoryCrafting; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -public abstract class AbstractRecipeRegistry -{ - public final TShortObjectMap> shapedRecipes = new TShortObjectHashMap<>(); - public final TShortObjectMap> shapelessRecipes = new TShortObjectHashMap<>(); +import javax.annotation.Nonnull; +import javax.annotation.Nullable; - public final void addRecipe(@Nonnull final R recipe) - { - final short recipeKey = recipe.getRecipeKey(); - if (recipeKey != 0) { - if (!shapedRecipes.containsKey(recipeKey)) - shapedRecipes.put(recipeKey, new ArrayList<>()); - shapedRecipes.get(recipeKey).add(recipe); - } else { - final short recipeSize = recipe.getRecipeSize(); - if (!shapelessRecipes.containsKey(recipeSize)) - shapelessRecipes.put(recipeSize, new ArrayList<>()); - shapelessRecipes.get(recipeSize).add(recipe); - } - } +import net.minecraft.inventory.InventoryCrafting; - public final void removeRecipe(@Nullable final R recipe) - { - if (recipe == null) - return; - final short recipeKey = recipe.getRecipeKey(); - if (recipeKey != 0) { - final List shapedRecipeList = shapedRecipes.get(recipeKey); - if (shapedRecipeList != null) - shapedRecipeList.remove(recipe); - } else { - final List shapelessRecipeList = shapelessRecipes.get(recipe.getRecipeSize()); - if (shapelessRecipeList != null) - shapelessRecipeList.remove(recipe); - } - } +import gnu.trove.map.TShortObjectMap; +import gnu.trove.map.hash.TShortObjectHashMap; - public final R findMatchingRecipe(@Nonnull final InventoryCrafting inventoryCrafting) - { - final int root = (int) Math.sqrt(inventoryCrafting.getSizeInventory()); - int offSetX = 0, offSetY = 0, width = 0, height = 0; - short recipeKey = 0, recipeSize = 0; - boolean foundX = false, foundY = false; - for (int x = 0; !foundX && x < root; x++) { - for (int y = 0; !foundX && y < root; y++) - if (inventoryCrafting.getStackInSlot(y * root + x) != null) - foundX = true; - if (foundX) - offSetX = x; - } - for (int y = 0; !foundY && y < root; y++) { - for (int x = 0; x < root; x++) { - if (inventoryCrafting.getStackInSlot(y * root + x) != null) - foundY = true; - if (foundY) - offSetY = y; - } - } - for (int y = 0; y < root; y++) { - int x = 0; - while (true) { - final int actualY = offSetY + y; - if (actualY < root) { - final int actualX = offSetX + x++; - if (actualX < root) { - if (inventoryCrafting.getStackInSlot(actualY * root + actualX) == null) - continue; - final int xDifference = actualX - (offSetX - 1); - final int yDifference = actualY - (offSetY - 1); - if (xDifference > width) - width = xDifference; - if (yDifference > height) - height = yDifference; - } else break; - } else break; - } - } - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) - if (inventoryCrafting.getStackInSlot((offSetY + y) * root + (offSetX + x)) != null) - recipeSize++; - final List recipeList = shapedRecipes.containsKey((recipeKey |= recipeSize | (width << 8) | (height << 12))) ? shapedRecipes.get(recipeKey) : shapelessRecipes.get(recipeSize); - if (recipeList != null) - for (R recipe : recipeList) - if (recipe.recipeMatch(inventoryCrafting, offSetX, offSetY)) - return recipe; - return null; - } -} \ No newline at end of file +public abstract class AbstractRecipeRegistry { + + public final TShortObjectMap> shapedRecipes = new TShortObjectHashMap<>(); + public final TShortObjectMap> shapelessRecipes = new TShortObjectHashMap<>(); + + public final void addRecipe(@Nonnull final R recipe) { + final short recipeKey = recipe.getRecipeKey(); + if (recipeKey != 0) { + if (!shapedRecipes.containsKey(recipeKey)) shapedRecipes.put(recipeKey, new ArrayList<>()); + shapedRecipes.get(recipeKey).add(recipe); + } else { + final short recipeSize = recipe.getRecipeSize(); + if (!shapelessRecipes.containsKey(recipeSize)) shapelessRecipes.put(recipeSize, new ArrayList<>()); + shapelessRecipes.get(recipeSize).add(recipe); + } + } + + public final void removeRecipe(@Nullable final R recipe) { + if (recipe == null) return; + final short recipeKey = recipe.getRecipeKey(); + if (recipeKey != 0) { + final List shapedRecipeList = shapedRecipes.get(recipeKey); + if (shapedRecipeList != null) shapedRecipeList.remove(recipe); + } else { + final List shapelessRecipeList = shapelessRecipes.get(recipe.getRecipeSize()); + if (shapelessRecipeList != null) shapelessRecipeList.remove(recipe); + } + } + + public final R findMatchingRecipe(@Nonnull final InventoryCrafting inventoryCrafting) { + final int root = (int) Math.sqrt(inventoryCrafting.getSizeInventory()); + int offSetX = 0, offSetY = 0, width = 0, height = 0; + short recipeKey = 0, recipeSize = 0; + boolean foundX = false, foundY = false; + for (int x = 0; !foundX && x < root; x++) { + for (int y = 0; !foundX && y < root; y++) + if (inventoryCrafting.getStackInSlot(y * root + x) != null) foundX = true; + if (foundX) offSetX = x; + } + for (int y = 0; !foundY && y < root; y++) { + for (int x = 0; x < root; x++) { + if (inventoryCrafting.getStackInSlot(y * root + x) != null) foundY = true; + if (foundY) offSetY = y; + } + } + for (int y = 0; y < root; y++) { + int x = 0; + while (true) { + final int actualY = offSetY + y; + if (actualY < root) { + final int actualX = offSetX + x++; + if (actualX < root) { + if (inventoryCrafting.getStackInSlot(actualY * root + actualX) == null) continue; + final int xDifference = actualX - (offSetX - 1); + final int yDifference = actualY - (offSetY - 1); + if (xDifference > width) width = xDifference; + if (yDifference > height) height = yDifference; + } else break; + } else break; + } + } + for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) + if (inventoryCrafting.getStackInSlot((offSetY + y) * root + (offSetX + x)) != null) recipeSize++; + final List recipeList = shapedRecipes.containsKey((recipeKey |= recipeSize | (width << 8) | (height << 12))) + ? shapedRecipes.get(recipeKey) + : shapelessRecipes.get(recipeSize); + if (recipeList != null) + for (R recipe : recipeList) if (recipe.recipeMatch(inventoryCrafting, offSetX, offSetY)) return recipe; + return null; + } +} diff --git a/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java b/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java index 1ea3f28..7182a2b 100644 --- a/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java +++ b/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java @@ -1,27 +1,26 @@ package wanion.lib.recipe.advanced; /* - * Created by WanionCane(https://github.com/WanionCane). - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Created by WanionCane(https://github.com/WanionCane). This Source Code Form is subject to the terms of the Mozilla + * Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at + * http://mozilla.org/MPL/2.0/. */ -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.ItemStack; -import wanion.lib.common.IRemovable; - import javax.annotation.Nonnull; -public interface IAdvancedRecipe extends IRemovable -{ - short getRecipeKey(); +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; - short getRecipeSize(); +import wanion.lib.common.IRemovable; - boolean recipeMatch(@Nonnull final InventoryCrafting inventoryCrafting, final int offSetX, final int offSetY); +public interface IAdvancedRecipe extends IRemovable { - @Nonnull - ItemStack getOutput(); -} \ No newline at end of file + short getRecipeKey(); + + short getRecipeSize(); + + boolean recipeMatch(@Nonnull final InventoryCrafting inventoryCrafting, final int offSetX, final int offSetY); + + @Nonnull + ItemStack getOutput(); +}