allow memory card to copy encoded patterns of interfaces
This commit is contained in:
@@ -301,7 +301,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
final NBTTagCompound data = memoryCard.getData(heldItem);
|
||||
|
||||
if (this.getUnlocalizedName().equals(savedName)) {
|
||||
tileEntity.uploadSettings(SettingsFrom.MEMORY_CARD, data);
|
||||
tileEntity.uploadSettings(SettingsFrom.MEMORY_CARD, data, player);
|
||||
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
|
||||
} else {
|
||||
memoryCard.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
|
||||
|
||||
@@ -41,7 +41,7 @@ public enum PlayerMessages {
|
||||
DeviceNotLinked,
|
||||
StationCanNotBeLocated,
|
||||
SettingCleared,
|
||||
;
|
||||
MissingPatternsToEncode;
|
||||
|
||||
public ITextComponent get() {
|
||||
return new TextComponentTranslation(this.getName());
|
||||
|
||||
@@ -38,6 +38,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
@@ -301,7 +302,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
|
||||
public void onPlacement(final ItemStack stack, final EntityPlayer player, final EnumFacing side) {
|
||||
if (stack.hasTagCompound()) {
|
||||
this.uploadSettings(SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound());
|
||||
this.uploadSettings(SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound(), player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +312,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
* @param from source of settings
|
||||
* @param compound compound of source
|
||||
*/
|
||||
public void uploadSettings(final SettingsFrom from, final NBTTagCompound compound) {
|
||||
public void uploadSettings(final SettingsFrom from, final NBTTagCompound compound, EntityPlayer player) {
|
||||
if (compound != null && this instanceof IConfigurableObject) {
|
||||
final IConfigManager cm = ((IConfigurableObject) this).getConfigManager();
|
||||
if (cm != null) {
|
||||
|
||||
@@ -22,6 +22,8 @@ package appeng.tile.misc;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
@@ -37,16 +39,23 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.SettingsFrom;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -56,6 +65,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
@@ -308,4 +319,61 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
|
||||
public GuiBridge getGuiBridge() {
|
||||
return GuiBridge.GUI_INTERFACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound downloadSettings(SettingsFrom from) {
|
||||
NBTTagCompound output = super.downloadSettings(from);
|
||||
if (from == SettingsFrom.MEMORY_CARD) {
|
||||
final IItemHandler inv = this.getInventoryByName("patterns");
|
||||
if (inv instanceof AppEngInternalInventory) {
|
||||
((AppEngInternalInventory) inv).writeToNBT(output, "patterns");
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadSettings(SettingsFrom from, NBTTagCompound compound, EntityPlayer player) {
|
||||
super.uploadSettings(from, compound, player);
|
||||
final IItemHandler inv = this.getInventoryByName("patterns");
|
||||
if (inv instanceof AppEngInternalInventory) {
|
||||
final AppEngInternalInventory target = (AppEngInternalInventory) inv;
|
||||
AppEngInternalInventory tmp = new AppEngInternalInventory(null, target.getSlots());
|
||||
tmp.readFromNBT(compound, "patterns");
|
||||
PlayerMainInvWrapper playerInv = new PlayerMainInvWrapper(player.inventory);
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
int missingPatternsToEncode = 0;
|
||||
|
||||
for (int i = 0; i < inv.getSlots(); i++) {
|
||||
if (target.getStackInSlot(i).getItem() instanceof ItemEncodedPattern) {
|
||||
ItemStack blank = materials.blankPattern().maybeStack(target.getStackInSlot(i).getCount()).get();
|
||||
if (!player.addItemStackToInventory(blank)) {
|
||||
player.dropItem(blank, true);
|
||||
}
|
||||
target.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int x = 0; x < tmp.getSlots(); x++) {
|
||||
if (!tmp.getStackInSlot(x).isEmpty()) {
|
||||
boolean found = false;
|
||||
for (int i = 0; i < playerInv.getSlots(); i++) {
|
||||
if (materials.blankPattern().isSameAs(playerInv.getStackInSlot(i))) {
|
||||
target.setStackInSlot(x, tmp.getStackInSlot(x));
|
||||
playerInv.getStackInSlot(i).shrink(1);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
missingPatternsToEncode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Platform.isServer() && missingPatternsToEncode > 0) {
|
||||
player.sendMessage(PlayerMessages.MissingPatternsToEncode.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import appeng.block.networking.BlockEnergyCell;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.SettingsFrom;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
@@ -106,7 +107,7 @@ public class TileEnergyCell extends AENetworkTile implements IAEPowerStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadSettings(final SettingsFrom from, final NBTTagCompound compound) {
|
||||
public void uploadSettings(final SettingsFrom from, final NBTTagCompound compound, EntityPlayer player) {
|
||||
if (from == SettingsFrom.DISMANTLE_ITEM) {
|
||||
this.internalCurrentPower = compound.getDouble("internalCurrentPower");
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ tile.appliedenergistics2.sky_stone_slab.name=Sky Stone Slabs
|
||||
// Chat Messages
|
||||
chat.appliedenergistics2.ChestCannotReadStorageCell=ME Chest cannot read storage cell.
|
||||
chat.appliedenergistics2.SettingCleared=Memory card cleared.
|
||||
chat.appliedenergistics2.MissingPatternsToEncode=Not enough patterns to finish copying
|
||||
chat.appliedenergistics2.OutOfRange=Wireless Out Of Range.
|
||||
chat.appliedenergistics2.InvalidMachine=Invalid Machine.
|
||||
chat.appliedenergistics2.LoadedSettings=Loaded device configuration from memory card.
|
||||
|
||||
Reference in New Issue
Block a user