mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-15 17:44:46 +00:00
add Fluid Buffer
This commit is contained in:
1 parent
5e31096c7e
commit
77ccfb5606
16 files changed
+436
-56
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package com.glodblock.github.common.block;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.block.AEBaseItemBlock;
|
||||
import appeng.util.Platform;
|
||||
import com.glodblock.github.client.render.RenderBlockFluidBuffer;
|
||||
import com.glodblock.github.common.tabs.FluidCraftingTabs;
|
||||
import com.glodblock.github.common.tile.TileFluidBuffer;
|
||||
import com.glodblock.github.crossmod.waila.Tooltip;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class BlockFluidBuffer extends FCBaseBlock {
|
||||
|
||||
public BlockFluidBuffer() {
|
||||
super(Material.iron, NameConst.BLOCK_FLUID_BUFFER);
|
||||
setTileEntity(TileFluidBuffer.class);
|
||||
setFullBlock(false);
|
||||
setOpaque(false);
|
||||
this.lightOpacity = 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivated(
|
||||
World world, int x, int y, int z, EntityPlayer player, int facing, float hitX, float hitY, float hitZ) {
|
||||
ItemStack itemStack = player.inventory.getCurrentItem();
|
||||
FluidStack fs = Util.getFluidFromItem(itemStack);
|
||||
if (Platform.isServer()) {
|
||||
TileFluidBuffer tile = getTileEntity(world, x, y, z);
|
||||
if (tile == null) return false;
|
||||
IAEFluidStack ias = tile.getAEStoreFluidStack();
|
||||
if (fs == null && ias != null) {
|
||||
player.addChatMessage(new ChatComponentText(
|
||||
Tooltip.fluidFormat(ias.getFluid().getLocalizedName(), ias.getStackSize())));
|
||||
return false;
|
||||
} else {
|
||||
tile.setFluid(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return fs != null;
|
||||
}
|
||||
|
||||
public BlockFluidBuffer register() {
|
||||
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_FLUID_BUFFER);
|
||||
GameRegistry.registerTileEntity(TileFluidBuffer.class, NameConst.BLOCK_FLUID_BUFFER);
|
||||
setCreativeTab(FluidCraftingTabs.INSTANCE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected RenderBlockFluidBuffer getRenderer() {
|
||||
return new RenderBlockFluidBuffer();
|
||||
}
|
||||
|
||||
public ItemStack stack(int size) {
|
||||
return new ItemStack(this, size);
|
||||
}
|
||||
|
||||
public ItemStack stack() {
|
||||
return new ItemStack(this, 1);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.util.FluidPatternDetails;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFluidEncodedPattern extends ItemEncodedPattern {
|
||||
@@ -31,19 +28,6 @@ public class ItemFluidEncodedPattern extends ItemEncodedPattern {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(
|
||||
final ItemStack stack, final EntityPlayer player, final List<String> lines, final boolean displayMoreInfo) {
|
||||
NBTTagCompound data = stack.getTagCompound();
|
||||
final boolean combine = data.getBoolean("combine");
|
||||
final boolean prio = data.getBoolean("prioritize");
|
||||
super.addCheckedInformation(stack, player, lines, displayMoreInfo);
|
||||
// lines.add(String.format("%s: %s",combine ?
|
||||
// StatCollector.translateToLocal(NameConst.TT_KEY+"combine"):StatCollector.translateToLocal(NameConst.TT_KEY+"not_combine"),combine ? GuiText.Yes.getLocal() : GuiText.No.getLocal()));
|
||||
// lines.add(String.format("%s: %s",prio ?
|
||||
// StatCollector.translateToLocal(NameConst.TT_KEY+"prio"):StatCollector.translateToLocal(NameConst.TT_KEY+"not_prio"),prio ? GuiText.Yes.getLocal() : GuiText.No.getLocal()));
|
||||
}
|
||||
|
||||
public ItemStack stack() {
|
||||
return new ItemStack(this, 1);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class PartFluidPatternTerminal extends FCBasePart {
|
||||
if (newStack != null) {
|
||||
NBTTagCompound data = newStack.getTagCompound();
|
||||
this.setCombineMode(data.getInteger("combine") == 1);
|
||||
// this.setBeSubstitute(data.getBoolean("beSubstitute"));
|
||||
this.setBeSubstitute(data.getBoolean("beSubstitute"));
|
||||
}
|
||||
for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
|
||||
this.crafting.setInventorySlotContents(i, null);
|
||||
|
||||
@@ -166,7 +166,7 @@ public class PartFluidPatternTerminalEx extends FCBasePart {
|
||||
if (newStack != null) {
|
||||
NBTTagCompound data = newStack.getTagCompound();
|
||||
this.setCombineMode(data.getInteger("combine") == 1);
|
||||
// this.setBeSubstitute(data.getBoolean("beSubstitute"));
|
||||
this.setBeSubstitute(data.getBoolean("beSubstitute"));
|
||||
}
|
||||
this.setInverted(inputsCount <= 8 && outputCount > 8);
|
||||
this.setActivePage(0);
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
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.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import com.glodblock.github.inventory.AEFluidInventory;
|
||||
import com.glodblock.github.inventory.IAEFluidInventory;
|
||||
import com.glodblock.github.inventory.IAEFluidTank;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class TileFluidBuffer extends AENetworkTile
|
||||
implements IAEFluidInventory, IFluidHandler, IPowerChannelState, IGridTickable {
|
||||
|
||||
private final AEFluidInventory invFluids = new AEFluidInventory(this, 1, Integer.MAX_VALUE);
|
||||
private final BaseActionSource source;
|
||||
private boolean isPowered;
|
||||
|
||||
public TileFluidBuffer() {
|
||||
getProxy().setIdlePowerUsage(2D);
|
||||
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
public boolean setFluid(FluidStack fs) {
|
||||
return this.setFluid(fs, Actionable.MODULATE);
|
||||
}
|
||||
|
||||
public boolean setFluid(FluidStack fs, Actionable actionable) {
|
||||
if (fs == null) {
|
||||
this.invFluids.setFluidInSlot(0, null);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
IAEFluidStack ias = this.getProxy()
|
||||
.getStorage()
|
||||
.getFluidInventory()
|
||||
.getStorageList()
|
||||
.findPrecise(AEFluidStack.create(fs));
|
||||
if (actionable == Actionable.MODULATE) this.invFluids.setFluidInSlot(0, ias);
|
||||
if (ias != null) return true;
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection forgeDirection, FluidStack fluidStack, boolean b) {
|
||||
IAEFluidStack ifs = this.getAEFluidStack();
|
||||
if (ifs != null && ifs.getFluid() == fluidStack.getFluid()) {
|
||||
try {
|
||||
IAEFluidStack notInserted = this.getProxy()
|
||||
.getStorage()
|
||||
.getFluidInventory()
|
||||
.injectItems(
|
||||
AEFluidStack.create(fluidStack),
|
||||
b ? Actionable.MODULATE : Actionable.SIMULATE,
|
||||
this.source);
|
||||
if (notInserted != null) return fluidStack.amount -= notInserted.getStackSize();
|
||||
return fluidStack.amount;
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection forgeDirection, FluidStack fluidStack, boolean b) {
|
||||
return this.drainFluid(fluidStack, b ? Actionable.MODULATE : Actionable.SIMULATE);
|
||||
}
|
||||
|
||||
public FluidStack drainFluid(FluidStack fs, Actionable actionable) {
|
||||
if (fs == null || fs.amount <= 0) return null;
|
||||
try {
|
||||
IAEFluidStack ias = AEFluidStack.create(fs);
|
||||
IAEFluidStack extracted =
|
||||
this.getProxy().getStorage().getFluidInventory().extractItems(ias, actionable, this.source);
|
||||
if (extracted == null) return null;
|
||||
return extracted.getFluidStack();
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection forgeDirection, int maxDrain, boolean b) {
|
||||
FluidStack fs = this.getFluidStack();
|
||||
if (maxDrain == 0 || fs == null) {
|
||||
return null;
|
||||
}
|
||||
FluidStack tmp = fs.copy();
|
||||
tmp.amount = maxDrain;
|
||||
return this.drainFluid(tmp, b ? Actionable.MODULATE : Actionable.SIMULATE);
|
||||
}
|
||||
|
||||
public IAEFluidStack getAEStoreFluidStack() {
|
||||
try {
|
||||
return this.getProxy()
|
||||
.getStorage()
|
||||
.getFluidInventory()
|
||||
.getStorageList()
|
||||
.findPrecise(this.getAEFluidStack());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidStack getFluidStack() {
|
||||
return this.getInternalFluid().getFluidStackInSlot(0);
|
||||
}
|
||||
|
||||
public IAEFluidStack getAEFluidStack() {
|
||||
return this.getInternalFluid().getFluidInSlot(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection forgeDirection, Fluid fluid) {
|
||||
FluidStack fs = this.getFluidStack();
|
||||
return fs != null && fs.getFluid() == fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return getInternalFluid().canDrain(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
FluidTankInfo[] FluidTankInfos = getInternalFluid().getTankInfo(from);
|
||||
FluidTankInfo[] tmp = FluidTankInfos.clone();
|
||||
for (FluidTankInfo ft : tmp) {
|
||||
if (ft.fluid == null) continue;
|
||||
ft.fluid.amount = 0;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
|
||||
invFluids.writeToNBT(data, "FluidInv");
|
||||
return data;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBTEvent(NBTTagCompound data) {
|
||||
invFluids.readFromNBT(data, "FluidInv");
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream(final ByteBuf data) {
|
||||
final boolean oldPower = this.isPowered;
|
||||
this.isPowered = data.readBoolean();
|
||||
return this.isPowered != oldPower;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream(final ByteBuf data) {
|
||||
data.writeBoolean(this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered() {
|
||||
return this.isPowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return this.isPowered;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange p) {
|
||||
this.updatePowerState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void bootingRender(final MENetworkBootingStatusChange c) {
|
||||
this.updatePowerState();
|
||||
}
|
||||
|
||||
private void updatePowerState() {
|
||||
boolean newState = false;
|
||||
try {
|
||||
newState = this.getProxy().isActive()
|
||||
&& this.getProxy().getEnergy().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG)
|
||||
> 0.0001;
|
||||
} catch (final GridAccessException ignored) {
|
||||
}
|
||||
if (newState != this.isPowered) {
|
||||
this.isPowered = newState;
|
||||
this.markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
saveChanges();
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEFluidInventory getInternalFluid() {
|
||||
return this.invFluids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(40, 120, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
private TickRateModulation doWork() {
|
||||
return this.setFluid(this.getFluidStack(), Actionable.SIMULATE)
|
||||
? TickRateModulation.SLOWER
|
||||
: TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
private boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user