From c96e1e63c30d63ad2515356f1a471727fb7d60e0 Mon Sep 17 00:00:00 2001 From: deirn Date: Tue, 21 Jun 2022 10:54:35 +0700 Subject: [PATCH 1/5] javadocs and guide to depend to megane (cherry picked from commit db9e3a49dd6588f5ea44728cc26d14c4403e1e92) --- README.md | 40 +++++++++++ .../megane/api/provider/AbstractProvider.java | 24 +++++++ .../megane/api/provider/CauldronProvider.java | 6 ++ .../api/provider/EnergyInfoProvider.java | 24 +++++++ .../megane/api/provider/EnergyProvider.java | 23 ++++++ .../api/provider/FluidInfoProvider.java | 22 ++++++ .../megane/api/provider/FluidProvider.java | 21 ++++++ .../bai/megane/api/provider/ItemProvider.java | 18 +++++ .../megane/api/provider/ProgressProvider.java | 25 +++++++ .../provider/base/InventoryItemProvider.java | 14 ++++ .../base/SlotArrayProgressProvider.java | 18 +++++ .../megane/api/registry/ClientRegistrar.java | 48 +++++++++++++ .../megane/api/registry/CommonRegistrar.java | 71 +++++++++++++++++++ 13 files changed, 354 insertions(+) diff --git a/README.md b/README.md index 51dd2f1..fe45f32 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,46 @@ For energy bar colors and units, `megane` value determines what's the default va **Config will get overloaded by the server**, so if the server disabled inventory tooltip, you won't see inventory tooltip regardless wether you enabled it or not. +### Adding Megane Compatibility to Your Mod +First, add megane on your build script: +```gradle +repositories { + maven { url "https://maven.bai.lol" } +} + +dependencies { + modImplementation "lol.bai.megane:megane-api:${megane_version}" + modRuntimeOnly "lol.bai.megane:megane-runtime:${megane_version}" + + // Optional: add other module to runtime classpath + // see the release page to see available modules + modRuntimeOnly "lol.bai.megane:megane-${module_name}:${megane_version}" +} +``` + +Implement `MeganeModule` interface, register your providers there +```java +class MyModMeganeModule implements MeganeModule { + @Override + public void registerCommon(CommonRegistrar registrar) { + } + + @Override + public void registerClient(ClientRegistrar registrar) { + } +} +``` + +In `fabric.mod.json`, add your module to the custom block: +```json +{ + "custom": { + "megane:modules": [ + "path.to.MyModMeganeModule" + ] + } +} +``` ### Culture Glasses are really versatile. First, you can have glasses-wearing girls take them off and suddenly become beautiful, or have girls wearing glasses diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/AbstractProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/AbstractProvider.java index a7cbf2a..75bfaec 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/AbstractProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/AbstractProvider.java @@ -6,6 +6,9 @@ import net.minecraft.world.World; import org.jetbrains.annotations.ApiStatus; +/** + * Base class to all providers. + */ public abstract class AbstractProvider { private World world; @@ -21,30 +24,51 @@ public abstract class AbstractProvider { protected void init() { } + /** + * Returns whether this provider will block any other provider. + */ public boolean blockOtherProvider() { return false; } + /** + * Returns the world context. + */ protected final World getWorld() { return world; } + /** + * Returns the position context. + */ protected final BlockPos getPos() { return pos; } + /** + * Returns the hit context. + */ protected final HitResult getHitResult() { return hitResult; } + /** + * Returns the player context. + */ protected final PlayerEntity getPlayer() { return player; } + /** + * Returns the object context. + */ protected final T getObject() { return object; } + /** + * Returns the object context, casted to arbitrary type. + */ @SuppressWarnings("unchecked") protected final C getObjectCasted() { return (C) object; diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/CauldronProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/CauldronProvider.java index ec53bbd..ab6dc6e 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/CauldronProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/CauldronProvider.java @@ -1,7 +1,13 @@ package lol.bai.megane.api.provider; +import lol.bai.megane.api.registry.CommonRegistrar; import net.minecraft.block.BlockState; +/** + * Base class to cauldron-base fluid provider. + *

