From 70352d89ce33dcb83e4aabeab5d55d0dba35e594 Mon Sep 17 00:00:00 2001 From: ikexing Date: Fri, 22 Apr 2022 18:23:07 +0800 Subject: [PATCH 1/3] Add Nature's Aura compat --- build.gradle | 1 + .../cleanroommc/multiblocked/MbdConfig.java | 10 ++ .../multiblocked/Multiblocked.java | 1 + .../api/recipe/RecipeBuilder.java | 26 ++++ .../api/registry/MbdCapabilities.java | 3 + .../capability/AuraMultiblockCapability.java | 119 ++++++++++++++++++ .../assets/multiblocked/lang/en_us.lang | 2 + 7 files changed, 162 insertions(+) create mode 100644 src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java diff --git a/build.gradle b/build.gradle index 23059cee..71b965d4 100644 --- a/build.gradle +++ b/build.gradle @@ -95,6 +95,7 @@ dependencies { deobfCompile 'curse.maven:the-one-probe-245211:2667280' deobfCompile 'curse.maven:prodigy-tech-297414:2769520' deobfCompile 'curse.maven:patchouli-306770:3162874' + deobfCompile 'curse.maven:natures-aura-306626:2882138' } sourceSets { diff --git a/src/main/java/com/cleanroommc/multiblocked/MbdConfig.java b/src/main/java/com/cleanroommc/multiblocked/MbdConfig.java index bf1e197f..4ae7d2e6 100644 --- a/src/main/java/com/cleanroommc/multiblocked/MbdConfig.java +++ b/src/main/java/com/cleanroommc/multiblocked/MbdConfig.java @@ -1,10 +1,20 @@ package com.cleanroommc.multiblocked; import net.minecraftforge.common.config.Config; +import net.minecraftforge.fml.common.Loader; @Config(modid = Multiblocked.MODID) public final class MbdConfig { + + public static NaturesAura naturesAura = Loader.isModLoaded(Multiblocked.MODID_NA) ? new NaturesAura() : null; + @Config.Comment({"location of the mbd scripts and resources.", "Default: {.../config}/multiblocked"}) @Config.RequiresMcRestart public static String location = "multiblocked"; + + public static class NaturesAura { + @Config.Comment({"set the radius of aura value consumption", "Default: 20"}) + public int radius = 20; + } + } diff --git a/src/main/java/com/cleanroommc/multiblocked/Multiblocked.java b/src/main/java/com/cleanroommc/multiblocked/Multiblocked.java index 532d13e8..4da5c2de 100644 --- a/src/main/java/com/cleanroommc/multiblocked/Multiblocked.java +++ b/src/main/java/com/cleanroommc/multiblocked/Multiblocked.java @@ -48,6 +48,7 @@ public class Multiblocked { public static final String MODID_LC = "lightningcraft"; public static final String MODID_TOP = "theoneprobe"; public static final String MODID_PRODIGY = "prodigytech"; + public static final String MODID_NA = "naturesaura"; public static final String NAME = "Multiblocked"; public static final String VERSION = "0.4.1"; public static final Logger LOGGER = LogManager.getLogger(NAME); diff --git a/src/main/java/com/cleanroommc/multiblocked/api/recipe/RecipeBuilder.java b/src/main/java/com/cleanroommc/multiblocked/api/recipe/RecipeBuilder.java index c69e6875..ed230fb5 100644 --- a/src/main/java/com/cleanroommc/multiblocked/api/recipe/RecipeBuilder.java +++ b/src/main/java/com/cleanroommc/multiblocked/api/recipe/RecipeBuilder.java @@ -421,6 +421,32 @@ public RecipeBuilder outputHotAir(float chance, int hotAir) { return output(HotAirProdigyCapability.CAP, chance, hotAir); } + @Optional.Method(modid = Multiblocked.MODID_NA) + @ZenMethod + public RecipeBuilder inputAura(int aura) { + return inputAura(1, aura); + } + + @Optional.Method(modid = Multiblocked.MODID_NA) + @ZenMethod + public RecipeBuilder outputAura(int aura) { + return outputAura(1, aura); + } + + @Optional.Method(modid = Multiblocked.MODID_NA) + @ZenMethod + public RecipeBuilder inputAura(float chance, int aura) { + keyBuilder.append(AuraMultiblockCapability.CAP.name).append(aura); + return input(AuraMultiblockCapability.CAP, chance, aura); + } + + @Optional.Method(modid = Multiblocked.MODID_NA) + @ZenMethod + public RecipeBuilder outputAura(float chance, int aura) { + keyBuilder.append(AuraMultiblockCapability.CAP.name).append(aura); + return output(AuraMultiblockCapability.CAP, chance, aura); + } + @ZenMethod public Recipe build() { ImmutableMap.Builder, ImmutableList>> inputBuilder = new ImmutableMap.Builder<>(); diff --git a/src/main/java/com/cleanroommc/multiblocked/api/registry/MbdCapabilities.java b/src/main/java/com/cleanroommc/multiblocked/api/registry/MbdCapabilities.java index 4572ea6d..f4b1716c 100644 --- a/src/main/java/com/cleanroommc/multiblocked/api/registry/MbdCapabilities.java +++ b/src/main/java/com/cleanroommc/multiblocked/api/registry/MbdCapabilities.java @@ -50,6 +50,9 @@ public static void registerCapabilities() { if (Loader.isModLoaded(Multiblocked.MODID_PRODIGY)) { registerCapability(HotAirProdigyCapability.CAP); } + if (Loader.isModLoaded(Multiblocked.MODID_NA)) { + registerCapability(AuraMultiblockCapability.CAP); + } } public static MultiblockCapability get(String s) { diff --git a/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java new file mode 100644 index 00000000..563edd2d --- /dev/null +++ b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java @@ -0,0 +1,119 @@ +package com.cleanroommc.multiblocked.common.capability; + +import com.cleanroommc.multiblocked.MbdConfig; +import com.cleanroommc.multiblocked.api.capability.IO; +import com.cleanroommc.multiblocked.api.capability.MultiblockCapability; +import com.cleanroommc.multiblocked.api.capability.proxy.CapabilityProxy; +import com.cleanroommc.multiblocked.api.gui.texture.TextTexture; +import com.cleanroommc.multiblocked.api.gui.widget.imp.recipe.ContentWidget; +import com.cleanroommc.multiblocked.api.pattern.util.BlockInfo; +import com.cleanroommc.multiblocked.api.recipe.Recipe; +import com.cleanroommc.multiblocked.common.capability.widget.NumberContentWidget; +import com.google.gson.*; +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; +import java.awt.*; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.List; + +public class AuraMultiblockCapability extends MultiblockCapability { + + public static final AuraMultiblockCapability CAP = new AuraMultiblockCapability(); + + private AuraMultiblockCapability() { + super("natures_aura", new Color(0x95EF95).getRGB()); + } + + @Override + public Integer defaultContent() { + return 200; + } + + @Override + public boolean isBlockHasCapability(@Nonnull IO io, @Nonnull TileEntity tileEntity) { + // The specific storage of aura should be in the chunk and not inside te + return true; + } + + @Override + public Integer copyInner(Integer content) { + return content; + } + + @Override + public CapabilityProxy createProxy(@Nonnull IO io, @Nonnull TileEntity tileEntity) { + return new ManaBotainaCapabilityProxy(tileEntity); + } + + @Override + public BlockInfo[] getCandidates() { + return new BlockInfo[]{ + BlockInfo.fromBlockState(Blocks.FURNACE.getDefaultState()), + BlockInfo.fromBlockState(Blocks.CHEST.getDefaultState()), + BlockInfo.fromBlockState(Blocks.HOPPER.getDefaultState()), + BlockInfo.fromBlockState(Blocks.ENDER_CHEST.getDefaultState()) + }; + } + + @Override + public Integer deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return jsonElement.getAsInt(); + } + + @Override + public JsonElement serialize(Integer integer, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(integer); + } + + @Override + public ContentWidget createContentWidget() { + return new NumberContentWidget().setContentTexture(new TextTexture("NA", color)).setUnit("NaturesAura"); + } + + public static class ManaBotainaCapabilityProxy extends CapabilityProxy { + + public ManaBotainaCapabilityProxy(TileEntity tileEntity) { + super(AuraMultiblockCapability.CAP, tileEntity); + } + + @Override + protected List handleRecipeInner(IO io, Recipe recipe, List left, boolean simulate) { + World world = getTileEntity().getWorld(); + BlockPos pos = getTileEntity().getPos(); + + int sum = left.stream().reduce(0, Integer::sum); + if (io == IO.IN) { + int cost = Math.min(IAuraChunk.getAuraInArea(world, pos, MbdConfig.naturesAura.radius), sum); + if (!simulate) { + BlockPos spot = IAuraChunk.getHighestSpot(world, pos, MbdConfig.naturesAura.radius, pos); + IAuraChunk.getAuraChunk(world, spot).drainAura(pos, sum); + } + sum -= cost; + } else if (io == IO.OUT) { + if (!simulate) { + BlockPos spot = IAuraChunk.getLowestSpot(world, pos, MbdConfig.naturesAura.radius, pos); + IAuraChunk.getAuraChunk(world, spot).storeAura(pos, sum); + } + return null; + } + return sum <= 0 ? null : Collections.singletonList(sum); + } + + int lastMana = Integer.MIN_VALUE; + + @Override + protected boolean hasInnerChanged() { + int auraInArea = IAuraChunk.getAuraInArea(getTileEntity().getWorld(), + getTileEntity().getPos(), MbdConfig.naturesAura.radius); + if (lastMana == auraInArea) return false; + lastMana = auraInArea; + return true; + } + } +} diff --git a/src/main/resources/assets/multiblocked/lang/en_us.lang b/src/main/resources/assets/multiblocked/lang/en_us.lang index 475f2d3e..9f9ea918 100644 --- a/src/main/resources/assets/multiblocked/lang/en_us.lang +++ b/src/main/resources/assets/multiblocked/lang/en_us.lang @@ -20,6 +20,8 @@ multiblocked.capability.gtce_energy=GTCE Energy gtce_energy.any.name=Available GTCE Energy Container multiblocked.capability.prodigy_hotair=ProdigyTech Hot Air prodigy_hotair.any.name=Available Hot Air Containers +multiblocked.capability.natures_aura=Nature's Aura +natures_aura.any.name=Any block containing TileEntity can be used as an IO for this capability multiblocked.content.miss=IO: %s Capability: %s miss widget From 5f94d233f2c573348dc9271a66e8b1684e58a3d0 Mon Sep 17 00:00:00 2001 From: ikexing Date: Fri, 22 Apr 2022 18:28:03 +0800 Subject: [PATCH 2/3] fix --- .../common/capability/AuraMultiblockCapability.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java index 563edd2d..692ec3bb 100644 --- a/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java +++ b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java @@ -89,12 +89,11 @@ protected List handleRecipeInner(IO io, Recipe recipe, List le int sum = left.stream().reduce(0, Integer::sum); if (io == IO.IN) { - int cost = Math.min(IAuraChunk.getAuraInArea(world, pos, MbdConfig.naturesAura.radius), sum); if (!simulate) { BlockPos spot = IAuraChunk.getHighestSpot(world, pos, MbdConfig.naturesAura.radius, pos); IAuraChunk.getAuraChunk(world, spot).drainAura(pos, sum); } - sum -= cost; + return null; } else if (io == IO.OUT) { if (!simulate) { BlockPos spot = IAuraChunk.getLowestSpot(world, pos, MbdConfig.naturesAura.radius, pos); From d3367af3d755f084b730d15e2ee9f655549e76f1 Mon Sep 17 00:00:00 2001 From: ikexing Date: Fri, 22 Apr 2022 18:28:55 +0800 Subject: [PATCH 3/3] a return.. --- .../common/capability/AuraMultiblockCapability.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java index 692ec3bb..7f8feabc 100644 --- a/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java +++ b/src/main/java/com/cleanroommc/multiblocked/common/capability/AuraMultiblockCapability.java @@ -93,15 +93,13 @@ protected List handleRecipeInner(IO io, Recipe recipe, List le BlockPos spot = IAuraChunk.getHighestSpot(world, pos, MbdConfig.naturesAura.radius, pos); IAuraChunk.getAuraChunk(world, spot).drainAura(pos, sum); } - return null; } else if (io == IO.OUT) { if (!simulate) { BlockPos spot = IAuraChunk.getLowestSpot(world, pos, MbdConfig.naturesAura.radius, pos); IAuraChunk.getAuraChunk(world, spot).storeAura(pos, sum); } - return null; } - return sum <= 0 ? null : Collections.singletonList(sum); + return null; } int lastMana = Integer.MIN_VALUE;