mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-12 00:07:29 +00:00
Update Storage Monitor
This commit is contained in:
1 parent
46f6dfef2e
commit
f3e5797ec5
6 files changed
+42
-214
No files matched your search
@@ -3,9 +3,11 @@ package com.glodblock.github.common.item;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.parts.PartFluidConversionMonitor;
|
||||
import com.glodblock.github.common.tabs.FluidCraftingTabs;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
@@ -37,6 +39,11 @@ public class ItemFluidConversionMonitor extends FCBaseItem implements IPartItem
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack p_77650_1_) {
|
||||
return FCPartsTexture.PartTerminalBroad.getIcon();
|
||||
}
|
||||
|
||||
public void registerIcons(IIconRegister _iconRegister) {}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.glodblock.github.common.item;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.textures.FCPartsTexture;
|
||||
import com.glodblock.github.common.parts.PartFluidStorageMonitor;
|
||||
import com.glodblock.github.common.tabs.FluidCraftingTabs;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
@@ -37,6 +39,11 @@ public class ItemFluidStorageMonitor extends FCBaseItem implements IPartItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack p_77650_1_) {
|
||||
return FCPartsTexture.PartTerminalBroad.getIcon();
|
||||
}
|
||||
|
||||
public void registerIcons(IIconRegister _iconRegister) {}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -1,157 +1,28 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import static appeng.util.item.AEFluidStackType.FLUID_STACK_TYPE;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import appeng.parts.reporting.PartConversionMonitor;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartFluidConversionMonitor extends PartFluidStorageMonitor {
|
||||
public class PartFluidConversionMonitor extends PartConversionMonitor {
|
||||
|
||||
public PartFluidConversionMonitor(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate(final EntityPlayer player, final Vec3 pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
FluidStack fluidStack;
|
||||
ItemStack item = player.getCurrentEquippedItem();
|
||||
if (item != null && item.getItem() instanceof ItemFluidPacket) {
|
||||
fluidStack = ItemFluidPacket.getFluidStack(item);
|
||||
} else {
|
||||
fluidStack = Util.FluidUtil.getFluidFromContainer(item);
|
||||
}
|
||||
if (this.getDisplayed() == null || fluidStack == null
|
||||
|| fluidStack.getFluid() != ((IAEFluidStack) this.getDisplayed()).getFluid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
// Migrate old tag
|
||||
if (data.hasKey("configuredItem")) {
|
||||
final NBTTagCompound myItem = data.getCompoundTag("configuredItem");
|
||||
if (!myItem.hasNoTags() && !myItem.hasKey("StackType")) {
|
||||
myItem.setString("StackType", FLUID_STACK_TYPE.getId());
|
||||
}
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy().getStorage().getFluidInventory();
|
||||
final IAEFluidStack input = (IAEFluidStack) this.getDisplayed().copy().setStackSize(fluidStack.amount);
|
||||
final IAEFluidStack failedToInsert = Platform
|
||||
.poweredInsert(energy, cell, input, new PlayerSource(player, this));
|
||||
if (failedToInsert != null && failedToInsert.getStackSize() == input.getStackSize()) {
|
||||
return false;
|
||||
} else if (failedToInsert == null || failedToInsert.getStackSize() != input.getStackSize()) {
|
||||
if (item.getItem() instanceof ItemFluidPacket) {
|
||||
if (failedToInsert != null) {
|
||||
player.getCurrentEquippedItem()
|
||||
.setTagCompound(ItemFluidPacket.newStack(failedToInsert).getTagCompound());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
ItemStack tmp = item.copy();
|
||||
tmp.stackSize = 1;
|
||||
ItemStack tank = null;
|
||||
if (failedToInsert == null) {
|
||||
tank = Util.FluidUtil.clearFluid(tmp);
|
||||
} else {
|
||||
if (tmp.getItem() instanceof IFluidContainerItem) {
|
||||
tank = Util.FluidUtil.setFluidContainerAmount(tmp, (int) failedToInsert.getStackSize());
|
||||
} else if (FluidContainerRegistry.isContainer(tmp)) {
|
||||
IAEFluidStack insertedFluid = input.copy();
|
||||
insertedFluid.decStackSize(failedToInsert.getStackSize());
|
||||
this.getProxy().getStorage().getFluidInventory()
|
||||
.extractItems(insertedFluid, Actionable.MODULATE, new PlayerSource(player, this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (tank != null && !player.inventory.addItemStackToInventory(tank)) {
|
||||
player.entityDropItem(tank, 0);
|
||||
}
|
||||
}
|
||||
item.stackSize--;
|
||||
if (item.stackSize <= 0) {
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (final GridAccessException ignored) {}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extractItem(final EntityPlayer player) {
|
||||
final IAEFluidStack input = (IAEFluidStack) this.getDisplayed();
|
||||
ItemStack eq = player.getCurrentEquippedItem();
|
||||
if (input != null && Util.FluidUtil.isFluidContainer(eq) && Util.FluidUtil.isEmpty(eq)) {
|
||||
try {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy().getStorage().getFluidInventory();
|
||||
ItemStack tank = eq.copy();
|
||||
tank.stackSize = 1;
|
||||
MutablePair<Integer, ItemStack> fillStack = Util.FluidUtil.fillStack(tank, input.getFluidStack());
|
||||
input.setStackSize(fillStack.left);
|
||||
|
||||
final IAEFluidStack retrieved = Platform
|
||||
.poweredExtraction(energy, cell, input, new PlayerSource(player, this));
|
||||
if (retrieved != null) {
|
||||
if (!player.inventory.addItemStackToInventory(fillStack.right)) {
|
||||
player.entityDropItem(fillStack.right.copy(), 0);
|
||||
}
|
||||
eq.stackSize--;
|
||||
if (eq.stackSize <= 0) {
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
|
||||
ItemStack newItems = adaptor.addItems(
|
||||
Util.FluidUtil.setFluidContainerAmount(fillStack.right, (int) retrieved.getStackSize()));
|
||||
if (newItems != null) {
|
||||
final TileEntity te = this.getTile();
|
||||
final List<ItemStack> list = Collections.singletonList(newItems);
|
||||
Platform.spawnDrops(
|
||||
player.worldObj,
|
||||
te.xCoord + this.getSide().offsetX,
|
||||
te.yCoord + this.getSide().offsetY,
|
||||
te.zCoord + this.getSide().offsetZ,
|
||||
list);
|
||||
}
|
||||
|
||||
if (player.openContainer != null) {
|
||||
player.openContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException ignored) {}
|
||||
}
|
||||
|
||||
super.readFromNBT(data);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,28 @@
|
||||
package com.glodblock.github.common.parts;
|
||||
|
||||
import static appeng.util.item.AEFluidStackType.FLUID_STACK_TYPE;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.glodblock.github.common.parts.base.FCPartMonitor;
|
||||
import appeng.parts.reporting.PartStorageMonitor;
|
||||
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.helpers.Reflected;
|
||||
public class PartFluidStorageMonitor extends PartStorageMonitor {
|
||||
|
||||
public class PartFluidStorageMonitor extends FCPartMonitor {
|
||||
|
||||
private static final CableBusTextures FRONT_BRIGHT_ICON = CableBusTextures.PartStorageMonitor_Bright;
|
||||
private static final CableBusTextures FRONT_DARK_ICON = CableBusTextures.PartStorageMonitor_Dark;
|
||||
private static final CableBusTextures FRONT_COLORED_ICON = CableBusTextures.PartStorageMonitor_Colored;
|
||||
private static final CableBusTextures FRONT_COLORED_ICON_LOCKED = CableBusTextures.PartStorageMonitor_Colored_Locked;
|
||||
|
||||
@Reflected
|
||||
public PartFluidStorageMonitor(final ItemStack is) {
|
||||
public PartFluidStorageMonitor(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableBusTextures getFrontBright() {
|
||||
return FRONT_BRIGHT_ICON;
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
// Migrate old tag
|
||||
if (data.hasKey("configuredItem")) {
|
||||
final NBTTagCompound myItem = data.getCompoundTag("configuredItem");
|
||||
if (!myItem.hasNoTags() && !myItem.hasKey("StackType")) {
|
||||
myItem.setString("StackType", FLUID_STACK_TYPE.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableBusTextures getFrontColored() {
|
||||
return this.isLocked() ? FRONT_COLORED_ICON_LOCKED : FRONT_COLORED_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableBusTextures getFrontDark() {
|
||||
return FRONT_DARK_ICON;
|
||||
super.readFromNBT(data);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.crossmod.waila.part.FluidInvWailaDataProvider;
|
||||
import com.glodblock.github.crossmod.waila.part.FluidMonitorWailaDataProvider;
|
||||
import com.glodblock.github.crossmod.waila.part.SpeedWailaDataProvider;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -32,8 +31,7 @@ public class PartWailaDataProvider implements IWailaDataProvider {
|
||||
public PartWailaDataProvider() {
|
||||
final IPartWailaDataProvider speed = new SpeedWailaDataProvider();
|
||||
final IPartWailaDataProvider fluidInv = new FluidInvWailaDataProvider();
|
||||
final IPartWailaDataProvider fluidMonitor = new FluidMonitorWailaDataProvider();
|
||||
this.providers = Lists.newArrayList(speed, fluidInv, fluidMonitor);
|
||||
this.providers = Lists.newArrayList(speed, fluidInv);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.glodblock.github.crossmod.waila.part;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.common.parts.base.FCPartMonitor;
|
||||
import com.glodblock.github.crossmod.waila.Tooltip;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.integration.modules.waila.part.BasePartWailaDataProvider;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
|
||||
public class FluidMonitorWailaDataProvider extends BasePartWailaDataProvider {
|
||||
|
||||
private final String key = "fluidStore";
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody(final IPart part, final List<String> currentToolTip,
|
||||
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
|
||||
if (part instanceof FCPartMonitor && accessor.getNBTData().hasKey(key)) {
|
||||
IAEFluidStack iaeFluidStack = Util.loadFluidStackFromNBT(accessor.getNBTData().getCompoundTag(key));
|
||||
if (iaeFluidStack != null) currentToolTip.add(
|
||||
Tooltip.fluidFormat(
|
||||
iaeFluidStack.getFluidStack().getLocalizedName(),
|
||||
iaeFluidStack.getStackSize()));
|
||||
}
|
||||
return currentToolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(final EntityPlayerMP player, final IPart part, final TileEntity te,
|
||||
final NBTTagCompound tag, final World world, final int x, final int y, final int z) {
|
||||
if (part instanceof FCPartMonitor && ((FCPartMonitor) part).getAEStoreFluidStack() != null) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
((FCPartMonitor) part).getAEStoreFluidStack().writeToNBT(data);
|
||||
tag.setTag(key, data);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user