Skip to content

Commit

Permalink
Fix Duplication Glitch With ME Stocking Bus/Hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Aug 27, 2024
1 parent 2bd06e3 commit e86bb33
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import net.minecraft.util.ResourceLocation;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEInputBus;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEStockingBus;

/**
* Fixes Duplication Glitch via Disconnecting from AE2.
*/
@Mixin(value = MetaTileEntityMEStockingBus.class, remap = false)
public abstract class MetaTileEntityMEStockingBusMixin extends MetaTileEntityMEInputBus {

@Shadow
@Final
private static int CONFIG_SIZE;

@Shadow
private boolean autoPull;

@Shadow
protected abstract void clearInventory(int startIndex);

/**
* Default Ignored Constructor
*/
public MetaTileEntityMEStockingBusMixin(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}

@Inject(method = "update",
at = @At(value = "INVOKE",
target = "Lgregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus;update()V",
shift = At.Shift.AFTER),
require = 1,
cancellable = true)
private void checkAe2Disconnect(CallbackInfo ci) {
if (!getWorld().isRemote && isWorkingEnabled() && !updateMEStatus()) {
// If Disconnected from ME
// Don't use Clear Inventory, Config Slots should not change
// Unless is Auto Pull
if (autoPull) clearInventory(0);
else {
for (int i = 0; i < CONFIG_SIZE; i++) {
getAEItemHandler().getInventory()[i].setStack(null);
}
}
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import net.minecraft.util.ResourceLocation;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEInputHatch;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEStockingHatch;

/**
* Fixes Duplication Glitch via Disconnecting from AE2.
*/
@Mixin(value = MetaTileEntityMEStockingHatch.class, remap = false)
public abstract class MetaTileEntityMEStockingHatchMixin extends MetaTileEntityMEInputHatch {

@Shadow
@Final
private static int CONFIG_SIZE;

@Shadow
private boolean autoPull;

@Shadow
protected abstract void clearInventory(int startIndex);

/**
* Default Ignored Constructor
*/
public MetaTileEntityMEStockingHatchMixin(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}

@Inject(method = "update",
at = @At(value = "INVOKE",
target = "Lgregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch;update()V",
shift = At.Shift.AFTER),
require = 1,
cancellable = true)
private void checkAe2Disconnect(CallbackInfo ci) {
if (!getWorld().isRemote && isWorkingEnabled() && !updateMEStatus()) {
// If Disconnected from ME
// Don't use Clear Inventory, Config Slots should not change
// Unless is Auto Pull
if (autoPull) clearInventory(0);
else {
for (int i = 0; i < CONFIG_SIZE; i++) {
getAEFluidHandler().getInventory()[i].setStack(null);
}
}
ci.cancel();
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/mixins.nomilabs.gregtech.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"MaterialRecipeHandlerMixin",
"MaterialStackMixin",
"MetaItemsMixin",
"MetaTileEntityMEStockingBusMixin",
"MetaTileEntityMEStockingHatchMixin",
"MetaTileEntityProcessingArrayMixin",
"MultiblockInfoCategoryMixin",
"OreDictUnifierAccessor",
Expand Down

0 comments on commit e86bb33

Please sign in to comment.