-
-
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
10 changed files
with
189 additions
and
11 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
14 changes: 14 additions & 0 deletions
14
...mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessBasicInventorySlot.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,14 @@ | ||
package lol.bai.megane.module.mekanism.mixin; | ||
|
||
import mekanism.common.inventory.container.slot.ContainerSlotType; | ||
import mekanism.common.inventory.slot.BasicInventorySlot; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(BasicInventorySlot.class) | ||
public interface AccessBasicInventorySlot { | ||
|
||
@Invoker("getSlotType") | ||
ContainerSlotType megane_getSlotType(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/FactoryProvider.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,42 @@ | ||
package lol.bai.megane.module.mekanism.provider; | ||
|
||
import lol.bai.megane.module.mekanism.mixin.AccessBasicInventorySlot; | ||
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.data.ProgressData; | ||
import mekanism.api.recipes.MekanismRecipe; | ||
import mekanism.common.tile.factory.TileEntityFactory; | ||
|
||
public class FactoryProvider implements IDataProvider<TileEntityFactory<MekanismRecipe>> { | ||
|
||
@Override | ||
public void appendData(IDataWriter data, IServerAccessor<TileEntityFactory<MekanismRecipe>> accessor, IPluginConfig config) { | ||
data.add(ProgressData.class, res -> { | ||
var factory = accessor.getTarget(); | ||
var ratio = 0d; | ||
|
||
for (var i = 0; i < factory.tier.processes; i++) { | ||
ratio = Math.max(ratio, factory.getScaledProgress(1, i)); | ||
} | ||
|
||
if (ratio > 0) { | ||
var progressData = ProgressData.ratio((float) ratio); | ||
var slots = factory.getInventorySlots(null); | ||
|
||
for (var slot : slots) { | ||
if (slot instanceof AccessBasicInventorySlot basic) { | ||
switch (basic.megane_getSlotType()) { | ||
case INPUT -> progressData.input(slot.getStack()); | ||
case OUTPUT -> progressData.output(slot.getStack()); | ||
} | ||
} | ||
} | ||
|
||
res.add(progressData); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
96 changes: 96 additions & 0 deletions
96
...orge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/SecurityProvider.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,96 @@ | ||
package lol.bai.megane.module.mekanism.provider; | ||
|
||
import lol.bai.megane.module.mekanism.MeganeMekaninsm; | ||
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.IDataReader; | ||
import mcp.mobius.waila.api.IDataWriter; | ||
import mcp.mobius.waila.api.IEntityAccessor; | ||
import mcp.mobius.waila.api.IEntityComponentProvider; | ||
import mcp.mobius.waila.api.IPluginConfig; | ||
import mcp.mobius.waila.api.IServerAccessor; | ||
import mcp.mobius.waila.api.ITooltip; | ||
import mcp.mobius.waila.api.component.PairComponent; | ||
import mekanism.api.MekanismAPI; | ||
import mekanism.api.security.SecurityMode; | ||
import mekanism.api.text.APILang; | ||
import mekanism.common.capabilities.Capabilities; | ||
import mekanism.common.util.MekanismUtils; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SecurityProvider<T extends ICapabilityProvider> implements IBlockComponentProvider, IEntityComponentProvider, IDataProvider<T> { | ||
|
||
public static final ResourceLocation DATA = MeganeMekaninsm.id("security"); | ||
|
||
private void appendBody(ITooltip tooltip, IDataReader data, IPluginConfig config) { | ||
if (!config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_SECURITY)) return; | ||
|
||
var security = data.get(Data.class); | ||
if (security == null || security.mode == SecurityMode.PUBLIC) return; | ||
|
||
tooltip.addLine((switch (security.mode) { | ||
case PRIVATE -> APILang.PRIVATE; | ||
case TRUSTED -> APILang.TRUSTED; | ||
default -> throw new AssertionError(); | ||
}).translate().withStyle(security.canAccess ? ChatFormatting.GREEN : ChatFormatting.RED)); | ||
|
||
var owner = security.owner; | ||
if (owner != null) tooltip.addLine(new PairComponent( | ||
Component.translatable("megane.mekanism.owner"), | ||
Component.literal(owner))); | ||
} | ||
|
||
@Override | ||
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { | ||
appendBody(tooltip, accessor.getData(), config); | ||
} | ||
|
||
@Override | ||
public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { | ||
appendBody(tooltip, accessor.getData(), config); | ||
} | ||
|
||
@Override | ||
public void appendData(IDataWriter data, IServerAccessor<T> accessor, IPluginConfig config) { | ||
if (!config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_SECURITY)) return; | ||
|
||
var be = accessor.getTarget(); | ||
be.getCapability(Capabilities.OWNER_OBJECT).ifPresent(owner -> { | ||
var api = MekanismAPI.getSecurityUtils(); | ||
var security = be.getCapability(Capabilities.SECURITY_OBJECT).resolve().orElse(null); | ||
var securityMode = security == null ? SecurityMode.PUBLIC : api.getEffectiveSecurityMode(security, false); | ||
var canAccess = security == null || api.canAccessObject(accessor.getPlayer(), security); | ||
data.addImmediate(new Data(securityMode, MekanismUtils.getLastKnownUsername(owner.getOwnerUUID()), canAccess)); | ||
}); | ||
} | ||
|
||
public record Data( | ||
SecurityMode mode, | ||
@Nullable String owner, | ||
boolean canAccess | ||
) implements IData { | ||
|
||
public Data(FriendlyByteBuf buf) { | ||
this( | ||
buf.readEnum(SecurityMode.class), | ||
buf.readNullable(FriendlyByteBuf::readUtf), | ||
buf.readBoolean()); | ||
} | ||
|
||
@Override | ||
public void write(FriendlyByteBuf buf) { | ||
buf.writeEnum(mode); | ||
buf.writeNullable(owner, FriendlyByteBuf::writeUtf); | ||
buf.writeBoolean(canAccess); | ||
} | ||
|
||
} | ||
|
||
} |
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