Skip to content

Commit 11233b1

Browse files
author
Circulate233
committed
修复MEK的创造气体储罐交互可以被清空的问题
可能修复了在没有物品元件的情况下流体无法交互的问题
1 parent f281236 commit 11233b1

6 files changed

Lines changed: 60 additions & 19 deletions

File tree

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ dependencies {
203203
compileOnly(rfg.deobf('curse.maven:packagedauto-308380:2977147')) // 1.0.3.14
204204
compileOnly(rfg.deobf('curse.maven:codechicken-lib-1-8-242818:2779848')) //ccl
205205
compileOnly(rfg.deobf('curse.maven:gregtech-ce-unofficial-557242:5121638')) // gt
206-
implementation(rfg.deobf('curse.maven:ae2-extended-life-570458:5378163')) //pae2
206+
implementation(rfg.deobf("curse.maven:ae2-extended-life-570458:6302098"))
207207
compileOnly(rfg.deobf('curse.maven:dynamistics-383632:3056455')) // dy
208208
implementation(rfg.deobf('curse.maven:baubles-227083:2518667')) //baubles
209209
compileOnly(rfg.deobf("curse.maven:thaumic-223628:2629023"))
210210
compileOnly(rfg.deobf("curse.maven:thaumic-energistics-extended-life-849094:6321322"))
211-
compileOnly(rfg.deobf("curse.maven:mekanism-ce-399904:4804509")) //mek-ce
212-
compileOnly(rfg.deobf("curse.maven:mekanism-energistics-1027681:5389347")) //mekeng
211+
implementation(rfg.deobf("curse.maven:mekanism-ce-399904:4804509")) //mek-ce
212+
implementation(rfg.deobf("curse.maven:mekanism-energistics-1027681:5389347")) //mekeng
213213
compileOnly(rfg.deobf('curse.maven:opencomputers-223008:4630537')) //oc
214214
compileOnly(rfg.deobf("curse.maven:p455w0rdslib-255232:2830265"))
215215
compileOnly(rfg.deobf("curse.maven:ae2wtlib-304024:2830114"))

src/main/java/com/glodblock/github/coremod/mixin/ae2/MixinGridStorageCache.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.Map;
2626

27+
@SuppressWarnings("unchecked")
2728
@Mixin(value = GridStorageCache.class, remap = false)
2829
public abstract class MixinGridStorageCache {
2930

@@ -33,12 +34,12 @@ public abstract class MixinGridStorageCache {
3334

3435
@Inject(method = "<init>", at = @At("TAIL"))
3536
private void onInit(final IGrid g, final CallbackInfo ci) {
36-
((FCNetworkMonitor) this.storageMonitors.get(Util.getItemChannel())).init();
37+
((FCNetworkMonitor<?>) this.storageMonitors.get(Util.getItemChannel())).init();
3738
}
3839

3940
@Inject(method = "buildNetworkStorage", at = @At("RETURN"))
4041
public void onBuild(final IStorageChannel<?> chan, final CallbackInfoReturnable<NetworkInventoryHandler<?>> cir) {
41-
final var m = (FCNetworkMonitor) this.storageMonitors.get(Util.getItemChannel());
42+
final var m = (FCNetworkMonitor<?>) this.storageMonitors.get(Util.getItemChannel());
4243
((FCNetworkInventoryHandler) cir.getReturnValue()).init(m);
4344
}
4445

@@ -52,7 +53,7 @@ public void postAlterationOfStoredItems(final IStorageChannel<?> chan, final Ite
5253
if (drop != null) list.add(drop.setStackSize(size));
5354
i.setStackSize(size);
5455
}
55-
((FCNetworkMonitor) this.storageMonitors.get(Util.getItemChannel())).fc$postChange(true, list, src);
56+
((FCNetworkMonitor<IAEItemStack>) this.storageMonitors.get(Util.getItemChannel())).fc$postChange(true, list, src);
5657
}
5758
}
5859

@@ -66,7 +67,7 @@ private <T extends IAEStack<T>, C extends IStorageChannel<T>> void postChangesTo
6667
if (drop != null) list.add(drop.setStackSize(size));
6768
i.setStackSize(size);
6869
}
69-
((FCNetworkMonitor) this.storageMonitors.get(Util.getItemChannel())).fc$postChange(upOrDown > 0, list, src);
70+
((FCNetworkMonitor<IAEItemStack>) this.storageMonitors.get(Util.getItemChannel())).fc$postChange(upOrDown > 0, list, src);
7071
}
7172
}
7273
}

