Mixin version of https://github.com/refinedmods/refinedstorage/pull/3435
This commit is contained in:
parent
304fd05955
commit
4dd6b7641e
|
|
@ -46,6 +46,7 @@ public class ModernFixEarlyConfig {
|
|||
this.addMixinRule("bugfix.structure_manager_crash", true);
|
||||
this.addMixinRule("bugfix.mc218112", true);
|
||||
this.addMixinRule("bugfix.tf_cme_on_load", modPresent("twilightforest"));
|
||||
this.addMixinRule("bugfix.refinedstorage", modPresent("refinedstorage"));
|
||||
this.addMixinRule("perf.async_jei", modPresent("jei"));
|
||||
this.addMixinRule("perf.thread_priorities", true);
|
||||
this.addMixinRule("perf.preload_block_classes", false);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package org.embeddedt.modernfix.duck.rs;
|
||||
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public interface IFluidExternalStorageCache {
|
||||
boolean initCache(IFluidHandler handler);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.embeddedt.modernfix.duck.rs;
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public interface IItemExternalStorageCache {
|
||||
boolean initCache(IItemHandler handler);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.network.INetwork;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.FluidExternalStorageCache;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import org.embeddedt.modernfix.duck.rs.IFluidExternalStorageCache;
|
||||
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 javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(FluidExternalStorageCache.class)
|
||||
public class FluidExternalStorageCacheMixin implements IFluidExternalStorageCache {
|
||||
@Shadow(remap = false) private List<FluidStack> cache;
|
||||
|
||||
@Shadow(remap = false) private int stored;
|
||||
|
||||
public boolean initCache(IFluidHandler handler) {
|
||||
if (cache != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cache = new ArrayList<>();
|
||||
|
||||
int stored = 0;
|
||||
for (int i = 0; i < handler.getTanks(); ++i) {
|
||||
FluidStack stack = handler.getFluidInTank(i).copy();
|
||||
cache.add(stack);
|
||||
stored += stack.getAmount();
|
||||
}
|
||||
this.stored = stored;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure all cache creation goes through initCache.
|
||||
*/
|
||||
@Inject(method = "update", at = @At(value = "FIELD", target = "Lcom/refinedmods/refinedstorage/apiimpl/storage/externalstorage/FluidExternalStorageCache;cache:Ljava/util/List;", ordinal = 0), cancellable = true, remap = false)
|
||||
private void checkNullCache(INetwork network, @Nullable IFluidHandler handler, CallbackInfo ci) {
|
||||
if(initCache(handler))
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.FluidExternalStorage;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.FluidExternalStorageCache;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorageCache;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.embeddedt.modernfix.duck.rs.IFluidExternalStorageCache;
|
||||
import org.embeddedt.modernfix.duck.rs.IItemExternalStorageCache;
|
||||
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.Redirect;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(FluidExternalStorage.class)
|
||||
public class FluidExternalStorageMixin {
|
||||
@Shadow(remap = false)
|
||||
@Final
|
||||
private FluidExternalStorageCache cache;
|
||||
|
||||
@Redirect(method = "getStacks", at = @At(value = "INVOKE", target = "Ljava/util/function/Supplier;get()Ljava/lang/Object;"), remap = false)
|
||||
private Object cacheAndGet(Supplier<IFluidHandler> supplier) {
|
||||
IFluidHandler handler = supplier.get();
|
||||
if(handler != null)
|
||||
((IFluidExternalStorageCache)cache).initCache(handler);
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.storage.externalstorage.IExternalStorage;
|
||||
import com.refinedmods.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.FluidExternalStorage;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.FluidExternalStorageProvider;
|
||||
import com.refinedmods.refinedstorage.tile.FluidInterfaceTile;
|
||||
import com.refinedmods.refinedstorage.util.WorldUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
@Mixin(FluidExternalStorageProvider.class)
|
||||
public class FluidExternalStorageProviderMixin {
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason replace supplier in 2nd arg, no easy way of doing so without overwrite
|
||||
*/
|
||||
@Overwrite
|
||||
public IExternalStorage<FluidStack> provide(IExternalStorageContext context, BlockEntity blockEntity, Direction direction) {
|
||||
return new FluidExternalStorage(context, () -> {
|
||||
Level level = blockEntity.getLevel();
|
||||
|
||||
if (level == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockPos blockPos = blockEntity.getBlockPos();
|
||||
|
||||
if (!level.isLoaded(blockPos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockEntity currentBlockEntity = level.getBlockEntity(blockPos);
|
||||
|
||||
return WorldUtils.getFluidHandler(currentBlockEntity, direction.getOpposite());
|
||||
}, blockEntity instanceof FluidInterfaceTile);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.network.INetwork;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorageCache;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.embeddedt.modernfix.duck.rs.IItemExternalStorageCache;
|
||||
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 javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(ItemExternalStorageCache.class)
|
||||
public class ItemExternalStorageCacheMixin implements IItemExternalStorageCache {
|
||||
@Shadow(remap = false) private List<ItemStack> cache;
|
||||
|
||||
@Shadow(remap = false) private int stored;
|
||||
|
||||
public boolean initCache(IItemHandler handler) {
|
||||
if (cache != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cache = new ArrayList<>();
|
||||
|
||||
int stored = 0;
|
||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||
ItemStack stack = handler.getStackInSlot(i).copy();
|
||||
cache.add(stack);
|
||||
stored += stack.getCount();
|
||||
}
|
||||
this.stored = stored;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure all cache creation goes through initCache.
|
||||
*/
|
||||
@Inject(method = "update", at = @At(value = "FIELD", remap = false, target = "Lcom/refinedmods/refinedstorage/apiimpl/storage/externalstorage/ItemExternalStorageCache;cache:Ljava/util/List;", ordinal = 0), cancellable = true, remap = false)
|
||||
private void checkNullCache(INetwork network, @Nullable IItemHandler handler, CallbackInfo ci) {
|
||||
if(initCache(handler))
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorage;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorageCache;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.embeddedt.modernfix.duck.rs.IItemExternalStorageCache;
|
||||
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.Redirect;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(ItemExternalStorage.class)
|
||||
public class ItemExternalStorageMixin {
|
||||
@Shadow(remap = false) @Final private ItemExternalStorageCache cache;
|
||||
|
||||
@Redirect(method = "getStacks", at = @At(value = "INVOKE", target = "Ljava/util/function/Supplier;get()Ljava/lang/Object;"), remap = false)
|
||||
private Object cacheAndGet(Supplier<IItemHandler> supplier) {
|
||||
IItemHandler handler = supplier.get();
|
||||
if(handler != null)
|
||||
((IItemExternalStorageCache)cache).initCache(handler);
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.embeddedt.modernfix.mixin.bugfix.refinedstorage.te_bug;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.storage.externalstorage.IExternalStorage;
|
||||
import com.refinedmods.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorage;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.externalstorage.ItemExternalStorageProvider;
|
||||
import com.refinedmods.refinedstorage.tile.InterfaceTile;
|
||||
import com.refinedmods.refinedstorage.util.WorldUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
@Mixin(ItemExternalStorageProvider.class)
|
||||
public class ItemExternalStorageProviderMixin {
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason replace supplier in 2nd arg, no easy way of doing so without overwrite
|
||||
*/
|
||||
@Overwrite
|
||||
public IExternalStorage<ItemStack> provide(IExternalStorageContext context, BlockEntity blockEntity, Direction direction) {
|
||||
return new ItemExternalStorage(context, () -> {
|
||||
Level level = blockEntity.getLevel();
|
||||
|
||||
if (level == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockPos blockPos = blockEntity.getBlockPos();
|
||||
|
||||
if (!level.isLoaded(blockPos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockEntity currentBlockEntity = level.getBlockEntity(blockPos);
|
||||
|
||||
return WorldUtils.getItemHandler(currentBlockEntity, direction.getOpposite());
|
||||
}, blockEntity instanceof InterfaceTile);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,12 @@
|
|||
"bugfix.edge_chunk_not_saved.ChunkManagerMixin",
|
||||
"bugfix.structure_manager_crash.StructureManagerMixin",
|
||||
"bugfix.tf_cme_on_load.TwilightForestModMixin",
|
||||
"bugfix.refinedstorage.te_bug.ItemExternalStorageProviderMixin",
|
||||
"bugfix.refinedstorage.te_bug.FluidExternalStorageProviderMixin",
|
||||
"bugfix.refinedstorage.te_bug.FluidExternalStorageCacheMixin",
|
||||
"bugfix.refinedstorage.te_bug.FluidExternalStorageMixin",
|
||||
"bugfix.refinedstorage.te_bug.ItemExternalStorageCacheMixin",
|
||||
"bugfix.refinedstorage.te_bug.ItemExternalStorageMixin",
|
||||
"perf.remove_biome_temperature_cache.BiomeMixin",
|
||||
"perf.resourcepacks.ModFileResourcePackMixin",
|
||||
"perf.resourcepacks.VanillaPackMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user