Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Config-p2p-interface-copy-paste'…
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
Dream-Master committed Oct 13, 2023
2 parents 2c81f2a + 0f28ed2 commit b4df7a4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/appeng/helpers/DualityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
private final IInterfaceHost iHost;
private final BaseActionSource mySource;
private final BaseActionSource interfaceRequestSource;
private final ConfigManager cm = new ConfigManager(this);
public final ConfigManager cm = new ConfigManager(this);
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, NUMBER_OF_CONFIG_SLOTS);
private final AppEngInternalInventory storage = new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS);
private final AppEngInternalInventory patterns = new AppEngInternalInventory(this, NUMBER_OF_PATTERN_SLOTS * 4);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/appeng/parts/p2p/PartP2PInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ public void writeToNBT(final NBTTagCompound data) {
this.duality.writeToNBT(data);
}

@Override
public NBTTagCompound getMemoryCardData() {
final NBTTagCompound output = super.getMemoryCardData();
this.duality.cm.writeToNBT(output);
return output;
}

@Override
public void pasteMemoryCardData(PartP2PTunnel newTunnel, NBTTagCompound data) throws GridAccessException {
this.duality.cm.readFromNBT(data);
super.pasteMemoryCardData(newTunnel, data);
}

@Override
public void addToWorld() {
super.addToWorld();
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/appeng/parts/p2p/PartP2PTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.me.GridAccessException;
import appeng.me.cache.P2PCache;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.parts.PartBasicState;
import cpw.mods.fml.relauncher.Side;
Expand Down Expand Up @@ -186,6 +187,27 @@ public void readFromNBT(final NBTTagCompound data) {
this.setFrequency(data.getLong("freq"));
}

public NBTTagCompound getMemoryCardData() {
final NBTTagCompound output = new NBTTagCompound();

if (this.hasCustomName()) {
final NBTTagCompound dsp = new NBTTagCompound();
dsp.setString("Name", this.getCustomName());
output.setTag("display", dsp);
}
output.setLong("freq", this.getFrequency());

return output;
}

public void pasteMemoryCardData(PartP2PTunnel<?> newTunnel, NBTTagCompound data) throws GridAccessException {
final long freq = data.getLong("freq");
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq(newTunnel, freq);
PartP2PTunnel input = p2p.getInput(freq);
if (input != null) newTunnel.setCustomNameInternal(input.getCustomName());
}

@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
Expand Down Expand Up @@ -243,8 +265,6 @@ public boolean onPartShiftActivate(final EntityPlayer player, final Vec3 pos) {
if (is != null && is.getItem() instanceof IMemoryCard mc) {
if (ForgeEventFactory.onItemUseStart(player, is, 1) <= 0) return false;

final NBTTagCompound data = new NBTTagCompound();

long newFreq = this.getFrequency();
final boolean wasOutput = this.isOutput();
this.setOutput(false);
Expand All @@ -258,15 +278,13 @@ public boolean onPartShiftActivate(final EntityPlayer player, final Vec3 pos) {
} catch (final GridAccessException e) {
// :P
}

this.onTunnelConfigChange();


final NBTTagCompound data = this.getMemoryCardData();
final ItemStack p2pItem = this.getItemStack(PartItemStack.Wrench);
final String type = p2pItem.getUnlocalizedName();

p2pItem.writeToNBT(data);
data.setLong("freq", this.getFrequency());
if (hasCustomName()) data.setString("custom_name", getCustomName());

mc.setMemoryCardContents(is, type + ".name", data);
mc.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/appeng/parts/p2p/PartP2PTunnelNormal.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
newTunnel.setOutput(true);

try {
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq(newTunnel, freq);
PartP2PTunnel input = p2p.getInput(freq);
if (input != null) newTunnel.setCustomNameInternal(input.getCustomName());
pasteMemoryCardData(newTunnel, data);
} catch (final GridAccessException e) {
// :P
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import appeng.api.parts.IPartItem;
import appeng.api.parts.PartItemStack;
import appeng.me.GridAccessException;
import appeng.me.cache.P2PCache;
import appeng.util.Platform;

/**
Expand All @@ -35,7 +34,6 @@ public boolean onPartActivate(EntityPlayer player, Vec3 pos) {
final NBTTagCompound data = mc.getData(is);

final ItemStack newType = ItemStack.loadItemStackFromNBT(data);
final long freq = data.getLong("freq");

if (newType != null) {
if (newType.getItem() instanceof IPartItem partItem) {
Expand All @@ -49,10 +47,7 @@ public boolean onPartActivate(EntityPlayer player, Vec3 pos) {
newTunnel.setOutput(true);

try {
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq(newTunnel, freq);
PartP2PTunnel input = p2p.getInput(freq);
if (input != null) newTunnel.setCustomNameInternal(input.getCustomName());
pasteMemoryCardData(newTunnel, data);
} catch (final GridAccessException e) {
// :P
}
Expand Down

0 comments on commit b4df7a4

Please sign in to comment.