mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 18:44:42 +00:00
Compatibility with ae native fluid (#293)
Co-authored-by: lordIcocain <[email protected]> Co-authored-by: Martin Robertz <[email protected]> Co-authored-by: Kogepan229 <[email protected]>
This commit is contained in:
17 files changed
+228
-1334
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package com.glodblock.github.common.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -23,6 +22,7 @@ import com.glodblock.github.util.NameConst;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -40,11 +40,34 @@ public class ItemFluidPacket extends FCBaseItem {
|
||||
if (stack == null || !stack.hasTagCompound()) {
|
||||
return null;
|
||||
}
|
||||
FluidStack fluid = FluidStack
|
||||
.loadFluidStackFromNBT(Objects.requireNonNull(stack.getTagCompound()).getCompoundTag("FluidStack"));
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
|
||||
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tag);
|
||||
if (fluid != null && tag.getLong("Amount") > Integer.MAX_VALUE) fluid.amount = Integer.MAX_VALUE;
|
||||
return (fluid != null && fluid.amount > 0) ? fluid : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
|
||||
return stack != null ? getFluidStack(stack.getItemStack()) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IAEFluidStack getFluidAEStack(ItemStack stack) {
|
||||
if (stack != null && stack.hasTagCompound()) {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
|
||||
IAEFluidStack ifs = AEFluidStack.create(FluidStack.loadFluidStackFromNBT(tag));
|
||||
if (ifs != null && tag.hasKey("Amount")) ifs.setStackSize(tag.getLong("Amount"));
|
||||
return ifs;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IAEFluidStack getFluidAEStack(@Nullable IAEItemStack stack) {
|
||||
return stack != null ? getFluidAEStack(stack.getItemStack()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
FluidStack fluid = getFluidStack(stack);
|
||||
@@ -83,25 +106,20 @@ public class ItemFluidPacket extends FCBaseItem {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
|
||||
return stack != null ? getFluidStack(stack.getItemStack()) : null;
|
||||
}
|
||||
|
||||
public static void setFluidAmount(ItemStack stack, int amount) {
|
||||
public static void setFluidAmount(ItemStack stack, long amount) {
|
||||
if (stack == null || !stack.hasTagCompound()
|
||||
|| !stack.getTagCompound().hasKey("FluidStack", Constants.NBT.TAG_COMPOUND)) {
|
||||
return;
|
||||
}
|
||||
stack.getTagCompound().getCompoundTag("FluidStack").setInteger("Amount", amount);
|
||||
stack.getTagCompound().getCompoundTag("FluidStack").setLong("Amount", amount);
|
||||
}
|
||||
|
||||
public static int getFluidAmount(ItemStack stack) {
|
||||
public static long getFluidAmount(ItemStack stack) {
|
||||
if (stack == null || !stack.hasTagCompound()) {
|
||||
return 0;
|
||||
}
|
||||
// Default to 0 if no tag exists
|
||||
return stack.getTagCompound().getCompoundTag("FluidStack").getInteger("Amount");
|
||||
return stack.getTagCompound().getCompoundTag("FluidStack").getLong("Amount");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -120,10 +138,22 @@ public class ItemFluidPacket extends FCBaseItem {
|
||||
|
||||
@Nullable
|
||||
public static ItemStack newStack(@Nullable IAEFluidStack fluid) {
|
||||
if (fluid == null || fluid.getStackSize() == 0) {
|
||||
return null;
|
||||
if (fluid != null && fluid.getStackSize() > 0) {
|
||||
ItemStack stack = new ItemStack(ItemAndBlockHolder.PACKET);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
NBTTagCompound fluidTag = new NBTTagCompound();
|
||||
fluid.getFluidStack().writeToNBT(fluidTag);
|
||||
fluidTag.setLong("Amount", fluid.getStackSize());
|
||||
tag.setTag("FluidStack", fluidTag);
|
||||
stack.setTagCompound(tag);
|
||||
return stack;
|
||||
}
|
||||
return newStack(fluid.getFluidStack());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
|
||||
return AEItemStack.create(newStack(fluid));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -143,11 +173,6 @@ public class ItemFluidPacket extends FCBaseItem {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
|
||||
return AEItemStack.create(newStack(fluid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpriteNumber() {
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import static appeng.util.Platform.convertStack;
|
||||
import static appeng.util.Platform.stackConvert;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -11,11 +14,11 @@ import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
|
||||
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.InsertionMode;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.SchedulingMode;
|
||||
@@ -43,7 +46,6 @@ import appeng.me.GridAccessException;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -269,7 +271,7 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
|
||||
}
|
||||
|
||||
protected InventoryAdaptor getHandler(TileEntity target) {
|
||||
return target != null ? FluidConvertingInventoryAdaptor.wrap(target, this.getSide().getOpposite()) : null;
|
||||
return target != null ? InventoryAdaptor.getAdaptor(target, getSide().getOpposite()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,17 +284,15 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
|
||||
final double power = Math.ceil(items.getStackSize() / 1000D);
|
||||
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
ItemStack inputStack = items.getItemStack();
|
||||
|
||||
ItemStack remaining;
|
||||
IAEItemStack remaining;
|
||||
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
remaining = d.simulateAdd(inputStack);
|
||||
remaining = stackConvert(d.simulateAddStack(convertStack(items), InsertionMode.DEFAULT));
|
||||
} else {
|
||||
remaining = d.addItems(inputStack);
|
||||
remaining = stackConvert(d.addStack(convertStack(items), InsertionMode.DEFAULT));
|
||||
}
|
||||
|
||||
return AEItemStack.create(remaining);
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
|
||||
@@ -53,6 +53,7 @@ import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
@@ -173,10 +174,13 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.addDrops(drops);
|
||||
} catch (GridAccessException ignored) {}
|
||||
} else {
|
||||
if (this.getWaitingToSend() != null) {
|
||||
for (final ItemStack is : this.getWaitingToSend()) {
|
||||
if (is != null) {
|
||||
drops.add(is);
|
||||
List<IAEStack<?>> waitingList = this.getWaitingToSend();
|
||||
if (waitingList != null) {
|
||||
for (final IAEStack<?> as : waitingList) {
|
||||
if (as instanceof IAEItemStack ais) {
|
||||
drops.add(ais.getItemStack());
|
||||
} else if (as instanceof IAEFluidStack afs) {
|
||||
drops.add(ItemFluidPacket.newStack(afs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import static appeng.util.Platform.writeStackNBT;
|
||||
import static com.glodblock.github.loader.RecipeLoader.BUCKET;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -17,7 +18,8 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -53,6 +55,8 @@ import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class TileFluidAutoFiller extends AENetworkInvTile
|
||||
implements ICraftingProvider, IMEMonitorHandlerReceiver<IAEFluidStack>, IGridTickable {
|
||||
@@ -60,7 +64,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
|
||||
private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1);
|
||||
private final BaseActionSource source = new MachineSource(this);
|
||||
private IItemList<IAEFluidStack> fluids = AEApi.instance().storage().createFluidList();
|
||||
private final Item encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeItem().orNull();
|
||||
private final Item encodedPattern = GameRegistry.findItem(FluidCraft.MODID, NameConst.ITEM_FLUID_ENCODED_PATTERN);
|
||||
private IAEItemStack returnStack;
|
||||
private boolean isPowered;
|
||||
|
||||
@@ -156,19 +160,21 @@ public class TileFluidAutoFiller extends AENetworkInvTile
|
||||
MutablePair<Integer, ItemStack> filled = Util.FluidUtil
|
||||
.fillStack(this.getContainerItem().copy(), new FluidStack(fluid, maxCapacity));
|
||||
if (filled.right == null) continue;
|
||||
ItemStack pattern = getPattern(this.getContainerItem(), filled.right);
|
||||
ItemStack pattern = getPattern(
|
||||
this.getContainerItem(),
|
||||
filled.right,
|
||||
fluidStack.copy().setStackSize(maxCapacity));
|
||||
ICraftingPatternItem patter = (ICraftingPatternItem) pattern.getItem();
|
||||
craftingTracker.addCraftingOption(this, patter.getPatternForItem(pattern, getWorldObj()));
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer) {
|
||||
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer, IAEFluidStack ifs) {
|
||||
NBTTagList in = new NBTTagList();
|
||||
NBTTagList out = new NBTTagList();
|
||||
in.appendTag(emptyContainer.writeToNBT(new NBTTagCompound()));
|
||||
ItemStack fluidDrop = ItemFluidDrop.newStack(Util.FluidUtil.getFluidFromContainer(filledContainer));
|
||||
in.appendTag(createItemTag(fluidDrop));
|
||||
out.appendTag(filledContainer.writeToNBT(new NBTTagCompound()));
|
||||
in.appendTag(writeStackNBT(AEItemStack.create(emptyContainer), new NBTTagCompound()));
|
||||
in.appendTag(writeStackNBT(ifs, new NBTTagCompound()));
|
||||
out.appendTag(writeStackNBT(AEItemStack.create(filledContainer), new NBTTagCompound()));
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setTag("in", in);
|
||||
itemTag.setTag("out", out);
|
||||
@@ -188,8 +194,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
|
||||
this.returnStack = AEApi.instance().storage()
|
||||
.createItemStack(patternDetails.getCondensedOutputs()[0].getItemStack());
|
||||
this.returnStack = (IAEItemStack) patternDetails.getCondensedOutputs()[0];
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (GridAccessException ignored) {
|
||||
|
||||
@@ -224,7 +224,6 @@ public class TileFluidInterface extends TileInterface implements IDualHost {
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, List<ItemStack> drops) {
|
||||
this.fluidDuality.addDrops(drops);
|
||||
this.fluidDuality.convertDrops(drops, this.getInterfaceDuality().getWaitingToSend());
|
||||
super.getDrops(w, x, y, z, drops);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user