mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-18 19:29:08 +00:00
Universal GUI (#340)
Co-authored-by: Kogepan229 <[email protected]> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
213 files changed
+1859
-19432
No files matched your search
@@ -1,69 +1,29 @@
|
||||
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;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
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.google.common.collect.ImmutableSet;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
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;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.StorageName;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AELog;
|
||||
import appeng.helpers.MultiCraftingTracker;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartBaseExportBus;
|
||||
import appeng.tile.inventory.IAEStackInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingRequester {
|
||||
|
||||
private final BaseActionSource source;
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, 9);
|
||||
private int nextSlot = 0;
|
||||
private long fluidToSend = 1000;
|
||||
private boolean didSomething;
|
||||
public class PartFluidExportBus extends PartBaseExportBus<IAEFluidStack> {
|
||||
|
||||
public PartFluidExportBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,238 +32,63 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(5, 40, this.isSleeping(), false);
|
||||
protected int getAdaptorFlags() {
|
||||
return InventoryAdaptor.DEFAULT & ~InventoryAdaptor.ALLOW_ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
private int getStartingSlot(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.RANDOM) {
|
||||
return Platform.getRandom().nextInt(this.availableSlots());
|
||||
public int calculateAmountToSend() {
|
||||
double amount = 1000D;
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
case 4:
|
||||
amount = amount * 1.5;
|
||||
case 3:
|
||||
amount = amount * 2;
|
||||
case 2:
|
||||
amount = amount * 4;
|
||||
case 1:
|
||||
amount = amount * 8;
|
||||
}
|
||||
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
return (this.nextSlot + x) % this.availableSlots();
|
||||
switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) {
|
||||
case 4:
|
||||
amount = amount * 8;
|
||||
case 3:
|
||||
amount = amount * 12;
|
||||
case 2:
|
||||
amount = amount * 16;
|
||||
case 1:
|
||||
amount = amount * 32;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
private int availableSlots() {
|
||||
return Math.min(1 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 4, this.getInv().getSizeInventory());
|
||||
}
|
||||
|
||||
private IInventory getInv() {
|
||||
return this.getInventoryByName("config");
|
||||
return (int) Math.floor(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
this.didSomething = false;
|
||||
this.fluidToSend = this.calculateAmountToSend();
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
InventoryAdaptor destination;
|
||||
if (te instanceof IFluidHandler && (destination = this.getHandler(te)) != null) {
|
||||
try {
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final IFluidHandler fh = (IFluidHandler) te;
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getFluidInventory();
|
||||
int i;
|
||||
for (i = 0; i < this.availableSlots() && this.fluidToSend > 0; i++) {
|
||||
final int slotToExport = this.getStartingSlot(this.getSchedulingMode(), i);
|
||||
IAEFluidStack fluid = AEFluidStack
|
||||
.create(ItemFluidPacket.getFluidStack(getInv().getStackInSlot(slotToExport)));
|
||||
if (fluid != null) {
|
||||
fluid.setStackSize(this.calculateAmountToSend());
|
||||
if (this.craftOnly()) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(
|
||||
i,
|
||||
fluid.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(fluid),
|
||||
destination,
|
||||
this.getTile().getWorldObj(),
|
||||
this.getProxy().getGrid(),
|
||||
cg,
|
||||
this.source);
|
||||
continue;
|
||||
}
|
||||
// Find out how much to push
|
||||
final IAEFluidStack toPush = fluid.copy();
|
||||
final int amtToInsert = fh.fill(this.getSide().getOpposite(), toPush.getFluidStack(), false);
|
||||
toPush.setStackSize(amtToInsert);
|
||||
// Extract from the ME system. This might not be the same amount we actually send...
|
||||
final IAEFluidStack real = inv.extractItems(toPush, Actionable.MODULATE, this.source);
|
||||
if (real != null) {
|
||||
int realInserted = fh.fill(this.getSide().getOpposite(), real.getFluidStack(), true);
|
||||
if (realInserted < real.getStackSize()) {
|
||||
// Could not use the entirety of the amount we extracted, so put it back.
|
||||
// This can result in voiding fluids if there's nowhere for the fluids to go.
|
||||
fluid.setStackSize(real.getStackSize() - realInserted);
|
||||
inv.injectItems(fluid, Actionable.MODULATE, this.source);
|
||||
}
|
||||
this.fluidToSend -= realInserted;
|
||||
didSomething = true;
|
||||
} else if (this.isCraftingEnabled()) {
|
||||
// If we didn't send anything, try crafting it if we can.
|
||||
this.didSomething = this.craftingTracker.handleCrafting(
|
||||
i,
|
||||
fluid.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(fluid),
|
||||
destination,
|
||||
this.getTile().getWorldObj(),
|
||||
this.getProxy().getGrid(),
|
||||
cg,
|
||||
this.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateSchedulingMode(this.getSchedulingMode(), i);
|
||||
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
} catch (GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
private void updateSchedulingMode(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
this.nextSlot = (this.nextSlot + x) % this.availableSlots();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(4, 4, 12, 12, 12, 14);
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(6, 6, 15, 10, 10, 16);
|
||||
bch.addBox(6, 6, 11, 10, 10, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon());
|
||||
|
||||
rh.setBounds(4, 4, 12, 12, 12, 14);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(5, 5, 14, 11, 11, 15);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(6, 6, 15, 10, 10, 16);
|
||||
rh.renderInventoryBox(renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache()));
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon(),
|
||||
CableBusTextures.PartExportSides.getIcon());
|
||||
|
||||
rh.setBounds(4, 4, 12, 12, 12, 14);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setBounds(5, 5, 14, 11, 11, 15);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setBounds(6, 6, 15, 10, 10, 16);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon());
|
||||
|
||||
rh.setBounds(6, 6, 11, 10, 10, 12);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
this.renderLights(x, y, z, rh, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
public SchedulingMode getSchedulingMode() {
|
||||
return (SchedulingMode) this.getConfigManager().getSetting(Settings.SCHEDULING_MODE);
|
||||
}
|
||||
|
||||
private boolean craftOnly() {
|
||||
return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean isCraftingEnabled() {
|
||||
return this.getInstalledUpgrades(Upgrades.CRAFTING) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
|
||||
protected InventoryAdaptor getHandler(TileEntity target) {
|
||||
return target != null ? InventoryAdaptor.getAdaptor(target, getSide().getOpposite()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
|
||||
final InventoryAdaptor d = this.getHandler(getConnectedTE());
|
||||
|
||||
protected IMEMonitor<IAEFluidStack> getMonitor() {
|
||||
try {
|
||||
if (d != null && this.getProxy().isActive()) {
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final double power = Math.ceil(items.getStackSize() / 1000D);
|
||||
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
IAEItemStack remaining;
|
||||
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
remaining = stackConvert(d.simulateAddStack(convertStack(items), InsertionMode.DEFAULT));
|
||||
} else {
|
||||
remaining = stackConvert(d.addStack(convertStack(items), InsertionMode.DEFAULT));
|
||||
}
|
||||
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
return this.getProxy().getStorage().getFluidInventory();
|
||||
} catch (final GridAccessException e) {
|
||||
AELog.debug(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link) {
|
||||
this.craftingTracker.jobStateChange(link);
|
||||
protected void doFuzzy(IAEFluidStack aes, FuzzyMode fzMode, InventoryAdaptor destination, IEnergyGrid energy,
|
||||
IMEMonitor<IAEFluidStack> gridInv) {}
|
||||
|
||||
@Override
|
||||
protected void doOreDict(InventoryAdaptor destination, IEnergyGrid energy, IMEMonitor<IAEFluidStack> gridInv) {}
|
||||
|
||||
// legacy
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
|
||||
final IAEStackInventory config = this.getAEInventoryByName(StorageName.NONE);
|
||||
for (int i = 0; i < config.getSizeInventory(); i++) {
|
||||
final IAEStack<?> stack = config.getAEStackInSlot(i);
|
||||
if (stack instanceof IAEItemStack ais) {
|
||||
config.putAEStackInSlot(i, Util.getAEFluidFromItem(ais.getItemStack()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,37 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.SchedulingMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.StorageName;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartBaseImportBus;
|
||||
import appeng.tile.inventory.IAEStackInventory;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartFluidImportBus extends FCSharedFluidBus {
|
||||
|
||||
private final BaseActionSource source;
|
||||
public class PartFluidImportBus extends PartBaseImportBus<IAEFluidStack> {
|
||||
|
||||
public PartFluidImportBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,79 +40,108 @@ public class PartFluidImportBus extends FCSharedFluidBus {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(5, 40, this.isSleeping(), false);
|
||||
protected Object getTarget() {
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity(self, (new BlockPos(self)).getOffSet(this.getSide()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorldObj();
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
if (w.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)) {
|
||||
return w.getTileEntity(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (te instanceof IFluidHandler) {
|
||||
try {
|
||||
final IFluidHandler fh = (IFluidHandler) te;
|
||||
FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite());
|
||||
if (tanksInfo == null) {
|
||||
return TickRateModulation.SLOWER;
|
||||
@Override
|
||||
public int calculateAmountToSend() {
|
||||
double amount = 1000D;
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
case 4:
|
||||
amount = amount * 1.5;
|
||||
case 3:
|
||||
amount = amount * 2;
|
||||
case 2:
|
||||
amount = amount * 4;
|
||||
case 1:
|
||||
amount = amount * 8;
|
||||
}
|
||||
switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) {
|
||||
case 4:
|
||||
amount = amount * 8;
|
||||
case 3:
|
||||
amount = amount * 12;
|
||||
case 2:
|
||||
amount = amount * 16;
|
||||
case 1:
|
||||
amount = amount * 32;
|
||||
}
|
||||
return (int) Math.floor(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMEMonitor<IAEFluidStack> getMonitor() {
|
||||
try {
|
||||
return this.getProxy().getStorage().getFluidInventory();
|
||||
} catch (final GridAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean importStuff(final Object myTarget, final IAEFluidStack whatToImport,
|
||||
final IMEMonitor<IAEFluidStack> inv, final IEnergySource energy, final FuzzyMode fzMode) {
|
||||
if (myTarget instanceof IFluidHandler fh) {
|
||||
FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite());
|
||||
if (tanksInfo == null) return true;
|
||||
|
||||
int maxDrain = this.calculateAmountToSend();
|
||||
boolean doBreak = true;
|
||||
|
||||
for (FluidTankInfo tankInfo : tanksInfo) {
|
||||
if (tankInfo.fluid == null) continue;
|
||||
|
||||
FluidStack fluidStack = new FluidStack(tankInfo.fluid, Math.min(tankInfo.fluid.amount, maxDrain));
|
||||
fluidStack = fh.drain(this.getSide().getOpposite(), fluidStack, false);
|
||||
if (this.filterEnabled() && !this.isInFilter(fluidStack)) continue;
|
||||
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.create(fluidStack);
|
||||
if (aeFluidStack != null) {
|
||||
final IAEFluidStack notInserted = inv.injectItems(aeFluidStack, Actionable.MODULATE, this.mySrc);
|
||||
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
aeFluidStack.decStackSize(notInserted.getStackSize());
|
||||
}
|
||||
|
||||
fh.drain(this.getSide().getOpposite(), aeFluidStack.getFluidStack(), true);
|
||||
maxDrain -= aeFluidStack.getFluidStack().amount;
|
||||
doBreak = false;
|
||||
}
|
||||
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getFluidInventory();
|
||||
int maxDrain = this.calculateAmountToSend();
|
||||
boolean drained = false;
|
||||
|
||||
for (FluidTankInfo tankInfo : tanksInfo) {
|
||||
if (tankInfo.fluid == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FluidStack fluidStack = new FluidStack(tankInfo.fluid, Math.min(tankInfo.fluid.amount, maxDrain));
|
||||
fluidStack = fh.drain(this.getSide().getOpposite(), fluidStack, false);
|
||||
if (this.filterEnabled() && !this.isInFilter(fluidStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.create(fluidStack);
|
||||
if (aeFluidStack != null) {
|
||||
final IAEFluidStack notInserted = inv
|
||||
.injectItems(aeFluidStack, Actionable.MODULATE, this.source);
|
||||
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
aeFluidStack.decStackSize(notInserted.getStackSize());
|
||||
}
|
||||
|
||||
fh.drain(this.getSide().getOpposite(), aeFluidStack.getFluidStack(), true);
|
||||
maxDrain -= aeFluidStack.getFluidStack().amount;
|
||||
drained = true;
|
||||
}
|
||||
}
|
||||
|
||||
return drained ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return doBreak;
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
protected boolean doOreDict(final Object myTarget, IMEMonitor<IAEFluidStack> inv, IEnergyGrid energy,
|
||||
FuzzyMode fzMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPowerMultiplier() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
private boolean isInFilter(FluidStack fluid) {
|
||||
for (int i = 0; i < this.getInventoryByName("config").getSizeInventory(); i++) {
|
||||
final IAEFluidStack stack = AEFluidStack
|
||||
.create(ItemFluidPacket.getFluidStack(this.getInventoryByName("config").getStackInSlot(i)));
|
||||
final IAEStackInventory inv = this.getAEInventoryByName(StorageName.NONE);
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
final IAEFluidStack stack = (IAEFluidStack) inv.getAEStackInSlot(i);
|
||||
if (stack != null && stack.getFluidStack().equals(fluid)) {
|
||||
return true;
|
||||
}
|
||||
@@ -133,9 +150,9 @@ public class PartFluidImportBus extends FCSharedFluidBus {
|
||||
}
|
||||
|
||||
private boolean filterEnabled() {
|
||||
for (int i = 0; i < this.getInventoryByName("config").getSizeInventory(); i++) {
|
||||
final IAEFluidStack stack = AEFluidStack
|
||||
.create(ItemFluidPacket.getFluidStack(this.getInventoryByName("config").getStackInSlot(i)));
|
||||
final IAEStackInventory inv = this.getAEInventoryByName(StorageName.NONE);
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
final IAEFluidStack stack = (IAEFluidStack) inv.getAEStackInSlot(i);
|
||||
if (stack != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -143,71 +160,17 @@ public class PartFluidImportBus extends FCSharedFluidBus {
|
||||
return false;
|
||||
}
|
||||
|
||||
// legacy
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 13);
|
||||
bch.addBox(5, 5, 13, 11, 11, 14);
|
||||
bch.addBox(4, 4, 14, 12, 12, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon());
|
||||
|
||||
rh.setBounds(3, 3, 15, 13, 13, 16);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(4, 4, 14, 12, 12, 15);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(5, 5, 13, 11, 11, 14);
|
||||
rh.renderInventoryBox(renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache()));
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon(),
|
||||
CableBusTextures.PartImportSides.getIcon());
|
||||
|
||||
rh.setBounds(4, 4, 14, 12, 12, 16);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setBounds(5, 5, 13, 11, 11, 14);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setBounds(6, 6, 12, 10, 10, 13);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
this.getFaceIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon());
|
||||
|
||||
rh.setBounds(6, 6, 11, 10, 10, 12);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
this.renderLights(x, y, z, rh, renderer);
|
||||
final IAEStackInventory config = this.getAEInventoryByName(StorageName.NONE);
|
||||
for (int i = 0; i < config.getSizeInventory(); i++) {
|
||||
final IAEStack<?> stack = config.getAEStackInSlot(i);
|
||||
if (stack instanceof IAEItemStack ais) {
|
||||
config.putAEStackInSlot(i, Util.getAEFluidFromItem(ais.getItemStack()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,22 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.client.FluidInterfaceButtons;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.AEFluidInventory;
|
||||
import com.glodblock.github.inventory.IAEFluidTank;
|
||||
import com.glodblock.github.inventory.IDualHost;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.DualityFluidInterface;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
@@ -31,86 +27,27 @@ import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.helpers.ICustomButtonDataObject;
|
||||
import appeng.helpers.ICustomButtonProvider;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PartFluidInterface extends PartInterface implements IDualHost {
|
||||
public class PartFluidInterface extends PartInterface implements IDualHost, ICustomButtonProvider {
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 6);
|
||||
private final DualityFluidInterface fluidDuality = new DualityFluidInterface(this.getProxy(), this);
|
||||
|
||||
private ICustomButtonDataObject customButtonDataObject;
|
||||
|
||||
public PartFluidInterface(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache()));
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
FCPartsTexture.BlockInterface_Face.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon());
|
||||
|
||||
rh.setBounds(2, 2, 14, 14, 14, 16);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
FCPartsTexture.BlockInterface_Face.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon());
|
||||
|
||||
rh.setBounds(5, 5, 12, 11, 11, 13);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
FCPartsTexture.BlockInterface_Face.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon());
|
||||
|
||||
rh.setBounds(5, 5, 13, 11, 11, 14);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
this.renderLights(x, y, z, rh, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
FCPartsTexture.BlockInterface_Face.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon(),
|
||||
CableBusTextures.PartMonitorSides.getIcon());
|
||||
|
||||
rh.setBounds(2, 2, 14, 14, 14, 16);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(5, 5, 12, 11, 11, 13);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(5, 5, 13, 11, 11, 14);
|
||||
rh.renderInventoryBox(renderer);
|
||||
this.customButtonDataObject = new FluidInterfaceButtons(false);
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
@@ -222,22 +159,6 @@ public class PartFluidInterface extends PartInterface implements IDualHost {
|
||||
return fluidDuality.getTankInfo(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(this.getSide()),
|
||||
GuiType.DUAL_INTERFACE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
saveChanges();
|
||||
@@ -283,4 +204,38 @@ public class PartFluidInterface extends PartInterface implements IDualHost {
|
||||
return fluid;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPrimaryGuiIcon() {
|
||||
return ItemAndBlockHolder.FLUID_INTERFACE.stack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomButtonData() {}
|
||||
|
||||
@Override
|
||||
public void readCustomButtonData() {}
|
||||
|
||||
@Override
|
||||
public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset,
|
||||
List<GuiButton> buttonList) {
|
||||
if (customButtonDataObject != null)
|
||||
customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean actionPerformedCustomButtons(final GuiButton btn) {
|
||||
return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomButtonDataObject getDataObject() {
|
||||
return customButtonDataObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataObject(ICustomButtonDataObject dataObject) {
|
||||
customButtonDataObject = dataObject;
|
||||
}
|
||||
}
|
||||
@@ -1,603 +1,14 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.glodblock.github.api.registries.ILevelViewable;
|
||||
import com.glodblock.github.api.registries.LevelItemInfo;
|
||||
import com.glodblock.github.api.registries.LevelState;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingWatcher;
|
||||
import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
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.storage.IBaseMonitor;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
|
||||
public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, ICraftingWatcherHost,
|
||||
IMEMonitorHandlerReceiver<IAEFluidStack>, IGridTickable, ILevelViewable {
|
||||
|
||||
private static final int FLAG_ON = 8;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 1);
|
||||
|
||||
private boolean prevState = false;
|
||||
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
|
||||
private IStackWatcher myWatcher;
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
|
||||
private int lastWorkingTick = 0;
|
||||
private boolean delayedUpdatesQueued = false;
|
||||
public class PartFluidLevelEmitter extends PartLevelEmitter {
|
||||
|
||||
@Reflected
|
||||
public PartFluidLevelEmitter(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL);
|
||||
|
||||
// Workaround the emitter randomly breaking on world load
|
||||
if (MinecraftServer.getServer() != null) {
|
||||
delayedUpdatesQueued = true;
|
||||
lastWorkingTick = MinecraftServer.getServer().getTickCounter();
|
||||
}
|
||||
}
|
||||
|
||||
public long getReportingValue() {
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue(final long v) {
|
||||
this.reportingValue = v;
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged(final MENetworkPowerStatusChange c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if (this.prevState != isOn) {
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
|
||||
Platform.notifyBlocksOfNeighbors(
|
||||
te.getWorldObj(),
|
||||
te.xCoord + this.getSide().offsetX,
|
||||
te.yCoord + this.getSide().offsetY,
|
||||
te.zCoord + this.getSide().offsetZ);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLevelEmitterOn() {
|
||||
if (Platform.isClient()) {
|
||||
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
|
||||
}
|
||||
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Enum<?> redstoneEmitterSetting = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER);
|
||||
final boolean result;
|
||||
|
||||
if (redstoneEmitterSetting == RedstoneMode.LOW_SIGNAL) {
|
||||
result = this.reportingValue >= this.lastReportedValue + 1;
|
||||
} else {
|
||||
result = this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(final MENetworkChannelsChanged c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.prevState ? FLAG_ON : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture() {
|
||||
return this.getItemStack().getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final ICraftingWatcher newWatcher) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange(final ICraftingGrid craftingGrid, final IAEItemStack what) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
private IAEFluidStack getIAEFluidStack() {
|
||||
final FluidStack fs = ItemFluidPacket.getFluidStack(this.config.getAEStackInSlot(0));
|
||||
if (fs != null) return Util.FluidUtil.createAEFluidStack(fs);
|
||||
return null;
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers() {
|
||||
final IAEFluidStack myStack = this.getIAEFluidStack();
|
||||
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.clear();
|
||||
}
|
||||
|
||||
try {
|
||||
this.getProxy().getStorage().getFluidInventory().removeListener(this);
|
||||
if (this.myWatcher != null && myStack != null) {
|
||||
this.myWatcher.add(myStack);
|
||||
}
|
||||
|
||||
if (myStack == null) {
|
||||
this.getProxy().getStorage().getFluidInventory().addListener(this, this.getProxy().getGrid());
|
||||
}
|
||||
|
||||
this.updateReportingValue(this.getProxy().getStorage().getFluidInventory());
|
||||
} catch (final GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
|
||||
final IAEFluidStack myStack = this.getIAEFluidStack();
|
||||
|
||||
if (myStack == null) {
|
||||
this.lastReportedValue = 0;
|
||||
for (final IAEFluidStack st : monitor.getStorageList()) {
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
} else {
|
||||
final IAEFluidStack r = monitor.getStorageList().findPrecise(myStack);
|
||||
if (r == null) {
|
||||
this.lastReportedValue = 0;
|
||||
} else {
|
||||
this.lastReportedValue = r.getStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final IStackWatcher newWatcher) {
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(@SuppressWarnings("rawtypes") final IItemList o,
|
||||
@SuppressWarnings("rawtypes") final IAEStack fullStack,
|
||||
@SuppressWarnings("rawtypes") final IAEStack diffStack, final BaseActionSource src,
|
||||
final StorageChannel chan) {
|
||||
if (chan == StorageChannel.FLUIDS && fullStack.equals(this.getIAEFluidStack())) {
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final Object effectiveGrid) {
|
||||
try {
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
} catch (final GridAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(
|
||||
AEConfig.instance.levelEmitterDelay / 2,
|
||||
AEConfig.instance.levelEmitterDelay,
|
||||
!delayedUpdatesQueued,
|
||||
true);
|
||||
}
|
||||
|
||||
private boolean canDoWork() {
|
||||
int currentTick = MinecraftServer.getServer().getTickCounter();
|
||||
return (currentTick - lastWorkingTick) > AEConfig.instance.levelEmitterDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
|
||||
if (delayedUpdatesQueued && canDoWork()) {
|
||||
delayedUpdatesQueued = false;
|
||||
lastWorkingTick = MinecraftServer.getServer().getTickCounter();
|
||||
this.onListUpdate();
|
||||
}
|
||||
return delayedUpdatesQueued ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
|
||||
final BaseActionSource actionSource) {
|
||||
if (canDoWork()) {
|
||||
if (delayedUpdatesQueued) {
|
||||
delayedUpdatesQueued = false;
|
||||
try {
|
||||
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
|
||||
} catch (GridAccessException e) {
|
||||
AELog.error(e, "Couldn't put level emitter to sleep after cancelling delayed updates");
|
||||
}
|
||||
}
|
||||
lastWorkingTick = MinecraftServer.getServer().getTickCounter();
|
||||
this.updateReportingValue((IMEMonitor<IAEFluidStack>) monitor);
|
||||
} else if (!delayedUpdatesQueued) {
|
||||
delayedUpdatesQueued = true;
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (GridAccessException e) {
|
||||
AELog.error(e, "Couldn't wake up level emitter for delayed updates");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
try {
|
||||
this.updateReportingValue(this.getProxy().getStorage().getFluidInventory());
|
||||
} catch (final GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final ForgeDirection dir) {
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(7, 7, 11, 9, 9, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
|
||||
rh.setTexture(this.getItemStack().getIconIndex());
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
this.renderTorchAtAngle(0, -0.5, 0);
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
private void renderTorchAtAngle(double baseX, double baseY, double baseZ) {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
final IIcon offTexture = this.getItemStack().getIconIndex();
|
||||
final IIcon IIcon = (isOn ? CableBusTextures.LevelEmitterTorchOn.getIcon() : offTexture);
|
||||
this.centerX = baseX + 0.5;
|
||||
this.centerY = baseY + 0.5;
|
||||
this.centerZ = baseZ + 0.5;
|
||||
|
||||
baseY += 7.0 / 16.0;
|
||||
|
||||
final float var16 = IIcon.getMinU();
|
||||
final float var17 = IIcon.getMaxU();
|
||||
final float var18 = IIcon.getMinV();
|
||||
final float var19 = IIcon.getMaxV();
|
||||
|
||||
final double var20b = offTexture.getInterpolatedU(7.0D);
|
||||
final double var24b = offTexture.getInterpolatedU(9.0D);
|
||||
|
||||
final double var20 = IIcon.getInterpolatedU(7.0D);
|
||||
final double var24 = IIcon.getInterpolatedU(9.0D);
|
||||
final double var22 = IIcon.getInterpolatedV(6.0D + (isOn ? 0 : 1.0D));
|
||||
final double var26 = IIcon.getInterpolatedV(8.0D + (isOn ? 0 : 1.0D));
|
||||
final double var28 = IIcon.getInterpolatedU(7.0D);
|
||||
final double var30 = IIcon.getInterpolatedV(13.0D);
|
||||
final double var32 = IIcon.getInterpolatedU(9.0D);
|
||||
final double var34 = IIcon.getInterpolatedV(15.0D);
|
||||
|
||||
final double var22b = IIcon.getInterpolatedV(9.0D);
|
||||
final double var26b = IIcon.getInterpolatedV(11.0D);
|
||||
|
||||
baseX += 0.5D;
|
||||
baseZ += 0.5D;
|
||||
final double var36 = baseX - 0.5D;
|
||||
final double var38 = baseX + 0.5D;
|
||||
final double var40 = baseZ - 0.5D;
|
||||
final double var42 = baseZ + 0.5D;
|
||||
|
||||
double toff = 0.0d;
|
||||
|
||||
if (!isOn) {
|
||||
toff = 1.0d / 16.0d;
|
||||
}
|
||||
|
||||
final Tessellator var12 = Tessellator.instance;
|
||||
if (isOn) {
|
||||
var12.setColorOpaque_F(1.0F, 1.0F, 1.0F);
|
||||
var12.setBrightness(11 << 20 | 11 << 4);
|
||||
}
|
||||
|
||||
final double TorchLen = 0.625D;
|
||||
final double var44 = 0.0625D;
|
||||
final double Zero = 0;
|
||||
final double par10 = 0;
|
||||
|
||||
final double x = baseX + Zero * (1.0D - TorchLen) - var44;
|
||||
final double x1 = baseX + Zero * (1.0D - TorchLen) + var44;
|
||||
|
||||
final double y = baseY + TorchLen - toff;
|
||||
final double var422 = 0.1915D + 1.0 / 16.0;
|
||||
final double y1 = baseY + var422;
|
||||
|
||||
final double z = baseZ + par10 * (1.0D - TorchLen) - var44;
|
||||
final double z1 = baseZ + par10 * (1.0D - TorchLen) + var44;
|
||||
|
||||
this.addVertexWithUV(x, y, z, var20, var22);
|
||||
this.addVertexWithUV(x, y, z1, var20, var26);
|
||||
this.addVertexWithUV(x1, y, z1, var24, var26);
|
||||
this.addVertexWithUV(x1, y, z, var24, var22);
|
||||
|
||||
this.addVertexWithUV(x1, y1, z, var24b, var22b);
|
||||
this.addVertexWithUV(x1, y1, z1, var24b, var26b);
|
||||
this.addVertexWithUV(x, y1, z1, var20b, var26b);
|
||||
this.addVertexWithUV(x, y1, z, var20b, var22b);
|
||||
|
||||
this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ - var44 + par10, var32, var30);
|
||||
this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ + var44 + par10, var32, var34);
|
||||
this.addVertexWithUV(baseX - var44 + Zero, baseY, baseZ + var44 + par10, var28, var34);
|
||||
this.addVertexWithUV(baseX - var44 + Zero, baseY, baseZ - var44 + par10, var28, var30);
|
||||
|
||||
this.addVertexWithUV(baseX - var44, baseY + 1.0D, var40, var16, var18);
|
||||
this.addVertexWithUV(baseX - var44 + Zero, baseY + 0.0D, var40 + par10, var16, var19);
|
||||
this.addVertexWithUV(baseX - var44 + Zero, baseY + 0.0D, var42 + par10, var17, var19);
|
||||
this.addVertexWithUV(baseX - var44, baseY + 1.0D, var42, var17, var18);
|
||||
|
||||
this.addVertexWithUV(baseX + var44, baseY + 1.0D, var42, var16, var18);
|
||||
this.addVertexWithUV(baseX + Zero + var44, baseY + 0.0D, var42 + par10, var16, var19);
|
||||
this.addVertexWithUV(baseX + Zero + var44, baseY + 0.0D, var40 + par10, var17, var19);
|
||||
this.addVertexWithUV(baseX + var44, baseY + 1.0D, var40, var17, var18);
|
||||
|
||||
this.addVertexWithUV(var36, baseY + 1.0D, baseZ + var44, var16, var18);
|
||||
this.addVertexWithUV(var36 + Zero, baseY + 0.0D, baseZ + var44 + par10, var16, var19);
|
||||
this.addVertexWithUV(var38 + Zero, baseY + 0.0D, baseZ + var44 + par10, var17, var19);
|
||||
this.addVertexWithUV(var38, baseY + 1.0D, baseZ + var44, var17, var18);
|
||||
|
||||
this.addVertexWithUV(var38, baseY + 1.0D, baseZ - var44, var16, var18);
|
||||
this.addVertexWithUV(var38 + Zero, baseY + 0.0D, baseZ - var44 + par10, var16, var19);
|
||||
this.addVertexWithUV(var36 + Zero, baseY + 0.0D, baseZ - var44 + par10, var17, var19);
|
||||
this.addVertexWithUV(var36, baseY + 1.0D, baseZ - var44, var17, var18);
|
||||
}
|
||||
|
||||
private void addVertexWithUV(double x, double y, double z, final double u, final double v) {
|
||||
final Tessellator var12 = Tessellator.instance;
|
||||
|
||||
x -= this.centerX;
|
||||
y -= this.centerY;
|
||||
z -= this.centerZ;
|
||||
|
||||
if (this.getSide() == ForgeDirection.DOWN) {
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
if (this.getSide() == ForgeDirection.EAST) {
|
||||
final double m = x;
|
||||
x = y;
|
||||
y = m;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
if (this.getSide() == ForgeDirection.WEST) {
|
||||
final double m = x;
|
||||
x = -y;
|
||||
y = m;
|
||||
}
|
||||
|
||||
if (this.getSide() == ForgeDirection.SOUTH) {
|
||||
final double m = z;
|
||||
z = y;
|
||||
y = m;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
if (this.getSide() == ForgeDirection.NORTH) {
|
||||
final double m = z;
|
||||
z = -y;
|
||||
y = m;
|
||||
}
|
||||
|
||||
x += this.centerX; // + orientation.offsetX * 0.4;
|
||||
y += this.centerY; // + orientation.offsetY * 0.4;
|
||||
z += this.centerZ; // + orientation.offsetZ * 0.4;
|
||||
|
||||
var12.addVertexWithUV(x, y, z, u, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
rh.setTexture(this.getItemStack().getIconIndex());
|
||||
|
||||
renderer.renderAllFaces = true;
|
||||
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
tess.setBrightness(rh.getBlock().getMixedBrightnessForBlock(this.getHost().getTile().getWorldObj(), x, y, z));
|
||||
tess.setColorOpaque_F(1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.renderTorchAtAngle(x, y, z);
|
||||
|
||||
renderer.renderAllFaces = false;
|
||||
|
||||
rh.setBounds(7, 7, 11, 9, 9, 12);
|
||||
this.renderLights(x, y, z, rh, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(final World world, final int x, final int y, final int z, final Random r) {
|
||||
if (this.isLevelEmitterOn()) {
|
||||
final ForgeDirection d = this.getSide();
|
||||
|
||||
final double d0 = d.offsetX * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d1 = d.offsetY * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d2 = d.offsetZ * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
|
||||
world.spawnParticle("reddust", 0.5 + x + d0, 0.5 + y + d1, 0.5 + z + d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
|
||||
if (!player.isSneaking()) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(getSide()),
|
||||
GuiType.FLUID_LEVEL_EMITTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName,
|
||||
@SuppressWarnings("rawtypes") final Enum newValue) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.config) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.lastReportedValue = data.getLong("lastReportedValue");
|
||||
this.reportingValue = data.getLong("reportingValue");
|
||||
this.prevState = data.getBoolean("prevState");
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setLong("lastReportedValue", this.lastReportedValue);
|
||||
data.setLong("reportingValue", this.reportingValue);
|
||||
data.setBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
public void setFluidInSlot(int id, IAEFluidStack fluid) {
|
||||
ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack());
|
||||
this.config.setInventorySlotContents(id, tmp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelItemInfo[] getLevelItemInfoList() {
|
||||
ItemStack stack = this.config.getStackInSlot(0);
|
||||
if (stack == null) return new LevelItemInfo[] { null };
|
||||
return new LevelItemInfo[] { new LevelItemInfo(
|
||||
stack,
|
||||
this.getReportingValue(),
|
||||
-1,
|
||||
this.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) };
|
||||
}
|
||||
}
|
||||
@@ -1,279 +1,53 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import static appeng.helpers.DualityInterface.NUMBER_OF_STORAGE_SLOTS;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import com.glodblock.github.client.FluidInterfaceButtons;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.AEFluidInventory;
|
||||
import com.glodblock.github.inventory.IAEFluidTank;
|
||||
import com.glodblock.github.inventory.IDualHost;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.DualityFluidInterface;
|
||||
import com.glodblock.github.util.Util;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
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;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.helpers.ICustomButtonDataObject;
|
||||
import appeng.helpers.ICustomButtonProvider;
|
||||
import appeng.parts.p2p.PartP2PInterface;
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
import appeng.parts.p2p.PartP2PTunnelStatic;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorIInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.WrapperInvSlot;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInterface>
|
||||
implements IGridTickable, IStorageMonitorable, IInventoryDestination, IDualHost, ISidedInventory,
|
||||
IAEAppEngInventory, ITileStorageMonitorable, IPriorityHost, IInterfaceHost {
|
||||
public class PartFluidP2PInterface extends PartP2PInterface implements IDualHost, ICustomButtonProvider {
|
||||
|
||||
boolean needUpdateOnNetworkBooted = false;
|
||||
boolean lastPowerStart = false;
|
||||
|
||||
public PartFluidP2PInterface(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
private final DualityInterface duality = new DualityInterface(this.getProxy(), this) {
|
||||
|
||||
@Override
|
||||
public void updateCraftingList() {
|
||||
if (!isOutput()) {
|
||||
CraftingGridCache.pauseRebuilds();
|
||||
|
||||
super.updateCraftingList();
|
||||
|
||||
try {
|
||||
for (PartFluidP2PInterface p2p : getOutputs()) {
|
||||
p2p.duality.updateCraftingList();
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
// ?
|
||||
}
|
||||
|
||||
CraftingGridCache.unpauseRebuilds();
|
||||
} else {
|
||||
PartFluidP2PInterface p2p = getInput();
|
||||
if (p2p != null) {
|
||||
this.craftingList = p2p.duality.craftingList;
|
||||
try {
|
||||
this.gridProxy.getGrid()
|
||||
.postEvent(new MENetworkCraftingPatternChange(this, this.gridProxy.getNode()));
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
final boolean powerState = proxy.isActive();
|
||||
if (needUpdateOnNetworkBooted || lastPowerStart != powerState) {
|
||||
needUpdateOnNetworkBooted = false;
|
||||
lastPowerStart = powerState;
|
||||
updateSharingInventory();
|
||||
}
|
||||
return super.tickingRequest(node, ticksSinceLastCall);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasWorkToDo() {
|
||||
if (isOutput()) {
|
||||
return hasItemsToSend() || hasConfig() || !getStorage().isEmpty();
|
||||
} else return super.hasWorkToDo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readConfig() {
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface p2p = getInput();
|
||||
boolean alertDevice = false;
|
||||
|
||||
if (p2p != null) {
|
||||
this.setHasConfig(p2p.duality.hasConfig());
|
||||
|
||||
alertDevice = hasWorkToDo();
|
||||
|
||||
} else {
|
||||
this.setHasConfig(false);
|
||||
}
|
||||
|
||||
if (alertDevice) {
|
||||
try {
|
||||
this.gridProxy.getTick().alertDevice(this.gridProxy.getNode());
|
||||
} catch (final GridAccessException ignored) {}
|
||||
} else {
|
||||
try {
|
||||
this.gridProxy.getTick().sleepDevice(this.gridProxy.getNode());
|
||||
} catch (final GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
this.notifyNeighbors();
|
||||
} else {
|
||||
super.readConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDrops(final List<ItemStack> drops) {
|
||||
if (!isOutput()) {
|
||||
super.addDrops(drops);
|
||||
try {
|
||||
for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.addDrops(drops);
|
||||
} catch (GridAccessException ignored) {}
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : this.getUpgrades()) {
|
||||
if (is != null) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : this.getPatterns()) {
|
||||
if (is != null) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u) {
|
||||
if (isOutput() && u == Upgrades.PATTERN_CAPACITY) return -1;
|
||||
return super.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigSize() {
|
||||
if (isOutput()) return -1;
|
||||
return super.getConfigSize();
|
||||
}
|
||||
};
|
||||
private final DualityFluidInterface dualityFluid = new DualityFluidInterface(this.getProxy(), this);
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 6);
|
||||
|
||||
private void updateSharingInventory() {
|
||||
duality.readConfig();
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface p2p = getInput();
|
||||
if (proxy.isActive() && p2p != null) {
|
||||
if (!duality.sharedInventory && !duality.getStorage().isEmpty()) {
|
||||
ArrayList<ItemStack> drops = new ArrayList<>();
|
||||
AppEngInternalInventory storageAppEng = this.duality.getStorage();
|
||||
AdaptorIInventory p2pInv = new AdaptorIInventory(p2p.duality.getStorage());
|
||||
for (ItemStack itemStack : storageAppEng) {
|
||||
if (itemStack == null) continue;
|
||||
ItemStack drop = p2pInv.addItems(itemStack);
|
||||
if (drop != null && drop.stackSize > 0) {
|
||||
drops.add(drop);
|
||||
}
|
||||
}
|
||||
TileEntity te = getTileEntity();
|
||||
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
|
||||
}
|
||||
duality.setStorage(p2p.duality.getStorage());
|
||||
duality.setSlotInv(p2p.duality.getSlotInv());
|
||||
duality.sharedInventory = true;
|
||||
} else {
|
||||
if (duality.sharedInventory) {
|
||||
duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS));
|
||||
duality.setSlotInv(new WrapperInvSlot(duality.getStorage()));
|
||||
duality.sharedInventory = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (duality.sharedInventory) {
|
||||
duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS));
|
||||
duality.setSlotInv(new WrapperInvSlot(duality.getStorage()));
|
||||
duality.sharedInventory = false;
|
||||
}
|
||||
try {
|
||||
for (PartFluidP2PInterface p2p : getOutputs()) {
|
||||
p2p.duality.readConfig();
|
||||
}
|
||||
} catch (GridAccessException ignored) {}
|
||||
}
|
||||
}
|
||||
private ICustomButtonDataObject customButtonDataObject;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
updateSharingInventory();
|
||||
needUpdateOnNetworkBooted = true;
|
||||
}
|
||||
public PartFluidP2PInterface(ItemStack is) {
|
||||
super(is);
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange c) {
|
||||
this.duality.notifyNeighbors();
|
||||
updateSharingInventory();
|
||||
needUpdateOnNetworkBooted = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
return this.duality.getInstalledUpgrades(u);
|
||||
this.customButtonDataObject = new FluidInterfaceButtons(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,31 +56,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
return ItemAndBlockHolder.INTERFACE.getBlockTextureFromSide(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged() {
|
||||
super.gridChanged();
|
||||
dualityFluid.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.duality.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getMemoryCardData() {
|
||||
final NBTTagCompound output = super.getMemoryCardData();
|
||||
this.duality.getConfigManager().writeToNBT(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartP2PTunnel<?> applyMemoryCard(EntityPlayer player, IMemoryCard memoryCard, ItemStack is) {
|
||||
PartP2PTunnel<?> newTunnel = super.applyMemoryCard(player, memoryCard, is);
|
||||
@@ -318,112 +67,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
return newTunnel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.duality.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
this.duality.addDrops(drops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(final String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged() {
|
||||
this.duality.updateRedstoneState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer p, final Vec3 pos) {
|
||||
if (super.onPartActivate(p, pos)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (p.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Platform.isServer()) {
|
||||
InventoryHandler.openGui(
|
||||
p,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(this.getSide()),
|
||||
GuiType.DUAL_INTERFACE);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void dropPatterns(final PartFluidP2PInterface p2p) {
|
||||
final AppEngInternalInventory patterns = p2p.duality.getPatterns();
|
||||
final List<ItemStack> drops = new ArrayList<>();
|
||||
for (int i = 0; i < patterns.getSizeInventory(); i++) {
|
||||
if (patterns.getStackInSlot(i) == null) continue;
|
||||
drops.add(patterns.getStackInSlot(i));
|
||||
}
|
||||
if (!drops.isEmpty()) {
|
||||
final TileEntity te = p2p.getTileEntity();
|
||||
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void copyContents(final PartP2PTunnel<?> from) {
|
||||
if (from instanceof PartFluidP2PInterface fromInterface) {
|
||||
DualityInterface newDuality = this.duality;
|
||||
// Copy interface storage, upgrades, and settings over
|
||||
UpgradeInventory upgrades = (UpgradeInventory) fromInterface.duality.getInventoryByName("upgrades");
|
||||
UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades");
|
||||
for (int i = 0; i < upgrades.getSizeInventory(); ++i) {
|
||||
newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i));
|
||||
}
|
||||
|
||||
if (!fromInterface.duality.sharedInventory) {
|
||||
IInventory storage = fromInterface.duality.getStorage();
|
||||
IInventory newStorage = newDuality.getStorage();
|
||||
for (int i = 0; i < storage.getSizeInventory(); ++i) {
|
||||
newStorage.setInventorySlotContents(i, storage.getStackInSlot(i));
|
||||
}
|
||||
|
||||
IInventory config = fromInterface.duality.getInventoryByName("config");
|
||||
IInventory newConfig = newDuality.getInventoryByName("config");
|
||||
for (int i = 0; i < config.getSizeInventory(); ++i) {
|
||||
newConfig.setInventorySlotContents(i, config.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
||||
AppEngInternalInventory patterns = fromInterface.duality.getPatterns();
|
||||
boolean drop = true;
|
||||
if (!from.isOutput() && !this.isOutput()) { // input to input
|
||||
for (int i = 0; i < patterns.getSizeInventory(); i++) {
|
||||
newDuality.getPatterns().setInventorySlotContents(i, patterns.getStackInSlot(i));
|
||||
}
|
||||
drop = false;
|
||||
}
|
||||
|
||||
if (drop) {
|
||||
this.dropPatterns(fromInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void copySettings(final PartP2PTunnel<?> from) {
|
||||
if (from instanceof PartFluidP2PInterface fromInterface) {
|
||||
@@ -435,26 +78,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture() {
|
||||
return this.getItemStack().getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
return this.duality.canInsert(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory() {
|
||||
return this.duality.getItemInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory() {
|
||||
return this.duality.getFluidInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
TickingRequest item = duality.getTickingRequest(node);
|
||||
@@ -477,216 +100,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return this.duality.getStorage().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int i) {
|
||||
return this.duality.getStorage().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(final int i, final int j) {
|
||||
return this.duality.getStorage().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(final int i) {
|
||||
return this.duality.getStorage().getStackInSlotOnClosing(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(final int i, final ItemStack itemstack) {
|
||||
this.duality.getStorage().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return this.duality.getStorage().getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return this.duality.getStorage().hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return this.duality.getStorage().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
this.duality.getStorage().markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
|
||||
return this.duality.getStorage().isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
this.duality.getStorage().openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
this.duality.getStorage().closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(final int i, final ItemStack itemstack) {
|
||||
return this.duality.getStorage().isItemValidForSlot(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(final int s) {
|
||||
return this.duality.getAccessibleSlotsFromSide(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(final int i, final ItemStack itemstack, final int j) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(final int i, final ItemStack itemstack, final int j) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.duality.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getTargets() {
|
||||
return EnumSet.of(this.getSide());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageMonitorable getMonitorable(final ForgeDirection side, final BaseActionSource src) {
|
||||
return this.duality.getMonitorable(side, src, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
|
||||
return this.duality.pushPattern(patternDetails, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return this.duality.isBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
||||
this.duality.provideCrafting(craftingTracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.duality.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
|
||||
return this.duality.injectCraftedItems(link, items, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
this.duality.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.duality.updateCraftingList();
|
||||
updateSharingInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange() {
|
||||
updateSharingInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getPatterns() {
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface input = getInput();
|
||||
if (input != null) {
|
||||
return input.getPatterns();
|
||||
}
|
||||
return IInterfaceHost.super.getPatterns();
|
||||
}
|
||||
return IInterfaceHost.super.getPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rows() {
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface input = getInput();
|
||||
if (input != null) {
|
||||
return input.rows();
|
||||
}
|
||||
return IInterfaceHost.super.rows();
|
||||
}
|
||||
return IInterfaceHost.super.rows();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rowSize() {
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface input = getInput();
|
||||
if (input != null) {
|
||||
return input.rowSize();
|
||||
}
|
||||
return IInterfaceHost.super.rowSize();
|
||||
}
|
||||
return IInterfaceHost.super.rowSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isOutput()) {
|
||||
PartFluidP2PInterface input = getInput();
|
||||
if (input != null) {
|
||||
return input.getName();
|
||||
}
|
||||
return IInterfaceHost.super.getName();
|
||||
}
|
||||
return IInterfaceHost.super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSelfRep() {
|
||||
return this.getItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return dualityFluid.fill(from, resource, doFill);
|
||||
@@ -758,8 +171,36 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDisplay() {
|
||||
return IInterfaceHost.super.shouldDisplay();
|
||||
public ItemStack getPrimaryGuiIcon() {
|
||||
return ItemAndBlockHolder.FLUID_INTERFACE.stack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomButtonData() {}
|
||||
|
||||
@Override
|
||||
public void readCustomButtonData() {}
|
||||
|
||||
@Override
|
||||
public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset,
|
||||
List<GuiButton> buttonList) {
|
||||
if (customButtonDataObject != null)
|
||||
customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean actionPerformedCustomButtons(final GuiButton btn) {
|
||||
return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomButtonDataObject getDataObject() {
|
||||
return customButtonDataObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataObject(ICustomButtonDataObject dataObject) {
|
||||
customButtonDataObject = dataObject;
|
||||
}
|
||||
}
|
||||
@@ -1,161 +1,13 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
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.FCFluidEncodeTerminal;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.BiggerAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class PartFluidPatternTerminal extends FCFluidEncodeTerminal {
|
||||
|
||||
private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidPatternTerminal_Bright;
|
||||
private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidPatternTerminal_Colored;
|
||||
private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidPatternTerminal_Dark;
|
||||
public class PartFluidPatternTerminal extends PartPatternTerminal {
|
||||
|
||||
public PartFluidPatternTerminal(ItemStack is) {
|
||||
super(is);
|
||||
this.crafting = new BiggerAppEngInventory(this, 9);
|
||||
this.output = new BiggerAppEngInventory(this, 3);
|
||||
this.prioritize = false;
|
||||
this.inverted = false;
|
||||
this.activePage = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiType getGui() {
|
||||
return GuiType.FLUID_PATTERN_TERMINAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.pattern && slot == 1) {
|
||||
final ItemStack is = inv.getStackInSlot(1);
|
||||
if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) {
|
||||
final ICraftingPatternDetails details = craftingPatternItem
|
||||
.getPatternForItem(is, this.getHost().getTile().getWorldObj());
|
||||
if (details != null) {
|
||||
final IAEItemStack[] inItems = details.getInputs();
|
||||
final IAEItemStack[] outItems = details.getOutputs();
|
||||
|
||||
this.setCraftingRecipe(details.isCraftable());
|
||||
this.setSubstitution(details.canSubstitute());
|
||||
if (newStack != null) {
|
||||
NBTTagCompound data = newStack.getTagCompound();
|
||||
this.setCombineMode(data.getInteger("combine") == 1);
|
||||
this.setBeSubstitute(details.canBeSubstitute());
|
||||
}
|
||||
for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
|
||||
this.crafting.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.output.getSizeInventory(); i++) {
|
||||
this.output.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) {
|
||||
if (inItems[i] != null) {
|
||||
final IAEItemStack item = inItems[i];
|
||||
if (item != null && item.getItem() instanceof ItemFluidDrop) {
|
||||
ItemStack packet = ItemFluidPacket
|
||||
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
|
||||
this.crafting.setInventorySlotContents(i, packet);
|
||||
} else this.crafting.setInventorySlotContents(i, item == null ? null : item.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) {
|
||||
if (outItems[i] != null) {
|
||||
final IAEItemStack item = outItems[i];
|
||||
if (item != null && item.getItem() instanceof ItemFluidDrop) {
|
||||
ItemStack packet = ItemFluidPacket
|
||||
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
|
||||
this.output.setInventorySlotContents(i, packet);
|
||||
} else this.output.setInventorySlotContents(i, item == null ? null : item.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inv == this.crafting) {
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
private void fixCraftingRecipes() {
|
||||
if (this.craftingMode) {
|
||||
for (int x = 0; x < this.crafting.getSizeInventory(); x++) {
|
||||
final ItemStack is = this.crafting.getStackInSlot(x);
|
||||
if (is != null) {
|
||||
is.stackSize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCraftingRecipe(final boolean craftingMode) {
|
||||
super.setCraftingRecipe(craftingMode);
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrioritization(boolean canPrioritize) {
|
||||
this.prioritize = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritize() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInverted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverted(boolean inverted) {
|
||||
this.inverted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivePage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivePage(int activePage) {
|
||||
this.activePage = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontBright() {
|
||||
return FRONT_BRIGHT_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontColored() {
|
||||
return FRONT_COLORED_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontDark() {
|
||||
return FRONT_DARK_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLightSource() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,149 +1,12 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
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.FCFluidEncodeTerminal;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import appeng.parts.reporting.PartPatternTerminalEx;
|
||||
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.BiggerAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class PartFluidPatternTerminalEx extends FCFluidEncodeTerminal {
|
||||
|
||||
private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidPatternTerminal_Bright;
|
||||
private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidPatternTerminal_Colored;
|
||||
private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidPatternTerminal_Dark;
|
||||
public class PartFluidPatternTerminalEx extends PartPatternTerminalEx {
|
||||
|
||||
public PartFluidPatternTerminalEx(ItemStack is) {
|
||||
super(is);
|
||||
this.crafting = new BiggerAppEngInventory(this, 32);
|
||||
this.output = new BiggerAppEngInventory(this, 32);
|
||||
this.craftingMode = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiType getGui() {
|
||||
return GuiType.FLUID_PATTERN_TERMINAL_EX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.pattern && slot == 1) {
|
||||
final ItemStack is = inv.getStackInSlot(1);
|
||||
|
||||
if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) {
|
||||
final ICraftingPatternDetails details = craftingPatternItem
|
||||
.getPatternForItem(is, this.getHost().getTile().getWorldObj());
|
||||
|
||||
if (details != null) {
|
||||
final IAEItemStack[] inItems = details.getInputs();
|
||||
final IAEItemStack[] outItems = details.getOutputs();
|
||||
int inputsCount = 0;
|
||||
int outputCount = 0;
|
||||
for (IAEItemStack inItem : inItems) {
|
||||
if (inItem != null) {
|
||||
inputsCount++;
|
||||
}
|
||||
}
|
||||
for (IAEItemStack outItem : outItems) {
|
||||
if (outItem != null) {
|
||||
outputCount++;
|
||||
}
|
||||
}
|
||||
|
||||
this.setSubstitution(details.canSubstitute());
|
||||
if (newStack != null) {
|
||||
NBTTagCompound data = newStack.getTagCompound();
|
||||
this.setCombineMode(data.getInteger("combine") == 1);
|
||||
this.setBeSubstitute(details.canBeSubstitute());
|
||||
}
|
||||
this.setInverted(inputsCount <= 8 && outputCount > 8);
|
||||
this.setActivePage(0);
|
||||
|
||||
for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
|
||||
this.crafting.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.output.getSizeInventory(); i++) {
|
||||
this.output.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) {
|
||||
final IAEItemStack item = inItems[i];
|
||||
if (item != null) {
|
||||
if (item.getItem() instanceof ItemFluidDrop) {
|
||||
ItemStack packet = ItemFluidPacket
|
||||
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
|
||||
this.crafting.setInventorySlotContents(i, packet);
|
||||
} else this.crafting.setInventorySlotContents(i, item.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
if (inverted) {
|
||||
for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) {
|
||||
final IAEItemStack item = outItems[i];
|
||||
if (item != null) {
|
||||
if (item.getItem() instanceof ItemFluidDrop) {
|
||||
ItemStack packet = ItemFluidPacket
|
||||
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
|
||||
this.output.setInventorySlotContents(i, packet);
|
||||
} else this.output.setInventorySlotContents(i, item.getItemStack());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < outItems.length && i < 8; i++) {
|
||||
final IAEItemStack item = outItems[i];
|
||||
if (item != null) {
|
||||
if (item.getItem() instanceof ItemFluidDrop) {
|
||||
ItemStack packet = ItemFluidPacket
|
||||
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
|
||||
this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, packet);
|
||||
} else this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, item.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCraftingRecipe(final boolean craftingMode) {
|
||||
this.craftingMode = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftingRecipe() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontBright() {
|
||||
return FRONT_BRIGHT_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontColored() {
|
||||
return FRONT_COLORED_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCPartsTexture getFrontDark() {
|
||||
return FRONT_DARK_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLightSource() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,529 +1,18 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.MEMonitorIFluidHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
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.IBaseMonitor;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.ITickManager;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.IExternalStorageHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.GridStorageCache;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.me.storage.StorageBusInventoryHandler;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.IterationCounter;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.prioitylist.PrecisePriorityList;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
|
||||
public class PartFluidStorageBus extends PartUpgradeable
|
||||
implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEFluidStack>, IPriorityHost {
|
||||
|
||||
private final BaseActionSource source;
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 63);
|
||||
private int priority = 0;
|
||||
private boolean cached = false;
|
||||
private MEMonitorIFluidHandler monitor = null;
|
||||
private MEInventoryHandler<IAEFluidStack> handler = null;
|
||||
private int handlerHash = 0;
|
||||
private boolean wasActive = false;
|
||||
private byte resetCacheLogic = 0;
|
||||
/**
|
||||
* used to read changes once when the list of extractable items was changed
|
||||
*/
|
||||
private boolean readOncePass = false;
|
||||
public class PartFluidStorageBus extends PartStorageBus {
|
||||
|
||||
public PartFluidStorageBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
|
||||
this.getConfigManager().registerSetting(Settings.STICKY_MODE, YesNo.NO);
|
||||
this.source = new MachineSource(this);
|
||||
if (is.getTagCompound() != null) {
|
||||
NBTTagCompound tag = is.getTagCompound();
|
||||
if (tag.hasKey("priority")) {
|
||||
priority = tag.getInteger("priority");
|
||||
// if we don't do this, the tag will stick forever to the storage bus, as it's never cleaned up,
|
||||
// even when the item is broken with a pickaxe
|
||||
this.is.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(final PartItemStack type) {
|
||||
if (type == PartItemStack.Wrench) {
|
||||
final NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("priority", priority);
|
||||
final ItemStack copy = this.is.copy();
|
||||
copy.setTagCompound(tag);
|
||||
return copy;
|
||||
}
|
||||
return super.getItemStack(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged changedChannels) {
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
protected void updateStatus() {
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if (this.wasActive != currentActive) {
|
||||
this.wasActive = currentActive;
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
this.getHost().markForUpdate();
|
||||
} catch (final GridAccessException e) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUpgradeSlots() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName,
|
||||
@SuppressWarnings("rawtypes") final Enum newValue) {
|
||||
this.resetCache(true);
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
super.upgradesChanged();
|
||||
this.resetCache(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.config.readFromNBT(data, "config");
|
||||
this.priority = data.getInteger("priority");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.config.writeToNBT(data, "config");
|
||||
data.setInteger("priority", this.priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.config;
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
|
||||
if (inv == this.config) {
|
||||
this.resetCache(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetCache(final boolean fullReset) {
|
||||
if (this.getHost() == null || this.getHost().getTile() == null
|
||||
|| this.getHost().getTile().getWorldObj() == null
|
||||
|| this.getHost().getTile().getWorldObj().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fullReset) {
|
||||
this.resetCacheLogic = 2;
|
||||
} else if (this.resetCacheLogic < 2) {
|
||||
this.resetCacheLogic = 1;
|
||||
}
|
||||
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException ignore) {}
|
||||
}
|
||||
|
||||
protected void resetCache() {
|
||||
final boolean fullReset = this.resetCacheLogic == 2;
|
||||
this.resetCacheLogic = 0;
|
||||
|
||||
final MEInventoryHandler<IAEFluidStack> in = this.getInternalHandler();
|
||||
IItemList<IAEFluidStack> before = AEApi.instance().storage().createFluidList();
|
||||
if (in != null) {
|
||||
before = in.getAvailableItems(before, IterationCounter.fetchNewId());
|
||||
}
|
||||
|
||||
this.cached = false;
|
||||
if (fullReset) {
|
||||
this.handlerHash = 0;
|
||||
}
|
||||
|
||||
final MEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
|
||||
if (this.monitor != null) {
|
||||
this.monitor.onTick();
|
||||
}
|
||||
|
||||
IItemList<IAEFluidStack> after = AEApi.instance().storage().createFluidList();
|
||||
|
||||
if (in != out) {
|
||||
if (out != null) {
|
||||
after = out.getAvailableItems(after, IterationCounter.fetchNewId());
|
||||
}
|
||||
Platform.postListChanges(before, after, this, this.source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final Object verificationToken) {
|
||||
return this.handler == verificationToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
|
||||
final BaseActionSource source) {
|
||||
try {
|
||||
if (this.getProxy().isActive()) {
|
||||
if (!this.readOncePass) {
|
||||
AccessRestriction currentAccess = (AccessRestriction) this.getConfigManager()
|
||||
.getSetting(Settings.ACCESS);
|
||||
if (!currentAccess.hasPermission(AccessRestriction.READ)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Iterable<IAEFluidStack> filteredChanges = this.filterChanges(change, this.readOncePass);
|
||||
this.readOncePass = false;
|
||||
if (filteredChanges == null) return;
|
||||
this.getProxy().getStorage()
|
||||
.postAlterationOfStoredItems(StorageChannel.FLUIDS, filteredChanges, this.source);
|
||||
}
|
||||
} catch (final GridAccessException ignore) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the changes to only include fluids that pass the handlers extract filter. Will return null if none of the
|
||||
* changes match the filter.
|
||||
*/
|
||||
@Nullable
|
||||
private Iterable<IAEFluidStack> filterChanges(final Iterable<IAEFluidStack> change, final boolean readOncePass) {
|
||||
if (readOncePass) {
|
||||
return change;
|
||||
}
|
||||
|
||||
if (this.handler != null && this.handler.isExtractFilterActive()
|
||||
&& !this.handler.getExtractPartitionList().isEmpty()) {
|
||||
List<IAEFluidStack> filteredChanges = new ArrayList<>();
|
||||
Predicate<IAEFluidStack> extractFilterCondition = this.handler.getExtractFilterCondition();
|
||||
for (final IAEFluidStack changedFluid : change) {
|
||||
if (extractFilterCondition.test(changedFluid)) {
|
||||
filteredChanges.add(changedFluid);
|
||||
}
|
||||
}
|
||||
return filteredChanges.isEmpty() ? null : Collections.unmodifiableList(filteredChanges);
|
||||
}
|
||||
return change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(3, 3, 15, 13, 13, 16);
|
||||
bch.addBox(2, 2, 14, 14, 14, 15);
|
||||
bch.addBox(5, 5, 12, 11, 11, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged() {
|
||||
this.resetCache(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(this.getSide()),
|
||||
GuiType.FLUID_STORAGE_BUS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(TickRates.StorageBus.getMin(), TickRates.StorageBus.getMax(), monitor == null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
if (this.resetCacheLogic != 0) {
|
||||
this.resetCache();
|
||||
}
|
||||
if (this.monitor != null) {
|
||||
return this.monitor.onTick();
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public MEInventoryHandler<IAEFluidStack> getInternalHandler() {
|
||||
if (this.cached) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
final boolean wasSleeping = this.monitor == null;
|
||||
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = new BlockPos(self).getOffSet(this.getSide()).getTileEntity();
|
||||
final int newHandlerHash = Platform.generateTileHash(target);
|
||||
if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) {
|
||||
return this.handler;
|
||||
}
|
||||
this.handlerHash = newHandlerHash;
|
||||
this.handler = null;
|
||||
this.monitor = null;
|
||||
this.readOncePass = true;
|
||||
if (target != null) {
|
||||
final IExternalStorageHandler esh = AEApi.instance().registries().externalStorage()
|
||||
.getHandler(target, this.getSide().getOpposite(), StorageChannel.FLUIDS, this.source);
|
||||
if (esh != null) {
|
||||
final IMEInventory<?> inv = esh
|
||||
.getInventory(target, this.getSide().getOpposite(), StorageChannel.FLUIDS, this.source);
|
||||
if (inv instanceof final MEMonitorIFluidHandler h) {
|
||||
h.setMode((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||
h.setActionSource(new MachineSource(this));
|
||||
this.monitor = h;
|
||||
}
|
||||
if (inv != null) {
|
||||
this.handler = new StorageBusInventoryHandler(inv, StorageChannel.FLUIDS);
|
||||
AccessRestriction currentAccess = (AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS);
|
||||
this.handler.setBaseAccess(currentAccess);
|
||||
this.handler.setWhitelist(
|
||||
this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST
|
||||
: IncludeExclude.WHITELIST);
|
||||
this.handler.setSticky(this.getInstalledUpgrades(Upgrades.STICKY) > 0);
|
||||
this.handler.setPriority(this.priority);
|
||||
// only READ since READ_WRITE would break compat of existing storage buses
|
||||
// could use a new setting that is applied via button or a card too
|
||||
this.handler.setIsExtractFilterActive(currentAccess == AccessRestriction.READ);
|
||||
|
||||
if (inv instanceof IMEMonitor) {
|
||||
((IBaseMonitor) inv).addListener(this, this.handler);
|
||||
}
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().createFluidList();
|
||||
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
|
||||
for (int x = 0; x < this.config.getSizeInventory() && x < slotsToUse; x++) {
|
||||
final IAEItemStack is = this.config.getAEStackInSlot(x);
|
||||
if (is != null) priorityList.add(AEFluidStack.create(ItemFluidPacket.getFluidStack(is)));
|
||||
}
|
||||
PrecisePriorityList partitionList = new PrecisePriorityList(priorityList);
|
||||
this.handler.setPartitionList(partitionList);
|
||||
this.handler.setExtractPartitionList(partitionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update sleep state...
|
||||
if (wasSleeping != (this.monitor == null)) {
|
||||
try {
|
||||
final ITickManager tm = this.getProxy().getTick();
|
||||
if (this.monitor == null) {
|
||||
tm.sleepDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
tm.wakeDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException ignore) {}
|
||||
}
|
||||
|
||||
try {
|
||||
// force grid to update handlers...
|
||||
((GridStorageCache) this.getProxy().getGrid().getCache(IStorageGrid.class)).cellUpdate(null);
|
||||
} catch (final GridAccessException ignore) {}
|
||||
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<IMEInventoryHandler> getCellArray(final StorageChannel channel) {
|
||||
if (channel == StorageChannel.FLUIDS) {
|
||||
final IMEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
|
||||
if (out != null) {
|
||||
return Collections.singletonList(out);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int newValue) {
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.resetCache(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges(@SuppressWarnings("rawtypes") final IMEInventory cellInventory) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public AppEngInternalAEInventory getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public void setFluidInSlot(int id, IAEFluidStack fluid) {
|
||||
ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack());
|
||||
this.config.setInventorySlotContents(id, tmp);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageBack.getIcon(),
|
||||
FCPartsTexture.PartFluidStorageBus.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon());
|
||||
|
||||
rh.setBounds(3, 3, 15, 13, 13, 16);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(2, 2, 14, 14, 14, 15);
|
||||
rh.renderInventoryBox(renderer);
|
||||
|
||||
rh.setBounds(5, 5, 12, 11, 11, 14);
|
||||
rh.renderInventoryBox(renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache()));
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageBack.getIcon(),
|
||||
FCPartsTexture.PartFluidStorageBus.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon());
|
||||
|
||||
rh.setBounds(3, 3, 15, 13, 13, 16);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setBounds(2, 2, 14, 14, 14, 15);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageBack.getIcon(),
|
||||
FCPartsTexture.PartFluidStorageBus.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon(),
|
||||
CableBusTextures.PartStorageSides.getIcon());
|
||||
|
||||
rh.setBounds(5, 5, 12, 11, 11, 13);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
rh.setTexture(
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(),
|
||||
FCPartsTexture.PartFluidStorageBus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon());
|
||||
|
||||
rh.setBounds(5, 5, 13, 11, 11, 14);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
this.renderLights(x, y, z, rh, renderer);
|
||||
public StorageChannel getStorageChannel() {
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.parts.base.FCPart;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
|
||||
import appeng.core.sync.GuiBridge;
|
||||
|
||||
public class PartFluidTerminal extends FCPart {
|
||||
|
||||
@@ -42,7 +43,7 @@ public class PartFluidTerminal extends FCPart {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiType getGui() {
|
||||
return GuiType.FLUID_TERMINAL;
|
||||
public GuiBridge getGui() {
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.parts.base.FCPart;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IClickableInTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.core.sync.GuiBridge;
|
||||
|
||||
public class PartLevelTerminal extends FCPart implements IClickableInTerminal {
|
||||
|
||||
private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartLevelTerminal_Bright;
|
||||
@@ -66,8 +73,8 @@ public class PartLevelTerminal extends FCPart implements IClickableInTerminal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiType getGui() {
|
||||
return GuiType.LEVEL_TERMINAL;
|
||||
public GuiBridge getGui() {
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,4 +87,14 @@ public class PartLevelTerminal extends FCPart implements IClickableInTerminal {
|
||||
public Util.DimensionalCoordSide getClickedInterface() {
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void openGui(EntityPlayer player) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(this.getSide()),
|
||||
GuiType.LEVEL_TERMINAL);
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
package com.glodblock.github.common.parts.base;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.item.IItemPatternTerminal;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.storage.ITerminalPins;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.items.contents.PinsHandler;
|
||||
import appeng.items.contents.PinsHolder;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
|
||||
public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatternTerminal, ITerminalPins {
|
||||
|
||||
protected AppEngInternalInventory crafting;
|
||||
protected AppEngInternalInventory output;
|
||||
protected final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
|
||||
private final PinsHolder pinsInv = new PinsHolder(this);
|
||||
|
||||
protected boolean craftingMode = true;
|
||||
protected boolean substitute = false;
|
||||
protected boolean combine = false;
|
||||
protected boolean prioritize = false;
|
||||
protected boolean inverted = false;
|
||||
protected boolean beSubstitute = false;
|
||||
protected boolean autoFillPattern = false;
|
||||
protected int activePage = 0;
|
||||
|
||||
public FCFluidEncodeTerminal(ItemStack is) {
|
||||
super(is, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
super.getDrops(drops, wrenched);
|
||||
for (final ItemStack is : this.pattern) {
|
||||
if (is != null) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.setCraftingRecipe(data.getBoolean("craftingMode"));
|
||||
this.setSubstitution(data.getBoolean("substitute"));
|
||||
this.setCombineMode(data.getBoolean("combine"));
|
||||
this.setBeSubstitute(data.getBoolean("beSubstitute"));
|
||||
this.setPrioritization(data.getBoolean("priorization"));
|
||||
this.setInverted(data.getBoolean("inverted"));
|
||||
this.setActivePage(data.getInteger("activePage"));
|
||||
this.setAutoFillPattern(data.getBoolean("autoFillPattern"));
|
||||
this.pattern.readFromNBT(data, "pattern");
|
||||
this.output.readFromNBT(data, "outputList");
|
||||
this.crafting.readFromNBT(data, "craftingGrid");
|
||||
pinsInv.readFromNBT(data, "pins");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setBoolean("craftingMode", this.craftingMode);
|
||||
data.setBoolean("combine", this.combine);
|
||||
data.setBoolean("beSubstitute", this.beSubstitute);
|
||||
data.setBoolean("priorization", this.prioritize);
|
||||
data.setBoolean("substitute", this.substitute);
|
||||
data.setBoolean("inverted", this.inverted);
|
||||
data.setInteger("activePage", this.activePage);
|
||||
data.setBoolean("autoFillPattern", this.autoFillPattern);
|
||||
this.pattern.writeToNBT(data, "pattern");
|
||||
this.output.writeToNBT(data, "outputList");
|
||||
this.crafting.writeToNBT(data, "craftingGrid");
|
||||
pinsInv.writeToNBT(data, "pins");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCombine() {
|
||||
return this.combine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCombineMode(boolean shouldCombine) {
|
||||
this.combine = shouldCombine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubstitution() {
|
||||
return this.substitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritize() {
|
||||
return this.prioritize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeSubstitute(boolean canBeSubstitute) {
|
||||
this.beSubstitute = canBeSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeSubstitute() {
|
||||
return this.beSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubstitution(boolean canSubstitute) {
|
||||
this.substitute = canSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrioritization(boolean canPrioritize) {
|
||||
this.prioritize = canPrioritize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInverted() {
|
||||
return inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverted(boolean inverted) {
|
||||
this.inverted = inverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivePage() {
|
||||
return this.activePage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivePage(int activePage) {
|
||||
this.activePage = activePage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCraftingRecipe(final boolean craftingMode) {
|
||||
this.craftingMode = craftingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftingRecipe() {
|
||||
return this.craftingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) {
|
||||
IInventory crafting = this.getInventoryByName("crafting");
|
||||
IInventory output = this.getInventoryByName("output");
|
||||
if (crafting instanceof AppEngInternalInventory && output instanceof AppEngInternalInventory) {
|
||||
for (int x = 0; x < crafting.getSizeInventory() && x < newCrafting.length; x++) {
|
||||
final IAEItemStack item = newCrafting[x];
|
||||
crafting.setInventorySlotContents(x, item == null ? null : item.getItemStack());
|
||||
}
|
||||
for (int x = 0; x < output.getSizeInventory() && x < newOutput.length; x++) {
|
||||
final IAEItemStack item = newOutput[x];
|
||||
output.setInventorySlotContents(x, item == null ? null : item.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(final String name) {
|
||||
if (name.equals("crafting")) {
|
||||
return this.crafting;
|
||||
}
|
||||
|
||||
if (name.equals("output")) {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
if (name.equals("pattern")) {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortCraftingItems() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<ItemStack> fluids = new ArrayList<>();
|
||||
for (ItemStack is : this.crafting) {
|
||||
if (is == null) continue;
|
||||
if (is.getItem() instanceof ItemFluidPacket) {
|
||||
fluids.add(is);
|
||||
} else {
|
||||
items.add(is);
|
||||
}
|
||||
}
|
||||
if (this.prioritize) {
|
||||
fluids.addAll(items);
|
||||
items.clear();
|
||||
} else {
|
||||
items.addAll(fluids);
|
||||
fluids.clear();
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
|
||||
if (this.crafting.getStackInSlot(i) == null) break;
|
||||
if (items.isEmpty()) {
|
||||
this.crafting.setInventorySlotContents(i, fluids.get(i));
|
||||
} else {
|
||||
this.crafting.setInventorySlotContents(i, items.get(i));
|
||||
}
|
||||
}
|
||||
saveChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoFillPattern() {
|
||||
return this.autoFillPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoFillPattern(boolean canFill) {
|
||||
this.autoFillPattern = canFill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PinsHandler getPinsHandler(EntityPlayer player) {
|
||||
return pinsInv.getHandler(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrid getGrid() {
|
||||
return getGridNode().getGrid();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.glodblock.github.common.parts.base;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
@@ -18,8 +17,6 @@ import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
@@ -44,6 +41,7 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
@@ -149,7 +147,7 @@ public abstract class FCPart extends AEBasePart
|
||||
this.viewCell.writeToNBT(data, "viewCell");
|
||||
}
|
||||
|
||||
public abstract GuiType getGui();
|
||||
public abstract GuiBridge getGui();
|
||||
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
@@ -223,7 +221,7 @@ public abstract class FCPart extends AEBasePart
|
||||
if (Platform.isServer()) {
|
||||
if (Util.hasPermission(player, SecurityPermissions.INJECT, (IGridHost) this)
|
||||
|| Util.hasPermission(player, SecurityPermissions.EXTRACT, (IGridHost) this)) {
|
||||
InventoryHandler.openGui(player, te.getWorldObj(), tePos, Objects.requireNonNull(getSide()), getGui());
|
||||
openGui(player);
|
||||
} else {
|
||||
player.addChatComponentMessage(new ChatComponentText("You don't have permission to view."));
|
||||
}
|
||||
@@ -231,6 +229,10 @@ public abstract class FCPart extends AEBasePart
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void openGui(EntityPlayer player) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), this.getGui());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPlacement(final EntityPlayer player, final ItemStack held, final ForgeDirection side) {
|
||||
super.onPlacement(player, held, side);
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
package com.glodblock.github.common.parts.base;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class FCSharedFluidBus extends PartUpgradeable implements IGridTickable {
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 9);
|
||||
private boolean lastRedstone;
|
||||
|
||||
public FCSharedFluidBus(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public abstract IIcon getFaceIcon();
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged() {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) {
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
try {
|
||||
if (!this.isSleeping()) {
|
||||
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
this.getHost().getTile().getWorldObj(),
|
||||
new BlockPos(this.getHost().getTile()),
|
||||
Objects.requireNonNull(this.getSide()),
|
||||
GuiType.FLUID_BUS_IO);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 13);
|
||||
bch.addBox(5, 5, 13, 11, 11, 14);
|
||||
bch.addBox(4, 4, 14, 12, 12, 16);
|
||||
}
|
||||
|
||||
protected TileEntity getConnectedTE() {
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity(self, (new BlockPos(self)).getOffSet(this.getSide()));
|
||||
}
|
||||
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorldObj();
|
||||
|
||||
if (w.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)) {
|
||||
return w.getTileEntity(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int calculateAmountToSend() {
|
||||
double amount = 1000D;
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
case 4:
|
||||
amount = amount * 1.5;
|
||||
case 3:
|
||||
amount = amount * 2;
|
||||
case 2:
|
||||
amount = amount * 4;
|
||||
case 1:
|
||||
amount = amount * 8;
|
||||
}
|
||||
switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) {
|
||||
case 4:
|
||||
amount = amount * 8;
|
||||
case 3:
|
||||
amount = amount * 12;
|
||||
case 2:
|
||||
amount = amount * 16;
|
||||
case 1:
|
||||
amount = amount * 32;
|
||||
}
|
||||
return (int) Math.floor(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.config.readFromNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.config.writeToNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.config;
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
public void setFluidInSlot(int id, IAEFluidStack fluid) {
|
||||
ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack());
|
||||
this.config.setInventorySlotContents(id, tmp);
|
||||
}
|
||||
|
||||
protected StorageChannel getChannel() {
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
protected abstract boolean canDoBusWork();
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo() {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user