src/main/java/com/glodblock/github/coremod/mixin/ae2/MixinNetworkInventoryHandler.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import appeng.api.config.Actionable;
44
import appeng.api.networking.security.IActionSource;
55
import appeng.api.networking.storage.IStorageGrid;
6+
import appeng.api.storage.IMEInventoryHandler;
67
import appeng.api.storage.IMEMonitor;
78
import appeng.api.storage.IStorageChannel;
89
import appeng.api.storage.data.IAEItemStack;
@@ -20,6 +21,7 @@
2021
import com.llamalad7.mixinextras.sugar.Share;
2122
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
2223
import org.objectweb.asm.Opcodes;
24+
import org.spongepowered.asm.mixin.Final;
2325
import org.spongepowered.asm.mixin.Mixin;
2426
import org.spongepowered.asm.mixin.Shadow;
2527
import org.spongepowered.asm.mixin.Unique;
@@ -28,8 +30,12 @@
2830
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2931
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3032

31-
@SuppressWarnings("DataFlowIssue")
32-
@Mixin(value = NetworkInventoryHandler.class, remap = false)
33+
import java.util.Deque;
34+
import java.util.List;
35+
import java.util.NavigableMap;
36+
37+
@SuppressWarnings({"DataFlowIssue", "unchecked"})
38+
@Mixin(value = NetworkInventoryHandler.class, remap = false, priority = 1001)
3339
public abstract class MixinNetworkInventoryHandler<T extends IAEStack<T>> implements FCNetworkInventoryHandler {
3440

3541
@Unique
@@ -47,6 +53,13 @@ public abstract class MixinNetworkInventoryHandler<T extends IAEStack<T>> implem
4753
@Shadow
4854
protected abstract boolean diveList(NetworkInventoryHandler<T> networkInventoryHandler, Actionable type);
4955

56+
@Shadow
57+
@Final
58+
private NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
59+
60+
@Shadow
61+
protected abstract Deque<?> getDepth(Actionable type);
62+
5063
@Inject(method = "<init>", at = @At("TAIL"))
5164
public void onInit(final IStorageChannel<?> chan, final SecurityCache security, final CallbackInfo ci) {
5265
monitor = security.getGrid().<IStorageGrid>getCache(IStorageGrid.class).getInventory(Util.getItemChannel());
@@ -58,13 +71,32 @@ private void notItemInject(final T input, final Actionable mode, final IActionSo
5871
if (src instanceof FakeMonitor.FakeMonitorSource || mode == Actionable.SIMULATE) return;
5972
final var drop = Util.packAEStackToDrop(input);
6073
if (drop != null) {
61-
this.surface((NetworkInventoryHandler<T>) (Object) this, mode);
74+
if (!this.getDepth(mode).isEmpty()) this.surface((NetworkInventoryHandler<T>) (Object) this, mode);
6275
cir.setReturnValue(FakeItemRegister.getAEStack(monitor.injectItems(drop, mode, src)));
6376
this.diveList((NetworkInventoryHandler<T>) (Object) this, mode);
6477
} else return;
6578
this.surface((NetworkInventoryHandler<T>) (Object) this, mode);
6679
}
6780

81+
@Inject(method = "injectItems", at = @At(value = "FIELD", target = "Lappeng/me/storage/NetworkInventoryHandler;priorityInventory:Ljava/util/NavigableMap;", opcode = Opcodes.GETFIELD), cancellable = true)
82+
private void injectItemsN(final T input, final Actionable mode, final IActionSource src, final CallbackInfoReturnable<T> cir, @Share("fc$fakeInput") final LocalBooleanRef fakeInput) {
83+
if (input == null || fakeInput.get() || !this.priorityInventory.isEmpty()) return;
84+
if (input instanceof final IAEItemStack i) {
85+
if (i.getItem() == FCItems.FLUID_DROP) {
86+
cir.setReturnValue((T) fluidMonitor.injectItems(i, mode, src));
87+
} else if (ModAndClassUtil.GAS && i.getItem() == FCGasItems.GAS_DROP) {
88+
cir.setReturnValue((T) gasMonitor.injectItems(i, mode, src));
89+
} else {
90+
fakeInput.set(true);
91+
return;
92+
}
93+
} else {
94+
fakeInput.set(true);
95+
return;
96+
}
97+
this.surface((NetworkInventoryHandler<T>) (Object) this, mode);
98+
}
99+
68100
@Inject(method = "injectItems", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;", ordinal = 2), cancellable = true)
69101
private void injectItems(final T input, final Actionable mode, final IActionSource src, final CallbackInfoReturnable<T> cir, @Share("fc$fakeInput") final LocalBooleanRef fakeInput) {
70102
if (input == null || fakeInput.get()) return;
@@ -110,7 +142,7 @@ public void extractItems(final T request, final Actionable mode, final IActionSo
110142
}
111143

112144
@Override
113-
public void init(final FCNetworkMonitor monitor) {
145+
public void init(final FCNetworkMonitor<?> monitor) {
114146
fluidMonitor = monitor.getFluidMonitor();
115147
gasMonitor = monitor.getGasMonitor();
116148
}

src/main/java/com/glodblock/github/coremod/mixin/ae2/MixinNetworkMonitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import javax.annotation.Nonnull;
3030

31+
@SuppressWarnings("unchecked")
3132
@Mixin(value = NetworkMonitor.class, remap = false)
3233
public abstract class MixinNetworkMonitor<T extends IAEStack<T>> implements FCNetworkMonitor<T> {
3334

src/main/java/com/glodblock/github/interfaces/FCNetworkInventoryHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
public interface FCNetworkInventoryHandler {
44

5-
void init(FCNetworkMonitor monitor);
5+
void init(FCNetworkMonitor<?> monitor);
66
}

src/main/java/com/glodblock/github/network/CpacketMEMonitorableAction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import io.netty.buffer.ByteBuf;
2222
import mekanism.api.gas.GasStack;
2323
import mekanism.api.gas.IGasItem;
24+
import mekanism.common.base.ITierItem;
25+
import mekanism.common.tier.BaseTier;
2426
import net.minecraft.entity.player.EntityPlayerMP;
2527
import net.minecraft.init.Items;
2628
import net.minecraft.item.ItemStack;
@@ -184,6 +186,7 @@ private static void fluidWork(final CpacketMEMonitorableAction message, final It
184186
private static void gasWork(final CpacketMEMonitorableAction message, final IGasItem ig, final ItemStack ch, final IStorageGrid grid, final IActionSource source, final EntityPlayerMP player) {
185187
final var h = player.inventory.getItemStack();
186188
if (!ItemStack.areItemsEqual(ch, h) || !ItemStack.areItemStackTagsEqual(ch, h) || h.isEmpty()) return;
189+
final boolean creative = h.getItem() instanceof ITierItem i && i.getBaseTier(h) == BaseTier.CREATIVE;
187190
boolean drain = false;
188191
final var allGas = ig.getGas(ch);
189192
final var allAmount = allGas == null ? 0 : allGas.amount;
@@ -202,18 +205,22 @@ private static void gasWork(final CpacketMEMonitorableAction message, final IGas
202205
allAEGas = AEGasStack.of(allGas);
203206
if (allAEGas == null) return;
204207
final var a = gasStorage.injectItems(allAEGas, Actionable.SIMULATE, source);
205-
final var size = allAEGas.getStackSize() - (a == null ? 0 : a.getStackSize());
206-
gasStorage.injectItems(allAEGas.setStackSize(size), Actionable.MODULATE, source);
207-
allGas.amount -= (int) size;
208-
ig.setGas(ch, allGas);
208+
if (!creative) {
209+
final var size = allAEGas.getStackSize() - (a == null ? 0 : a.getStackSize());
210+
gasStorage.injectItems(allAEGas.setStackSize(size), Actionable.MODULATE, source);
211+
allGas.amount -= (int) size;
212+
ig.setGas(ch, allGas);
213+
}
209214
} else {
210215
allAEGas = AEGasStack.of(gas);
211216
if (allAEGas == null) return;
212217
final var a = gasStorage.extractItems(allAEGas, Actionable.SIMULATE, source);
213218
if (a == null) return;
214-
final var size = Math.min(ig.getMaxGas(ch) - allAmount, (int) a.getStackSize());
215-
gasStorage.extractItems(allAEGas.setStackSize(size), Actionable.MODULATE, source);
216-
gas.amount = size + allAmount;
219+
if (!creative) {
220+
final var size = Math.min(ig.getMaxGas(ch) - allAmount, (int) a.getStackSize());
221+
gasStorage.extractItems(allAEGas.setStackSize(size), Actionable.MODULATE, source);
222+
gas.amount = size + allAmount;
223+
} else gas.amount = Integer.MAX_VALUE;
217224
ig.setGas(ch, gas);
218225
}
219226
if (h.getCount() > 1) {

0 commit comments

Comments
 (0)