+ * Register implementations with {@link CommonRegistrar#addCauldron}. + */ public abstract class CauldronProvider extends FluidProvider { protected final BlockState getState() { diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyInfoProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyInfoProvider.java index b3272ac..474a78c 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyInfoProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyInfoProvider.java @@ -2,23 +2,47 @@ import javax.annotation.Nullable; +import lol.bai.megane.api.registry.ClientRegistrar; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; +/** + * Base class of dynamic energy information provider. + * This decides how energy info will be displayed on client. + *

+ * Register implementations with {@link ClientRegistrar#addEnergyInfo} + * + * @param type of {@link BlockEntity} this provider for. + */ public abstract class EnergyInfoProvider extends AbstractProvider { public static final Text DEFAULT_NAME = new TranslatableText("megane.energy"); + /** + * Returns whether this provider decides the look of the info. + */ public boolean hasEnergyInfo() { return true; } + /** + * Returns the name of energy. + * + * @see #DEFAULT_NAME + */ public Text getName() { return DEFAULT_NAME; } + /** + * Returns the color of the energy bar. + */ public abstract int getColor(); + /** + * Returns the unit of the energy, or {@code null} if it doesn't have one. + */ @Nullable public abstract String getUnit(); diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyProvider.java index 854c8d9..c1c6fc9 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/EnergyProvider.java @@ -1,13 +1,36 @@ package lol.bai.megane.api.provider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; + +/** + * Base class for energy provider. + *

+ * Register implementations with {@link CommonRegistrar#addEnergy} + * + * @param type of {@link BlockEntity} this provider for. + */ public abstract class EnergyProvider extends AbstractProvider { + /** + * Returns whether the object has an energy. + */ public boolean hasEnergy() { return true; } + /** + * Returns how much energy is currently stored. + *

+ * Return {@code -1} to mark this as unlimited energy. + */ public abstract long getStored(); + /** + * Returns how much the capacity of the storage. + *

+ * Return {@code -1} to mark this as unlimited capacity. + */ public abstract long getMax(); } diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidInfoProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidInfoProvider.java index ee4ac6e..17f341b 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidInfoProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidInfoProvider.java @@ -1,23 +1,45 @@ package lol.bai.megane.api.provider; +import lol.bai.megane.api.registry.ClientRegistrar; +import net.minecraft.fluid.Fluid; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +/** + * Base class of dynamic fluid information provider. + * This decides how fluid info will be displayed on client. + *

+ * Register implementations with {@link ClientRegistrar#addFluidInfo} + * + * @param type of {@link Fluid} this provider for. + */ public abstract class FluidInfoProvider extends AbstractProvider { @Nullable private NbtCompound nbt; + /** + * Returns whether this provider decides the look of the info. + */ public boolean hasFluidInfo() { return true; } + /** + * Returns the color of the fluid + */ public abstract int getColor(); + /** + * Returns the name of the fluid. + */ public abstract Text getName(); + /** + * Returns the nbt of the fluid, if any. + */ @Nullable protected final NbtCompound getNbt() { return nbt; diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidProvider.java index 9e72748..b8de0b4 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/FluidProvider.java @@ -1,20 +1,41 @@ package lol.bai.megane.api.provider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.fluid.Fluid; import net.minecraft.nbt.NbtCompound; import org.jetbrains.annotations.Nullable; +/** + * Base class for fluid provider. + *

+ * Register implementations with {@link CommonRegistrar#addFluid} + * + * @param type of {@link BlockEntity} this provider for. + */ public abstract class FluidProvider extends AbstractProvider { + /** + * Returns whether the object has fluids. + */ public boolean hasFluids() { return true; } + /** + * Returns the fluid slot count of this object + */ public abstract int getSlotCount(); + /** + * Returns the fluid of specified slot, or {@code null} if empty. + */ @Nullable public abstract Fluid getFluid(int slot); + /** + * Returns the fluid nbt of specified slot, or {@code null} if empty. + */ @Nullable public NbtCompound getNbt(int slot) { return null; diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/ItemProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/ItemProvider.java index 857dd08..b074470 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/ItemProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/ItemProvider.java @@ -1,20 +1,38 @@ package lol.bai.megane.api.provider; import lol.bai.megane.api.provider.base.InventoryItemProvider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; /** + * Base class for item provider. + *

+ * Register implementations with {@link CommonRegistrar#addItem} + * + * @param type of {@link BlockEntity} or {@link Entity} this provider for. + * * @see InventoryItemProvider */ public abstract class ItemProvider extends AbstractProvider { + /** + * Returns whether the object contains any item. + */ public boolean hasItems() { return true; } + /** + * Returns the size of the storage. + */ public abstract int getSlotCount(); + /** + * Returns the item of the specified slot. + */ @NotNull public abstract ItemStack getStack(int slot); diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/ProgressProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/ProgressProvider.java index 275f57f..9f0912c 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/ProgressProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/ProgressProvider.java @@ -1,29 +1,54 @@ package lol.bai.megane.api.provider; import lol.bai.megane.api.provider.base.SlotArrayProgressProvider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; /** + * Base class for progress provider. + *

+ * Register implementations with {@link CommonRegistrar#addProgress} + * + * @param type of {@link BlockEntity} this provider for. + * * @see SlotArrayProgressProvider */ public abstract class ProgressProvider extends AbstractProvider { + /** + * Returns whether the object has a current progress going. + */ public boolean hasProgress() { return true; } + /** + * Returns the size of input slots. + */ public abstract int getInputSlotCount(); + /** + * Returns the size of output slots. + */ public abstract int getOutputSlotCount(); + /** + * Returns the stack for specified input slot. + */ @NotNull public abstract ItemStack getInputStack(int slot); + /** + * Returns the stack for specified output slot. + */ @NotNull public abstract ItemStack getOutputStack(int slot); /** + * Returns the percentage of the progress. + * * @see #currentPercentage(double, double) * @see #remainingPercentage(double, double) */ diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/base/InventoryItemProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/base/InventoryItemProvider.java index 558a696..874e3d8 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/base/InventoryItemProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/base/InventoryItemProvider.java @@ -1,15 +1,29 @@ package lol.bai.megane.api.provider.base; +import javax.swing.text.html.parser.Entity; + import lol.bai.megane.api.provider.ItemProvider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Base class for {@link Inventory} based item provider. + *

+ * Register implementations with {@link CommonRegistrar#addItem} + * + * @param type of {@link BlockEntity} or {@link Entity} this provider for. + */ public abstract class InventoryItemProvider extends ItemProvider { private Inventory inventory; + /** + * Returns the {@link Inventory instance} of the object. + */ @Nullable protected abstract Inventory getInventory(); diff --git a/module-base/api/src/main/java/lol/bai/megane/api/provider/base/SlotArrayProgressProvider.java b/module-base/api/src/main/java/lol/bai/megane/api/provider/base/SlotArrayProgressProvider.java index 6ea0721..278223d 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/provider/base/SlotArrayProgressProvider.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/provider/base/SlotArrayProgressProvider.java @@ -1,15 +1,33 @@ package lol.bai.megane.api.provider.base; import lol.bai.megane.api.provider.ProgressProvider; +import lol.bai.megane.api.registry.CommonRegistrar; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; +/** + * Base class for slot array based progress provider. + *

+ * Register implementations with {@link CommonRegistrar#addProgress} + * + * @param type of {@link BlockEntity} this provider for. + */ public abstract class SlotArrayProgressProvider extends ProgressProvider { + /** + * Returns the input slot indexes. + */ protected abstract int[] getInputSlots(); + /** + * Returns the output slot indexes. + */ protected abstract int[] getOutputSlots(); + /** + * Returns the stack for the specified slot. + */ @NotNull protected abstract ItemStack getStack(int slot); diff --git a/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java b/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java index 71ec318..c53a56e 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java @@ -10,22 +10,70 @@ public interface ClientRegistrar { int DEFAULT_PRIORITY = 1000; + /** + * Registers static energy info for specified namespace. + * + * @param namespace the namespace of the block entity type + * @param color the energy bar color + * @param unit the energy unit + * @param name the energy name + */ void addEnergyInfo(String namespace, int color, String unit, Text name); + /** + * Registers static energy info for specified namespace. + * + * @param namespace the namespace of the block entity type + * @param color the energy bar color + * @param unit the energy unit + */ default void addEnergyInfo(String namespace, int color, String unit) { addEnergyInfo(namespace, color, unit, new TranslatableText("megane.energy")); } + /** + * Registers dynamic energy info for specified block entity class. + * + * @param clazz the class of block entity + * @param provider the provider instance + * @param priority the priority of the provider + */ void addEnergyInfo(Class clazz, EnergyInfoProvider provider, int priority); + /** + * Registers dynamic energy info for specified block entity class. + * + * @param clazz the class of block entity + * @param provider the provider instance + */ default void addEnergyInfo(Class clazz, EnergyInfoProvider provider) { addEnergyInfo(clazz, provider, DEFAULT_PRIORITY); } + /** + * Registers static fluid info for specified fluid. + * + * @param fluid the fluid + * @param color the fluid bar color + * @param name the fluid name + */ void addFluidInfo(Fluid fluid, int color, Text name); + /** + * Registers dynamic fluid info for specified fluid class. + * + * @param clazz the class of the fluid + * @param provider the provider instance + * @param priority the priority of the provider + */ void addFluidInfo(Class clazz, FluidInfoProvider provider, int priority); + /** + * Registers dynamic fluid info for specified fluid class. + * + * @param clazz the class of the fluid + * @param provider the provider instance + */ default void addFluidInfo(Class clazz, FluidInfoProvider provider) { addFluidInfo(clazz, provider, DEFAULT_PRIORITY); } diff --git a/module-base/api/src/main/java/lol/bai/megane/api/registry/CommonRegistrar.java b/module-base/api/src/main/java/lol/bai/megane/api/registry/CommonRegistrar.java index 8e7fdf7..9d3425f 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/registry/CommonRegistrar.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/registry/CommonRegistrar.java @@ -11,34 +11,105 @@ public interface CommonRegistrar { int DEFAULT_PRIORITY = 1000; + /** + * Registers energy provider for specified block entity class + * + * @param priority the priority of the provider + * @param clazz the block entity class + * @param provider the provider instance + */ void addEnergy(int priority, Class clazz, EnergyProvider provider); + /** + * Registers energy provider for specified block entity class + * + * @param clazz the block entity class + * @param provider the provider instance + */ default void addEnergy(Class clazz, EnergyProvider provider) { addEnergy(DEFAULT_PRIORITY, clazz, provider); } + /** + * Registers fluid provider for specified block entity class + * + * @param priority the priority of the provider + * @param clazz the block entity class + * @param provider the provider instance + */ void addFluid(int priority, Class clazz, FluidProvider provider); + /** + * Registers fluid provider for specified block entity class + * + * @param clazz the block entity class + * @param provider the provider instance + */ default void addFluid(Class clazz, FluidProvider provider) { addFluid(DEFAULT_PRIORITY, clazz, provider); } + /** + * Registers cauldron fluid provider for specified block + * + * @param block the cauldron block + * @param provider the provider instance + */ void addCauldron(Block block, CauldronProvider provider); + /** + * Registers cauldron fluid provider for specified block class + * + * @param priority the priority of the provider + * @param clazz the block class + * @param provider the provider instance + */ void addCauldron(int priority, Class clazz, CauldronProvider provider); + /** + * Registers cauldron fluid provider for specified block class + * + * @param clazz the block class + * @param provider the provider instance + */ default void addCauldron(Class clazz, CauldronProvider provider) { addCauldron(DEFAULT_PRIORITY, clazz, provider); } + /** + * Registers item provider for specified block or entity class + * + * @param priority the priority of the provider + * @param clazz the block or entity class + * @param provider the provider instance + */ void addItem(int priority, Class clazz, ItemProvider provider); + /** + * Registers item provider for specified block or entity class + * + * @param clazz the block or entity class + * @param provider the provider instance + */ default void addItem(Class clazz, ItemProvider provider) { addItem(DEFAULT_PRIORITY, clazz, provider); } + /** + * Registers progress provider for specified block class + * + * @param priority the priority of the provider + * @param clazz the block class + * @param provider the provider instance + */ void addProgress(int priority, Class clazz, ProgressProvider provider); + /** + * Registers progress provider for specified block class + * + * @param clazz the block class + * @param provider the provider instance + */ default void addProgress(Class clazz, ProgressProvider provider) { addProgress(DEFAULT_PRIORITY, clazz, provider); } From cad669559cb1922a49d72557a9509a682e33d56d Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 17 Jul 2022 16:50:01 +0700 Subject: [PATCH 2/5] fix tech reborn fluid showing as air (cherry picked from commit 7f7cd39bc1e5c7d398f73d79ce91d0dd354e9d65) --- .../bai/megane/api/registry/ClientRegistrar.java | 8 ++++++++ .../bai/megane/runtime/registry/Registrar.java | 5 +++++ .../techreborn/provider/ModFluidInfoProvider.java | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java b/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java index c53a56e..a3ebff0 100644 --- a/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java +++ b/module-base/api/src/main/java/lol/bai/megane/api/registry/ClientRegistrar.java @@ -59,6 +59,14 @@ default void addEnergyInfo(Class clazz, EnergyInfoProvider provider) { */ void addFluidInfo(Fluid fluid, int color, Text name); + /** + * Registers static fluid info for specified fluid. + * + * @param fluid the fluid + * @param provider the provider instance + */ + void addFluidInfo(T fluid, FluidInfoProvider provider); + /** * Registers dynamic fluid info for specified fluid class. * diff --git a/module-base/runtime/src/main/java/lol/bai/megane/runtime/registry/Registrar.java b/module-base/runtime/src/main/java/lol/bai/megane/runtime/registry/Registrar.java index e816f9e..3c00deb 100644 --- a/module-base/runtime/src/main/java/lol/bai/megane/runtime/registry/Registrar.java +++ b/module-base/runtime/src/main/java/lol/bai/megane/runtime/registry/Registrar.java @@ -103,4 +103,9 @@ public Text getName() { } }); } + + @Override + public void addFluidInfo(T fluid, FluidInfoProvider provider) { + FLUID_INFO.add(fluid, provider); + } } diff --git a/module-compat/tech-reborn/src/main/java/lol/bai/megane/module/techreborn/provider/ModFluidInfoProvider.java b/module-compat/tech-reborn/src/main/java/lol/bai/megane/module/techreborn/provider/ModFluidInfoProvider.java index 73c042e..02fb864 100644 --- a/module-compat/tech-reborn/src/main/java/lol/bai/megane/module/techreborn/provider/ModFluidInfoProvider.java +++ b/module-compat/tech-reborn/src/main/java/lol/bai/megane/module/techreborn/provider/ModFluidInfoProvider.java @@ -1,6 +1,8 @@ package lol.bai.megane.module.techreborn.provider; +import lol.bai.megane.api.provider.FluidInfoProvider; import lol.bai.megane.api.registry.ClientRegistrar; +import net.minecraft.text.Text; import techreborn.init.ModFluids; import static techreborn.init.ModFluids.BERYLLIUM; @@ -86,8 +88,17 @@ public void registerAll() { } private void register(ModFluids modFluid, int color) { - registrar.addFluidInfo(modFluid.getFluid(), color, modFluid.getBlock().getName()); - registrar.addFluidInfo(modFluid.getFlowingFluid(), color, modFluid.getBlock().getName()); + registrar.addFluidInfo(modFluid.getFluid(), new FluidInfoProvider<>() { + @Override + public int getColor() { + return color; + } + + @Override + public Text getName() { + return modFluid.getBlock().getName(); + } + }); } } From 05561083df5971fd9c734c4daefd99f39077a8d0 Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 17 Jul 2022 18:37:52 +0700 Subject: [PATCH 3/5] modern dynamics (cherry picked from commit e5e0a38fc73dab70023814c1d640b97bcf4b27c7) --- .editorconfig | 3 ++ build.gradle.kts | 9 ++++- buildSrc/src/main/kotlin/Dependencies.kt | 1 + buildSrc/src/main/kotlin/Uploads.kt | 2 + conflict.mapping | 2 + curseforge.html | 1 + .../modern-dynamics/build.gradle.kts | 5 +++ .../moderndynamics/MeganeModernDynamics.java | 19 +++++++++ .../mixin/AccessorItemHost.java | 16 ++++++++ .../provider/PipeFluidProvider.java | 39 +++++++++++++++++++ .../provider/PipeItemProvider.java | 34 ++++++++++++++++ .../src/main/resources/fabric.mod.json | 21 ++++++++++ .../megane-modern-dynamics.mixins.json | 12 ++++++ settings.gradle.kts | 1 + 14 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 conflict.mapping create mode 100644 module-compat/modern-dynamics/build.gradle.kts create mode 100644 module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/MeganeModernDynamics.java create mode 100644 module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/mixin/AccessorItemHost.java create mode 100644 module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java create mode 100644 module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeItemProvider.java create mode 100644 module-compat/modern-dynamics/src/main/resources/fabric.mod.json create mode 100644 module-compat/modern-dynamics/src/main/resources/megane-modern-dynamics.mixins.json diff --git a/.editorconfig b/.editorconfig index f68e566..d0225ef 100644 --- a/.editorconfig +++ b/.editorconfig @@ -483,3 +483,6 @@ ij_yaml_spaces_within_brackets = true indent_size = 2 tab_width = 2 ij_continuation_indent_size = 2 + +[*.mapping] +indent_style = tab diff --git a/build.gradle.kts b/build.gradle.kts index e64bd67..e7b866f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,12 @@ allprojects { dependencies { minecraft(deps.minecraft) - mappings(deps.yarn) + mappings(loom.layered { + mappings(deps.yarn) + mappings(rootProject.file("conflict.mapping")) { + enigmaMappings() + } + }) modImplementation(deps.fabricLoader) } @@ -153,6 +158,7 @@ afterEvaluate { optional.project(mrIds.create) optional.project(mrIds.extraGen) optional.project(mrIds.kibe) + optional.project(mrIds.modernDynamics) } } @@ -183,6 +189,7 @@ afterEvaluate { addOptional(cfSlugs.indrev) addOptional(cfSlugs.kibe) addOptional(cfSlugs.lba) + addOptional(cfSlugs.modernDynamics) addOptional(cfSlugs.rebornCore) addOptional(cfSlugs.techReborn) addOptional(cfSlugs.wirelessNet) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 3167444..bd35aad 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -35,6 +35,7 @@ object deps { val alloyForgery = "curse.maven:alloy-forgery-438718:3758381" val owo = "io.wispforest:owo-lib:0.7.2+1.18" val create = "com.simibubi:Create:mc1.18.2_v0.4.1+628" + val modernDynamics = "curse.maven:modern-dynamics-552758:3875167" object lba { val core = "alexiil.mc.lib:libblockattributes-core:0.10.2" diff --git a/buildSrc/src/main/kotlin/Uploads.kt b/buildSrc/src/main/kotlin/Uploads.kt index f2481b8..4d6e3fd 100644 --- a/buildSrc/src/main/kotlin/Uploads.kt +++ b/buildSrc/src/main/kotlin/Uploads.kt @@ -12,6 +12,7 @@ object cfSlugs { val indrev = "industrial-revolution" val kibe = "kibe" val lba = "libblockattributes" + val modernDynamics = "modern-dynamics" val rebornCore = "reborncore" val techReborn = "techreborn" val wirelessNet = "wireless-networks" @@ -26,4 +27,5 @@ object mrIds { val create = "Xbc0uyRg" val extraGen = "VXtwLg17" val kibe = "OvlwmUdC" + val modernDynamics = "fMpvLrnF" } diff --git a/conflict.mapping b/conflict.mapping new file mode 100644 index 0000000..113095b --- /dev/null +++ b/conflict.mapping @@ -0,0 +1,2 @@ +CLASS net/minecraft/class_1735 + METHOD method_7682 yarn_isEnabled ()Z diff --git a/curseforge.html b/curseforge.html index 099efdf..f62c857 100644 --- a/curseforge.html +++ b/curseforge.html @@ -28,6 +28,7 @@

megane

         • Lib Block Attributes
+ • Modern Dynamics
Modern Industrialization
Reborn Core
Team Reborn Energy
diff --git a/module-compat/modern-dynamics/build.gradle.kts b/module-compat/modern-dynamics/build.gradle.kts new file mode 100644 index 0000000..d8594bc --- /dev/null +++ b/module-compat/modern-dynamics/build.gradle.kts @@ -0,0 +1,5 @@ +dependencies { + modImpl(deps.modernDynamics) + modImpl(deps.fabricApi) + modImpl(deps.trEnergy) +} diff --git a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/MeganeModernDynamics.java b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/MeganeModernDynamics.java new file mode 100644 index 0000000..6a4374a --- /dev/null +++ b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/MeganeModernDynamics.java @@ -0,0 +1,19 @@ +package lol.bai.megane.module.moderndynamics; + +import dev.technici4n.moderndynamics.pipe.FluidPipeBlockEntity; +import dev.technici4n.moderndynamics.pipe.ItemPipeBlockEntity; +import lol.bai.megane.api.MeganeModule; +import lol.bai.megane.api.registry.CommonRegistrar; +import lol.bai.megane.module.moderndynamics.provider.PipeFluidProvider; +import lol.bai.megane.module.moderndynamics.provider.PipeItemProvider; + +@SuppressWarnings("unused") +public class MeganeModernDynamics implements MeganeModule { + + @Override + public void registerCommon(CommonRegistrar registrar) { + registrar.addFluid(FluidPipeBlockEntity.class, new PipeFluidProvider()); + registrar.addItem(ItemPipeBlockEntity.class, new PipeItemProvider()); + } + +} diff --git a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/mixin/AccessorItemHost.java b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/mixin/AccessorItemHost.java new file mode 100644 index 0000000..edecb49 --- /dev/null +++ b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/mixin/AccessorItemHost.java @@ -0,0 +1,16 @@ +package lol.bai.megane.module.moderndynamics.mixin; + +import java.util.List; + +import dev.technici4n.moderndynamics.network.item.ItemHost; +import dev.technici4n.moderndynamics.network.item.TravelingItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ItemHost.class) +public interface AccessorItemHost { + + @Accessor + List getTravelingItems(); + +} diff --git a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java new file mode 100644 index 0000000..5e31b4a --- /dev/null +++ b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java @@ -0,0 +1,39 @@ +package lol.bai.megane.module.moderndynamics.provider; + +import dev.technici4n.moderndynamics.network.fluid.FluidHost; +import dev.technici4n.moderndynamics.pipe.FluidPipeBlockEntity; +import lol.bai.megane.api.provider.FluidProvider; +import net.minecraft.fluid.Fluid; +import org.jetbrains.annotations.Nullable; + +@SuppressWarnings("UnstableApiUsage") +public class PipeFluidProvider extends FluidProvider { + + FluidHost host; + + @Override + protected void init() { + host = ((FluidHost) getObject().getHosts()[0]); + } + + @Override + public int getSlotCount() { + return 1; + } + + @Override + public @Nullable Fluid getFluid(int slot) { + return host.getVariant().getFluid(); + } + + @Override + public double getStored(int slot) { + return droplets(host.getAmount()); + } + + @Override + public double getMax(int slot) { + return 1000; + } + +} diff --git a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeItemProvider.java b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeItemProvider.java new file mode 100644 index 0000000..8e2667d --- /dev/null +++ b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeItemProvider.java @@ -0,0 +1,34 @@ +package lol.bai.megane.module.moderndynamics.provider; + +import java.util.List; + +import com.google.common.primitives.Ints; +import dev.technici4n.moderndynamics.network.item.TravelingItem; +import dev.technici4n.moderndynamics.pipe.ItemPipeBlockEntity; +import lol.bai.megane.api.provider.ItemProvider; +import lol.bai.megane.module.moderndynamics.mixin.AccessorItemHost; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("UnstableApiUsage") +public class PipeItemProvider extends ItemProvider { + + List travelingItems; + + @Override + protected void init() { + travelingItems = ((AccessorItemHost) getObject().getHosts()[0]).getTravelingItems(); + } + + @Override + public int getSlotCount() { + return travelingItems.size(); + } + + @Override + public @NotNull ItemStack getStack(int slot) { + TravelingItem item = travelingItems.get(slot); + return item.variant.toStack(Ints.saturatedCast(item.amount)); + } + +} diff --git a/module-compat/modern-dynamics/src/main/resources/fabric.mod.json b/module-compat/modern-dynamics/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..98c9e29 --- /dev/null +++ b/module-compat/modern-dynamics/src/main/resources/fabric.mod.json @@ -0,0 +1,21 @@ +{ + "schemaVersion": 1, + "id" : "megane-modern-dynamics", + "version" : "${version}", + "authors" : ["deirn"], + "license" : "MIT", + "icon" : "assets/megane/icon.png", + "mixins" : ["megane-modern-dynamics.mixins.json"], + "depends" : { + "megane-api" : "*", + "moderndynamics": "*" + }, + "custom" : { + "megane:modules": [ + "lol.bai.megane.module.moderndynamics.MeganeModernDynamics" + ], + "modmenu" : { + "parent": "megane" + } + } +} diff --git a/module-compat/modern-dynamics/src/main/resources/megane-modern-dynamics.mixins.json b/module-compat/modern-dynamics/src/main/resources/megane-modern-dynamics.mixins.json new file mode 100644 index 0000000..b2118ff --- /dev/null +++ b/module-compat/modern-dynamics/src/main/resources/megane-modern-dynamics.mixins.json @@ -0,0 +1,12 @@ +{ + "required" : true, + "minVersion" : "0.8", + "package" : "lol.bai.megane.module.moderndynamics.mixin", + "compatibilityLevel": "JAVA_8", + "injectors" : { + "defaultRequire": 1 + }, + "mixins" : [ + "AccessorItemHost" + ] +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 6c460c7..0be35bd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,7 @@ compat("fabric-transfer") compat("industrial-revolution") compat("kibe") compat("lib-block-attributes") +compat("modern-dynamics") compat("reborn-core") compat("reborn-energy") compat("tech-reborn") From 017413372302ae3cb94c62a8c6dad420bafbb4ca Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 17 Jul 2022 19:08:06 +0700 Subject: [PATCH 4/5] luggage (cherry picked from commit 5e5cf6e0a37586ec03bd2c56f5d2597912cb235a) --- build.gradle.kts | 1 + buildSrc/src/main/kotlin/Dependencies.kt | 1 + buildSrc/src/main/kotlin/Uploads.kt | 1 + curseforge.html | 3 ++- module-compat/luggage/build.gradle.kts | 4 ++++ .../megane/module/luggage/MeganeLuggage.java | 16 +++++++++++++++ .../luggage/provider/LuggageItemProvider.java | 15 ++++++++++++++ .../src/main/resources/fabric.mod.json | 20 +++++++++++++++++++ settings.gradle.kts | 1 + 9 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 module-compat/luggage/build.gradle.kts create mode 100644 module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/MeganeLuggage.java create mode 100644 module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/provider/LuggageItemProvider.java create mode 100644 module-compat/luggage/src/main/resources/fabric.mod.json diff --git a/build.gradle.kts b/build.gradle.kts index e7b866f..4964ae0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -189,6 +189,7 @@ afterEvaluate { addOptional(cfSlugs.indrev) addOptional(cfSlugs.kibe) addOptional(cfSlugs.lba) + addOptional(cfSlugs.luggage) addOptional(cfSlugs.modernDynamics) addOptional(cfSlugs.rebornCore) addOptional(cfSlugs.techReborn) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index bd35aad..a291b19 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -36,6 +36,7 @@ object deps { val owo = "io.wispforest:owo-lib:0.7.2+1.18" val create = "com.simibubi:Create:mc1.18.2_v0.4.1+628" val modernDynamics = "curse.maven:modern-dynamics-552758:3875167" + val luggage = "curse.maven:luggage-594709:3870818" object lba { val core = "alexiil.mc.lib:libblockattributes-core:0.10.2" diff --git a/buildSrc/src/main/kotlin/Uploads.kt b/buildSrc/src/main/kotlin/Uploads.kt index 4d6e3fd..1286e48 100644 --- a/buildSrc/src/main/kotlin/Uploads.kt +++ b/buildSrc/src/main/kotlin/Uploads.kt @@ -12,6 +12,7 @@ object cfSlugs { val indrev = "industrial-revolution" val kibe = "kibe" val lba = "libblockattributes" + val luggage = "luggage" val modernDynamics = "modern-dynamics" val rebornCore = "reborncore" val techReborn = "techreborn" diff --git a/curseforge.html b/curseforge.html index f62c857..5845889 100644 --- a/curseforge.html +++ b/curseforge.html @@ -24,10 +24,11 @@

megane

Extra Generators
Industrial Revolution
Kibe
+ • Lib Block Attributes
         - • Lib Block Attributes
+ • Luggage
Modern Dynamics
Modern Industrialization
Reborn Core
diff --git a/module-compat/luggage/build.gradle.kts b/module-compat/luggage/build.gradle.kts new file mode 100644 index 0000000..2b7908c --- /dev/null +++ b/module-compat/luggage/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + modImpl(deps.luggage) + modImpl(deps.fabricApi) +} diff --git a/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/MeganeLuggage.java b/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/MeganeLuggage.java new file mode 100644 index 0000000..cb1d282 --- /dev/null +++ b/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/MeganeLuggage.java @@ -0,0 +1,16 @@ +package lol.bai.megane.module.luggage; + +import com.gizmo.luggage.entity.LuggageEntity; +import lol.bai.megane.api.MeganeModule; +import lol.bai.megane.api.registry.CommonRegistrar; +import lol.bai.megane.module.luggage.provider.LuggageItemProvider; + +@SuppressWarnings("unused") +public class MeganeLuggage implements MeganeModule { + + @Override + public void registerCommon(CommonRegistrar registrar) { + registrar.addItem(LuggageEntity.class, new LuggageItemProvider()); + } + +} diff --git a/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/provider/LuggageItemProvider.java b/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/provider/LuggageItemProvider.java new file mode 100644 index 0000000..6cce2e5 --- /dev/null +++ b/module-compat/luggage/src/main/java/lol/bai/megane/module/luggage/provider/LuggageItemProvider.java @@ -0,0 +1,15 @@ +package lol.bai.megane.module.luggage.provider; + +import com.gizmo.luggage.entity.LuggageEntity; +import lol.bai.megane.api.provider.base.InventoryItemProvider; +import net.minecraft.inventory.Inventory; +import org.jetbrains.annotations.Nullable; + +public class LuggageItemProvider extends InventoryItemProvider { + + @Override + protected @Nullable Inventory getInventory() { + return getObject().getInventory(); + } + +} diff --git a/module-compat/luggage/src/main/resources/fabric.mod.json b/module-compat/luggage/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..13055a9 --- /dev/null +++ b/module-compat/luggage/src/main/resources/fabric.mod.json @@ -0,0 +1,20 @@ +{ + "schemaVersion": 1, + "id" : "megane-luggage", + "version" : "${version}", + "authors" : ["deirn"], + "license" : "MIT", + "icon" : "assets/megane/icon.png", + "depends" : { + "megane-api": "*", + "luggage" : "*" + }, + "custom" : { + "megane:modules": [ + "lol.bai.megane.module.luggage.MeganeLuggage" + ], + "modmenu" : { + "parent": "megane" + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 0be35bd..59169a3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,7 @@ compat("fabric-transfer") compat("industrial-revolution") compat("kibe") compat("lib-block-attributes") +compat("luggage") compat("modern-dynamics") compat("reborn-core") compat("reborn-energy") From 1c6bb693607120ed8f7e02ed42d27e1b0925264f Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 17 Jul 2022 19:57:52 +0700 Subject: [PATCH 5/5] add nbt support for modern dynamics pipe --- .../module/moderndynamics/provider/PipeFluidProvider.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java index 5e31b4a..312be29 100644 --- a/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java +++ b/module-compat/modern-dynamics/src/main/java/lol/bai/megane/module/moderndynamics/provider/PipeFluidProvider.java @@ -4,6 +4,7 @@ import dev.technici4n.moderndynamics.pipe.FluidPipeBlockEntity; import lol.bai.megane.api.provider.FluidProvider; import net.minecraft.fluid.Fluid; +import net.minecraft.nbt.NbtCompound; import org.jetbrains.annotations.Nullable; @SuppressWarnings("UnstableApiUsage") @@ -26,6 +27,11 @@ public int getSlotCount() { return host.getVariant().getFluid(); } + @Override + public @Nullable NbtCompound getNbt(int slot) { + return host.getVariant().getNbt(); + } + @Override public double getStored(int slot) { return droplets(host.getAmount());