-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
405 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/MeganeMekaninsm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
package lol.bai.megane.module.mekanism; | ||
|
||
import lol.bai.megane.module.mekanism.provider.ChemicalProvider; | ||
import lol.bai.megane.module.mekanism.provider.FluidProvider; | ||
import lol.bai.megane.module.mekanism.provider.MultiblockProvider; | ||
import lol.bai.megane.module.mekanism.provider.StrictEnergyProvider; | ||
import mcp.mobius.waila.api.IRegistrar; | ||
import mcp.mobius.waila.api.IWailaPlugin; | ||
import mcp.mobius.waila.api.TooltipPosition; | ||
import mcp.mobius.waila.api.data.EnergyData; | ||
import mekanism.common.lib.multiblock.IMultiblockBase; | ||
import mekanism.common.tile.base.TileEntityUpdateable; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
|
||
public class MeganeMekaninsm implements IWailaPlugin { | ||
|
||
public static final ResourceLocation CONFIG_SHOW_CHEMICALS = id("chemical"); | ||
|
||
public static ResourceLocation id(String path) { | ||
return new ResourceLocation("megane", "mekanism." + path); | ||
} | ||
|
||
@Override | ||
public void register(IRegistrar registrar) { | ||
EnergyData.describe("mekanism").color(0x3CFE9A); | ||
|
||
registrar.addFeatureConfig(CONFIG_SHOW_CHEMICALS, false); | ||
registrar.addDataType(ChemicalProvider.DATA, ChemicalProvider.Data.class, ChemicalProvider.Data::new); | ||
registrar.addBlockData(new ChemicalProvider.Blocker(), BlockEntity.class, 0); | ||
var chemicalProvider = new ChemicalProvider(); | ||
registrar.addBlockData(chemicalProvider, BlockEntity.class, 1500); | ||
registrar.addComponent(chemicalProvider, TooltipPosition.BODY, BlockEntity.class, 600); | ||
|
||
registrar.addBlockData(new StrictEnergyProvider(), BlockEntity.class, 1500); | ||
|
||
var fluidProvider = new FluidProvider(); | ||
registrar.addBlockData(fluidProvider, TileEntityUpdateable.class); | ||
|
||
registrar.addBlockData(new MultiblockProvider(fluidProvider), IMultiblockBase.class, 900); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...rge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessLookingAtUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package lol.bai.megane.module.mekanism.mixin; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import mekanism.api.chemical.Chemical; | ||
import mekanism.api.chemical.ChemicalStack; | ||
import mekanism.api.chemical.IChemicalHandler; | ||
import mekanism.api.chemical.IChemicalTank; | ||
import mekanism.api.chemical.merged.MergedChemicalTank; | ||
import mekanism.api.text.ILangEntry; | ||
import mekanism.common.capabilities.merged.MergedTank; | ||
import mekanism.common.integration.lookingat.LookingAtHelper; | ||
import mekanism.common.integration.lookingat.LookingAtUtils; | ||
import mekanism.common.lib.multiblock.MultiblockData; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.fluids.capability.IFluidHandler; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(LookingAtUtils.class) | ||
public interface AccessLookingAtUtils { | ||
|
||
@Invoker("getMultiblock") | ||
static @Nullable MultiblockData megane_getMultiblock(BlockEntity tile) { | ||
throw new AssertionError("mixin"); | ||
} | ||
|
||
@Invoker("displayFluid") | ||
static void megane_displayFluid(LookingAtHelper info, IFluidHandler fluidHandler) { | ||
|
||
} | ||
|
||
@Invoker("addInfo") | ||
static < | ||
CHEMICAL extends Chemical<CHEMICAL>, | ||
STACK extends ChemicalStack<CHEMICAL>, | ||
TANK extends IChemicalTank<CHEMICAL, STACK>, | ||
HANDLER extends IChemicalHandler<CHEMICAL, STACK> | ||
> | ||
void megane_addInfo( | ||
BlockEntity tile, | ||
@Nullable MultiblockData structure, | ||
Capability<HANDLER> capability, | ||
Function<MultiblockData, List<TANK>> multiBlockToTanks, | ||
LookingAtHelper info, | ||
ILangEntry langEntry, | ||
MergedChemicalTank.Current matchingCurrent, | ||
MergedTank.CurrentType matchingCurrentType) { | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/MixinMekanismWTHITPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lol.bai.megane.module.mekanism.mixin; | ||
|
||
import mcp.mobius.waila.api.IRegistrar; | ||
import mekanism.common.integration.lookingat.wthit.MekanismWTHITPlugin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(MekanismWTHITPlugin.class) | ||
public class MixinMekanismWTHITPlugin { | ||
|
||
@Unique | ||
private static final Logger megane_LOGGER = LoggerFactory.getLogger("MixinMekanismWTHITPlugin"); | ||
|
||
@Inject(method = "register", at = @At("HEAD"), remap = false, cancellable = true) | ||
private void megane_disable(IRegistrar registration, CallbackInfo ci) { | ||
megane_LOGGER.info("[megane-mekanism] Disabled Mekanism's builtin WTHIT compatibility in favor of Megane's"); | ||
ci.cancel(); | ||
} | ||
|
||
} |
148 changes: 148 additions & 0 deletions
148
...orge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/ChemicalProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package lol.bai.megane.module.mekanism.provider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import lol.bai.megane.module.mekanism.MeganeMekaninsm; | ||
import lol.bai.megane.module.mekanism.mixin.AccessLookingAtUtils; | ||
import mcp.mobius.waila.api.IBlockAccessor; | ||
import mcp.mobius.waila.api.IBlockComponentProvider; | ||
import mcp.mobius.waila.api.IData; | ||
import mcp.mobius.waila.api.IDataProvider; | ||
import mcp.mobius.waila.api.IDataWriter; | ||
import mcp.mobius.waila.api.IPluginConfig; | ||
import mcp.mobius.waila.api.IServerAccessor; | ||
import mcp.mobius.waila.api.ITooltip; | ||
import mcp.mobius.waila.api.WailaHelper; | ||
import mcp.mobius.waila.api.component.PairComponent; | ||
import mcp.mobius.waila.api.component.SpriteBarComponent; | ||
import mcp.mobius.waila.api.component.WrappedComponent; | ||
import mcp.mobius.waila.api.data.FluidData; | ||
import mcp.mobius.waila.api.data.FluidData.Unit; | ||
import mekanism.api.chemical.ChemicalStack; | ||
import mekanism.api.chemical.ChemicalType; | ||
import mekanism.api.chemical.ChemicalUtils; | ||
import mekanism.api.chemical.merged.MergedChemicalTank; | ||
import mekanism.api.math.FloatingLong; | ||
import mekanism.client.render.MekanismRenderer; | ||
import mekanism.common.MekanismLang; | ||
import mekanism.common.capabilities.Capabilities; | ||
import mekanism.common.capabilities.merged.MergedTank; | ||
import mekanism.common.integration.lookingat.LookingAtHelper; | ||
import mekanism.common.lib.multiblock.MultiblockData; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ChemicalProvider implements IBlockComponentProvider, IDataProvider<BlockEntity> { | ||
|
||
public static final ResourceLocation DATA = MeganeMekaninsm.id("chemical"); | ||
|
||
private static final String INFINITE = "∞"; | ||
|
||
@Override | ||
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { | ||
var data = accessor.getData().get(Data.class); | ||
if (data == null || !config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_CHEMICALS)) return; | ||
|
||
var displayUnit = config.<Unit>getEnum(FluidData.CONFIG_DISPLAY_UNIT); | ||
|
||
for (var tank : data.tanks) { | ||
var stack = tank.stack; | ||
if (stack.isEmpty()) continue; | ||
|
||
var stored = stack.getAmount(); | ||
var capacity = tank.capacity; | ||
var ratio = Double.isInfinite(capacity) ? 1f : (float) stored / capacity; | ||
|
||
String text; | ||
if (Double.isInfinite(stored)) text = INFINITE; | ||
else { | ||
text = WailaHelper.suffix((long) Unit.convert(Unit.MILLIBUCKETS, displayUnit, stored)); | ||
if (Double.isFinite(capacity)) text += "/" + WailaHelper.suffix((long) Unit.convert(Unit.MILLIBUCKETS, displayUnit, capacity)); | ||
} | ||
|
||
text += " " + displayUnit.symbol; | ||
|
||
var sprite = MekanismRenderer.getChemicalTexture(stack.getType()); | ||
tooltip.addLine(new PairComponent( | ||
new WrappedComponent(stack.getTextComponent()), | ||
new SpriteBarComponent(ratio, sprite, 16, 16, stack.getChemicalTint(), Component.literal(text)))); | ||
} | ||
} | ||
|
||
@Override | ||
public void appendData(IDataWriter data, IServerAccessor<BlockEntity> accessor, IPluginConfig config) { | ||
data.add(Data.class, res -> addChemicals(res, accessor.getTarget(), null)); | ||
} | ||
|
||
public static void addChemicals(IDataWriter.Result<Data> res, BlockEntity tile, @Nullable MultiblockData structure) { | ||
var info = new Data(new ArrayList<>()); | ||
AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.GAS_HANDLER, multiblock -> multiblock.getGasTanks(null), info, MekanismLang.GAS, MergedChemicalTank.Current.GAS, MergedTank.CurrentType.GAS); | ||
AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.INFUSION_HANDLER, multiblock -> multiblock.getInfusionTanks(null), info, MekanismLang.INFUSE_TYPE, MergedChemicalTank.Current.INFUSION, MergedTank.CurrentType.INFUSION); | ||
AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.PIGMENT_HANDLER, multiblock -> multiblock.getPigmentTanks(null), info, MekanismLang.PIGMENT, MergedChemicalTank.Current.PIGMENT, MergedTank.CurrentType.PIGMENT); | ||
AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.SLURRY_HANDLER, multiblock -> multiblock.getSlurryTanks(null), info, MekanismLang.SLURRY, MergedChemicalTank.Current.SLURRY, MergedTank.CurrentType.SLURRY); | ||
if (!info.tanks.isEmpty()) res.add(info); | ||
} | ||
|
||
public static final class Blocker implements IDataProvider<BlockEntity> { | ||
|
||
@Override | ||
public void appendData(IDataWriter data, IServerAccessor<BlockEntity> accessor, IPluginConfig config) { | ||
if (!config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_CHEMICALS)) data.blockAll(Data.class); | ||
} | ||
|
||
} | ||
|
||
public record Data(List<Tank> tanks) implements IData, LookingAtHelper { | ||
|
||
public record Tank(ChemicalStack<?> stack, long capacity) { | ||
|
||
} | ||
|
||
public Data(FriendlyByteBuf buf) { | ||
this(buf.readList(b -> { | ||
var type = b.readEnum(ChemicalType.class); | ||
var stack = switch (type) { | ||
case GAS -> ChemicalUtils.readGasStack(b); | ||
case INFUSION -> ChemicalUtils.readInfusionStack(b); | ||
case PIGMENT -> ChemicalUtils.readPigmentStack(b); | ||
case SLURRY -> ChemicalUtils.readSlurryStack(b); | ||
}; | ||
var capacity = b.readVarLong(); | ||
return new Tank(stack, capacity); | ||
})); | ||
} | ||
|
||
@Override | ||
public void write(FriendlyByteBuf buf) { | ||
buf.writeCollection(tanks, (b, t) -> { | ||
b.writeEnum(ChemicalType.getTypeFor(t.stack)); | ||
ChemicalUtils.writeChemicalStack(b, t.stack); | ||
b.writeVarLong(t.capacity); | ||
}); | ||
} | ||
|
||
@Override | ||
public void addChemicalElement(ChemicalStack<?> stored, long capacity) { | ||
tanks.add(new Tank(stored, capacity)); | ||
} | ||
|
||
@Override | ||
public void addText(Component text) { | ||
} | ||
|
||
@Override | ||
public void addEnergyElement(FloatingLong energy, FloatingLong maxEnergy) { | ||
} | ||
|
||
@Override | ||
public void addFluidElement(FluidStack stored, int capacity) { | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.