Skip to content

Commit

Permalink
Update to Mekanism 10.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed May 27, 2022
1 parent 02b4d06 commit 0c579cb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ dependencies {
// We depend on many AE2 internals, such as using their basic cell drive, thus not using classifier = "api"
implementation(fg.deobf("appeng:appliedenergistics2:${ae2_version}"))

// We depend on Mekanism internals, such as using QIO, thus not using classifier = "api"
compileOnly(fg.deobf("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:api"))
compileOnly(fg.deobf("mekanism:Mekanism:${minecraft_version}-${mekanism_version}"))
runtimeOnly(fg.deobf("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:all"))

compileOnly(fg.deobf("mezz.jei:jei-${minecraft_version}:${jei_version}:api"))
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
minecraft_version=1.18.2
forge_version=40.0.44
forge_version=40.1.18
ae2_version=11.0.0
mekanism_version=10.2.0.459
mekanism_version=10.2.1.461
jei_version=9.7.0.180

org.gradle.daemon=false
Expand Down
47 changes: 21 additions & 26 deletions src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package me.ramidzkh.mekae2.qio;

import java.util.Objects;

import org.jetbrains.annotations.Nullable;

import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;

import me.ramidzkh.mekae2.AMText;
import mekanism.api.Action;
import mekanism.common.content.qio.QIOFrequency;
import mekanism.common.lib.security.SecurityMode;
import mekanism.common.tile.qio.TileEntityQIODashboard;
import mekanism.api.MekanismAPI;
import mekanism.api.inventory.qio.IQIOComponent;
import mekanism.api.inventory.qio.IQIOFrequency;
import mekanism.api.security.SecurityMode;

import appeng.api.config.Actionable;
import appeng.api.features.IPlayerRegistry;
Expand All @@ -23,32 +23,37 @@
import appeng.api.stacks.KeyCounter;
import appeng.api.storage.MEStorage;

public class QioStorageAdapter implements MEStorage {
private final TileEntityQIODashboard dashboard;
/**
* This generic trick allows us to capture both the BE and the IQIOComponent without depending on the actual Mekanism
* block entity class.
*/
public class QioStorageAdapter<DASHBOARD extends BlockEntity & IQIOComponent> implements MEStorage {
private final DASHBOARD dashboard;
@Nullable
private final Direction queriedSide;
private final IActionSource querySrc;

public QioStorageAdapter(TileEntityQIODashboard dashboard, @Nullable Direction queriedSide,
public QioStorageAdapter(DASHBOARD dashboard, @Nullable Direction queriedSide,
IActionSource querySrc) {
this.dashboard = dashboard;
this.queriedSide = queriedSide;
this.querySrc = querySrc;
}

@Nullable
public QIOFrequency getFrequency() {
public IQIOFrequency getFrequency() {
// Check dashboard facing.
if (dashboard.getBlockState().getValue(BlockStateProperties.FACING).getOpposite() != queriedSide) {
return null;
}
// Check that it has a frequency.
var freq = dashboard.getFrequency();
if (freq == null) {
var freq = dashboard.getQIOFrequency();
if (freq == null || !freq.isValid()) {
return null;
}
// Check security.
var securityMode = dashboard.getSecurityMode();
var utils = MekanismAPI.getSecurityUtils();
var securityMode = utils.getSecurityMode(dashboard, dashboard.getLevel().isClientSide());
if (securityMode != SecurityMode.PUBLIC) {
// Private or trusted: the player who placed the storage bus must have dashboard access.
var host = querySrc.machine().map(IActionHost::getActionableNode).orElse(null);
Expand All @@ -57,17 +62,8 @@ public QIOFrequency getFrequency() {
}
var storageBusOwner = IPlayerRegistry.getMapping(dashboard.getLevel())
.getProfileId(host.getOwningPlayerId());
var dashboardOwner = dashboard.getOwnerUUID();

if (!Objects.equals(dashboardOwner, storageBusOwner)) {
var securityFreq = dashboard.getSecurity().getFrequency();

if (securityMode == SecurityMode.PRIVATE) {
return null;
} else if (securityMode == SecurityMode.TRUSTED
&& !securityFreq.getTrustedUUIDs().contains(storageBusOwner)) {
return null;
}
if (!utils.canAccess(storageBusOwner, dashboard, dashboard.getLevel().isClientSide())) {
return null;
}
}
return freq;
Expand Down Expand Up @@ -103,9 +99,8 @@ public void getAvailableStacks(KeyCounter out) {
if (freq == null) {
return;
}
for (var entry : freq.getItemDataMap().entrySet()) {
out.add(AEItemKey.of(entry.getKey().getStack()), entry.getValue().getCount());
}
// noinspection ConstantConditions
freq.forAllStored((stack, value) -> out.add(AEItemKey.of(stack), value));
}

@Override
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
Expand All @@ -14,14 +15,15 @@
import net.minecraftforge.event.AttachCapabilitiesEvent;

import me.ramidzkh.mekae2.AppliedMekanistics;
import mekanism.common.tile.qio.TileEntityQIODashboard;
import mekanism.api.inventory.qio.IQIOComponent;

import appeng.api.storage.IStorageMonitorableAccessor;

public class QioSupport {
private static final Capability<IStorageMonitorableAccessor> STORAGE_MONITORABLE = CapabilityManager
.get(new CapabilityToken<>() {
});
private static final ResourceLocation DASHBOARD = new ResourceLocation("mekanism", "qio_dashboard");

public static void initialize() {
MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, QioSupport::onBlockEntityCapability);
Expand All @@ -30,21 +32,25 @@ public static void initialize() {
public static void onBlockEntityCapability(AttachCapabilitiesEvent<BlockEntity> event) {
var object = event.getObject();

if (object instanceof TileEntityQIODashboard dashboard) {
event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() {
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability, @Nullable Direction arg) {
if (capability == STORAGE_MONITORABLE) {
return LazyOptional.of(() -> (IStorageMonitorableAccessor) querySrc -> {
var adapter = new QioStorageAdapter(dashboard, arg, querySrc);
// Make sure that we only allow non-null frequencies.
return adapter.getFrequency() == null ? null : adapter;
}).cast();
if (object instanceof IQIOComponent) {
if (DASHBOARD.equals(object.getType().getRegistryName())) {
event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() {
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability,
@Nullable Direction arg) {
if (capability == STORAGE_MONITORABLE) {
return LazyOptional.of(() -> (IStorageMonitorableAccessor) querySrc -> {
var adapter = new QioStorageAdapter<>((BlockEntity & IQIOComponent) object, arg,
querySrc);
// Make sure that we only allow non-null frequencies.
return adapter.getFrequency() == null ? null : adapter;
}).cast();
}
return LazyOptional.empty();
}
return LazyOptional.empty();
}
});
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ side = "BOTH"
[[dependencies.appmek]]
modId = "mekanism"
mandatory = true
versionRange = "[10.1.2,11.0.0)"
versionRange = "[10.2.1,11.0.0)"
ordering = "AFTER"
side = "BOTH"

0 comments on commit 0c579cb

Please sign in to comment.