Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nature's Aura compat #18

Merged
merged 3 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/cleanroommc/multiblocked/MbdConfig.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MultiblockCapability<?>, ImmutableList<Tuple<Object, Float>>> inputBuilder = new ImmutableMap.Builder<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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<Integer> {

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<? extends Integer> 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<? super Integer> createContentWidget() {
return new NumberContentWidget().setContentTexture(new TextTexture("NA", color)).setUnit("NaturesAura");
}

public static class ManaBotainaCapabilityProxy extends CapabilityProxy<Integer> {

public ManaBotainaCapabilityProxy(TileEntity tileEntity) {
super(AuraMultiblockCapability.CAP, tileEntity);
}

@Override
protected List<Integer> handleRecipeInner(IO io, Recipe recipe, List<Integer> left, boolean simulate) {
World world = getTileEntity().getWorld();
BlockPos pos = getTileEntity().getPos();

int sum = left.stream().reduce(0, Integer::sum);
if (io == IO.IN) {
if (!simulate) {
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, MbdConfig.naturesAura.radius, pos);
IAuraChunk.getAuraChunk(world, spot).drainAura(pos, sum);
}
} 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;
}

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;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/multiblocked/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down