Skip to content

Commit

Permalink
Merge pull request #34 from GlodBlock/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
GlodBlock authored Jul 30, 2022
2 parents 3e8c507 + 63d12aa commit c961a5d
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 17 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ dependencies {
compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.29:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:GTplusplus:1.7.49:dev") {transitive = false}


runtime("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,19 @@ public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActio

if( this.canHoldNewFluid() ) // room for new type, and for at least one item!
{
final int remainingItemCount = (int) this.getRemainingFluidCount() - this.getBytesPerType() * 8;
final long remainingItemCount = this.getRemainingFluidCount() - this.getBytesPerType() * 8;

if( remainingItemCount > 0 )
{
if( input.getStackSize() > remainingItemCount )
{
final FluidStack toReturn = Util.cloneFluidStack(sharedFluidStack);
toReturn.amount = sharedFluidStack.amount - remainingItemCount;
toReturn.amount = (int) (sharedFluidStack.amount - remainingItemCount);

if( mode == Actionable.MODULATE )
{
final FluidStack toWrite = Util.cloneFluidStack( sharedFluidStack );
toWrite.amount = remainingItemCount;
toWrite.amount = (int) remainingItemCount;

this.cellItems.add( AEFluidStack.create( toWrite ) );
this.updateFluidCount( toWrite.amount );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.glodblock.github.common.tile;

import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.GridFlags;
import appeng.api.networking.crafting.ICraftingGrid;
Expand All @@ -19,7 +20,6 @@
import appeng.me.cache.CraftingGridCache;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.grid.AENetworkTile;
import appeng.util.Platform;
import com.glodblock.github.common.item.ItemFluidDrop;

import java.util.ArrayList;
Expand Down Expand Up @@ -48,8 +48,6 @@ public boolean canBeRotated() {
@Override
@SuppressWarnings("rawtypes")
public List<IMEInventoryHandler> getCellArray(StorageChannel channel) {
/*conflict = !checkDiscreatizer();
if (conflict) return Collections.emptyList();*/
if (getProxy().isActive()) {
if (channel == StorageChannel.ITEMS) {
return Collections.singletonList(fluidDropInv.invHandler);
Expand Down Expand Up @@ -131,6 +129,25 @@ public void onStorageUpdate(MENetworkStorageEvent event) {
updateState();
}

@MENetworkEventSubscribe
public void onBootUp(MENetworkBootingStatusChange event) {
try {
IMEInventory<IAEItemStack> inventory = this.getProxy().getStorage().getItemInventory();
IItemList<IAEItemStack> items = inventory.getAvailableItems(AEApi.instance().storage().createItemList());
IItemList<IAEItemStack> drops = AEApi.instance().storage().createItemList();
for (IAEItemStack item : items) {
if (item != null && item.getItem() instanceof ItemFluidDrop) {
drops.add(item);
}
}
for (IAEItemStack drop : drops) {
inventory.extractItems(drop, Actionable.MODULATE, ownActionSource);
inventory.injectItems(drop, Actionable.MODULATE, ownActionSource);
}
} catch (GridAccessException ignored) {
}
}

private class FluidDiscretizingInventory implements IMEInventory<IAEItemStack>, IMEMonitorHandlerReceiver<IAEFluidStack> {

private final MEInventoryHandler<IAEItemStack> invHandler = new MEInventoryHandler<>(this, getChannel());
Expand All @@ -142,7 +159,6 @@ private class FluidDiscretizingInventory implements IMEInventory<IAEItemStack>,

@Override
public IAEItemStack injectItems(IAEItemStack request, Actionable type, BaseActionSource src) {
/*if (conflict) return request;*/
IAEFluidStack fluidStack = ItemFluidDrop.getAeFluidStack(request);
if (fluidStack == null) {
return request;
Expand All @@ -165,7 +181,6 @@ public IAEItemStack injectItems(IAEItemStack request, Actionable type, BaseActio

@Override
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) {
/*if (conflict) return null;*/
IAEFluidStack fluidStack = ItemFluidDrop.getAeFluidStack(request);
if (fluidStack == null) {
return null;
Expand All @@ -188,7 +203,6 @@ public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActi

@Override
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
/*if (conflict) return out;*/
if (itemCache == null) {
itemCache = new ArrayList<>();
IMEMonitor<IAEFluidStack> fluidGrid = getFluidGrid();
Expand Down Expand Up @@ -253,7 +267,6 @@ private class FluidCraftingInventory implements IMEInventory<IAEFluidStack> {
@Override
@SuppressWarnings("rawtypes")
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) {
/*if (conflict) return null;*/
ICraftingGrid craftingGrid;
try {
craftingGrid = getProxy().getGrid().getCache(ICraftingGrid.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.me.GridAccessException;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalAEInventory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ public void run() {
FluidRecipe.addRecipeMap(null, new ForestryRecipeExtractor(new NEIHandlerStill()));
}

if (ModAndClassUtil.IC2) {
FluidRecipe.addRecipeMap("blastfurnace", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("BlockCutter", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("centrifuge", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("compressor", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("extractor", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("fluidcanner", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("macerator", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("metalformer", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("oreWashing", new IndustrialCraftRecipeExtractor());
FluidRecipe.addRecipeMap("solidcanner", new IndustrialCraftRecipeExtractor());
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.glodblock.github.nei.recipes.extractor;

import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import com.glodblock.github.nei.object.IRecipeExtractor;
import com.glodblock.github.nei.object.OrderStack;
import com.glodblock.github.util.Ae2Reflect;
import ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler;
import ic2.neiIntegration.core.recipehandler.OreWashingRecipeHandler;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class IndustrialCraftRecipeExtractor implements IRecipeExtractor {

@Override
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
List<OrderStack<?>> tmp = new LinkedList<>();
for (int i = 0; i < rawInputs.size(); i ++) {
if (rawInputs.get(i) == null) continue;
tmp.add(OrderStack.pack(rawInputs.get(i), i));
}
return tmp;
}

@Override
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
List<OrderStack<?>> tmp = new LinkedList<>();
for (int i = 0; i < rawOutputs.size(); i ++) {
if (rawOutputs.get(i) == null) continue;
tmp.add(OrderStack.pack(rawOutputs.get(i), i));
}
return tmp;
}

@Override
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
List<OrderStack<?>> stacks = new LinkedList<>();

if (recipe instanceof FluidCannerRecipeHandler) {
FluidCannerRecipeHandler.CachedFluidCannerRecipe cachedRecipe = (FluidCannerRecipeHandler.CachedFluidCannerRecipe) ((FluidCannerRecipeHandler) recipe).arecipes.get(index);
FluidStack input = ReflectIC2.getInputFluid(cachedRecipe);
PositionedStack add = rawInputs.size() > 1 ? rawInputs.get(1) : null;
stacks.add(OrderStack.pack(add, 0));
stacks.add(new OrderStack<>(input, 1));
}
else if (recipe instanceof OreWashingRecipeHandler) {
stacks = getInputIngredients(rawInputs);
int water = ReflectIC2.getOreWasherWater((OreWashingRecipeHandler) recipe, index);
stacks.add(new OrderStack<>(new FluidStack(FluidRegistry.WATER, water), stacks.size()));
} else {
stacks = getInputIngredients(rawInputs);
}

return stacks.stream().filter(Objects::nonNull).collect(Collectors.toList());
}

@Override
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs, IRecipeHandler recipe, int index) {
List<OrderStack<?>> stacks = new LinkedList<>();

if (recipe instanceof FluidCannerRecipeHandler) {
FluidCannerRecipeHandler.CachedFluidCannerRecipe cachedRecipe = (FluidCannerRecipeHandler.CachedFluidCannerRecipe) ((FluidCannerRecipeHandler) recipe).arecipes.get(index);
FluidStack output = ReflectIC2.getOutputFluid(cachedRecipe);
stacks.add(new OrderStack<>(output, 0));
} else {
stacks = getOutputIngredients(rawOutputs);
}

return stacks.stream().filter(Objects::nonNull).collect(Collectors.toList());
}

private static class ReflectIC2 {

private final static Field inputsF;
private final static Field resultF;

private final static Method oreWasherWater;

static {
try {
inputsF = Ae2Reflect.reflectField(FluidCannerRecipeHandler.CachedFluidCannerRecipe.class, "fluidInput");
resultF = Ae2Reflect.reflectField(FluidCannerRecipeHandler.CachedFluidCannerRecipe.class, "fluidOutput");
oreWasherWater = Ae2Reflect.reflectMethod(OreWashingRecipeHandler.class, "getreqWater", int.class);
} catch (NoSuchFieldException | NoSuchMethodException e) {
throw new IllegalStateException("Failed to initialize IC2 reflection hacks!", e);
}
}

private static FluidStack getInputFluid(FluidCannerRecipeHandler.CachedFluidCannerRecipe recipe) {
return Ae2Reflect.readField(recipe, inputsF);
}

private static FluidStack getOutputFluid(FluidCannerRecipeHandler.CachedFluidCannerRecipe recipe) {
return Ae2Reflect.readField(recipe, resultF);
}

private static int getOreWasherWater(OreWashingRecipeHandler recipeHandler, int index) {
try {
return (int) oreWasherWater.invoke(recipeHandler, index);
} catch (Exception e) {
throw new IllegalStateException("Failed to invoke method: " + oreWasherWater, e);
}
}

}

}
5 changes: 4 additions & 1 deletion src/main/java/com/glodblock/github/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.glodblock.github.loader.ListenerLoader;
import com.glodblock.github.loader.RenderLoader;
import com.glodblock.github.nei.recipes.DefaultExtractorLoader;
import com.glodblock.github.util.ModAndClassUtil;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -24,6 +25,8 @@ public void init(FMLInitializationEvent event){
@Override
public void postInit(FMLPostInitializationEvent event){
super.postInit(event);
(new DefaultExtractorLoader()).run();
if (ModAndClassUtil.NEI) {
(new DefaultExtractorLoader()).run();
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/glodblock/github/util/ModAndClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public final class ModAndClassUtil {
public static boolean OC = false;
public static boolean ThE = false;
public static boolean WCT = false;
public static boolean IC2 = false;
public static boolean NEI = false;
public static boolean GTPP = false;

public static boolean isDoubleButton;
Expand Down Expand Up @@ -113,6 +115,10 @@ public static void init() {
ThE = true;
if (Loader.isModLoaded("ae2wct"))
WCT = true;
if (Loader.isModLoaded("IC2"))
IC2 = true;
if (Loader.isModLoaded("NotEnoughItems"))
NEI = true;
if (Loader.isModLoaded("miscutils"))
GTPP = true;
}
Expand Down

0 comments on commit c961a5d

Please sign in to comment.