save upgrades
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package appeng.fluids.container;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.IUpgradeableCellContainer;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.api.networking.IGridHost;
|
||||
@@ -36,6 +41,8 @@ import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import appeng.parts.automation.StackUpgradeInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
@@ -45,7 +52,9 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
@@ -74,6 +83,8 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
private int ticks = 0;
|
||||
private final int slot;
|
||||
|
||||
protected AppEngInternalInventory upgrades;
|
||||
|
||||
public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable) {
|
||||
this(ip, monitorable, null, true);
|
||||
}
|
||||
@@ -129,43 +140,45 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
this.bindPlayerInventory(ip, 0, 140);
|
||||
}
|
||||
hasPower = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001;
|
||||
upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2);
|
||||
this.loadFromNBT();
|
||||
|
||||
this.setupUpgrades();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
|
||||
|
||||
if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
|
||||
this.setValidContainer(false);
|
||||
} else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) {
|
||||
if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) {
|
||||
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack());
|
||||
} else {
|
||||
this.setValidContainer(false);
|
||||
}
|
||||
}
|
||||
|
||||
// drain 1 ae t
|
||||
this.ticks++;
|
||||
if (this.ticks > 10) {
|
||||
double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
|
||||
this.ticks = 0;
|
||||
this.hasPower = power > 0.001;
|
||||
}
|
||||
|
||||
if (!this.wirelessTerminalGUIObject.rangeCheck()) {
|
||||
if (Platform.isServer() && this.isValidContainer()) {
|
||||
this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get());
|
||||
}
|
||||
|
||||
this.setValidContainer(false);
|
||||
} else {
|
||||
this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange()));
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
|
||||
|
||||
if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
|
||||
this.setValidContainer(false);
|
||||
} else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) {
|
||||
if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) {
|
||||
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack());
|
||||
} else {
|
||||
this.setValidContainer(false);
|
||||
}
|
||||
}
|
||||
|
||||
// drain 1 ae t
|
||||
this.ticks++;
|
||||
if (this.ticks > 10) {
|
||||
double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
|
||||
this.ticks = 0;
|
||||
this.hasPower = power > 0.001;
|
||||
}
|
||||
|
||||
if (!this.wirelessTerminalGUIObject.rangeCheck()) {
|
||||
if (Platform.isServer() && this.isValidContainer()) {
|
||||
this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get());
|
||||
}
|
||||
|
||||
this.setValidContainer(false);
|
||||
} else {
|
||||
this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange()));
|
||||
}
|
||||
|
||||
if (this.monitor != this.terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) {
|
||||
this.setValidContainer(false);
|
||||
}
|
||||
@@ -218,9 +231,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
}
|
||||
}
|
||||
//this.updatePowerStatus();
|
||||
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -453,6 +464,11 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChange(Slot s) {
|
||||
detectAndSendChanges();
|
||||
}
|
||||
|
||||
private void queueInventory(final IContainerListener c) {
|
||||
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
|
||||
try {
|
||||
@@ -527,7 +543,6 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
@Override
|
||||
public void setupUpgrades() {
|
||||
if (wirelessTerminalGUIObject != null) {
|
||||
final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades");
|
||||
for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) {
|
||||
this.addSlotToContainer(
|
||||
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, 139 + upgradeSlot * 18, this.getInventoryPlayer()))
|
||||
@@ -536,14 +551,24 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
if (Platform.isServer()) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
this.upgrades.writeToNBT(tag, "upgrades");
|
||||
|
||||
this.wirelessTerminalGUIObject.saveChanges(tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromNBT() {
|
||||
NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound();
|
||||
if (data != null) {
|
||||
upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user