Skip to content

Commit

Permalink
Fixed notebook gen in Admin Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
MineDragonCZ committed Nov 7, 2023
1 parent 78f1d62 commit 0eabc16
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void generateAddressEntries(boolean reset) {
StargateEntry e = new StargateEntry();
e.pos = pos;
e.address = notGeneratedMap.get(pos).get(Objects.requireNonNull(guiBase.gateTile).getSymbolType());
e.addresses = notGeneratedMap.get(pos);
e.notGenerated = true;
e.defaultName = "NOT GENERATED - ";
entries.add(e);
Expand Down Expand Up @@ -244,10 +245,10 @@ public void mainButtonPerformAction(int index) {
dialGate(index, EnumDialingType.values()[btn.getCurrentState()]);
break;
case 3:
JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(EntryActionEnum.GIVE_NOTEBOOK, pos, entry.notGenerated));
JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(EntryActionEnum.GIVE_NOTEBOOK, pos, entry.addresses, entry.notGenerated));
break;
case 4:
JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(EntryActionEnum.TELEPORT_TO_POS, pos, false));
JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(EntryActionEnum.TELEPORT_TO_POS, pos, null, false));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import tauri.dev.jsg.stargate.network.StargateAddress;
import tauri.dev.jsg.stargate.network.StargatePos;
import tauri.dev.jsg.stargate.network.SymbolTypeEnum;

import java.util.Map;

public class StargateEntry {
public StargatePos pos;
public StargateAddress address;

public Map<SymbolTypeEnum, StargateAddress> addresses;

public boolean notGenerated = false;
public String defaultName = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import tauri.dev.jsg.JSG;
import tauri.dev.jsg.item.JSGItems;
import tauri.dev.jsg.item.linkable.dialer.UniverseDialerItem;
import tauri.dev.jsg.item.linkable.dialer.UniverseDialerMode;
Expand All @@ -30,6 +29,7 @@
import tauri.dev.jsg.util.BlockHelpers;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class EntryActionToServer implements IMessage {
Expand All @@ -44,6 +44,8 @@ public class EntryActionToServer implements IMessage {
private StargatePos targetGatePos;
private EnumDialingType dialType = EnumDialingType.NORMAL;

private Map<SymbolTypeEnum, StargateAddress> addresses = new HashMap<>();

public EntryActionToServer() {
}

Expand Down Expand Up @@ -71,7 +73,7 @@ public EntryActionToServer(EnumHand hand, String name, StargatePos targetGate) {
this.linkedGate = null;
}

public EntryActionToServer(EntryActionEnum action, StargatePos targetGate, boolean notGenerated) {
public EntryActionToServer(EntryActionEnum action, StargatePos targetGate, Map<SymbolTypeEnum, StargateAddress> addresses, boolean notGenerated) {
this.hand = EnumHand.MAIN_HAND;
this.dataType = EntryDataTypeEnum.ADMIN_CONTROLLER;
this.action = action;
Expand All @@ -80,6 +82,7 @@ public EntryActionToServer(EntryActionEnum action, StargatePos targetGate, boole
this.targetGatePos = targetGate;
this.addressToDial = null;
this.linkedGate = null;
this.addresses = addresses;
}

public EntryActionToServer(EntryActionEnum action, BlockPos linkedGate) {
Expand Down Expand Up @@ -129,10 +132,20 @@ public void toBytes(ByteBuf buf) {
} else buf.writeBoolean(false);
if (targetGatePos != null) {
buf.writeBoolean(true);
buf.writeInt(targetGatePos.symbolType.id);
targetGatePos.toBytes(buf);
} else buf.writeBoolean(false);
if(dialType == null) dialType = EnumDialingType.NORMAL;
if (dialType == null) dialType = EnumDialingType.NORMAL;
buf.writeInt(dialType.ordinal());

if (addresses != null) {
buf.writeBoolean(true);
buf.writeInt(addresses.size());
for (Map.Entry<SymbolTypeEnum, StargateAddress> e : addresses.entrySet()) {
buf.writeInt(e.getKey().id);
e.getValue().toBytes(buf);
}
}
}

@Override
Expand All @@ -152,11 +165,22 @@ public void fromBytes(ByteBuf buf) {
linkedGate = BlockPos.fromLong(buf.readLong());
}
if (buf.readBoolean()) {
targetGatePos = new StargatePos(SymbolTypeEnum.valueOf(index), buf);
int id = buf.readInt();
targetGatePos = new StargatePos(SymbolTypeEnum.valueOf(id), buf);
}
int i = buf.readInt();
if(EnumDialingType.values().length <= i) i = 0;
if (EnumDialingType.values().length <= i) i = 0;
dialType = EnumDialingType.values()[i];

if (buf.readBoolean()) {
addresses = new HashMap<>();
int ii = buf.readInt();
for (int j = 0; j < ii; j++) {
SymbolTypeEnum s = SymbolTypeEnum.valueOf(buf.readInt());
StargateAddress sa = new StargateAddress(buf);
addresses.put(s, sa);
}
}
}

public static class EntryActionServerHandler implements IMessageHandler<EntryActionToServer, IMessage> {
Expand All @@ -171,7 +195,7 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) {
NBTTagCompound compound = stack.getTagCompound();

if (message.dataType.page()) {
if(compound == null) return;
if (compound == null) return;
NBTTagList list = compound.getTagList("addressList", NBT.TAG_COMPOUND);

switch (message.action) {
Expand Down Expand Up @@ -203,7 +227,7 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) {
break;
}
} else if (message.dataType.universe()) {
if(compound == null) return;
if (compound == null) return;
NBTTagList list = compound.getTagList(UniverseDialerMode.MEMORY.tagListName, NBT.TAG_COMPOUND);
BlockPos linkedPos = BlockPos.fromLong(compound.getLong(UniverseDialerMode.MEMORY.tagPosName));
NBTTagCompound selectedCompound = list.getCompoundTagAt(message.index);
Expand Down Expand Up @@ -241,7 +265,7 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) {
break;
}
} else if (message.dataType.oc()) {
if(compound == null) return;
if (compound == null) return;
NBTTagList list = compound.getTagList(UniverseDialerMode.OC.tagListName, NBT.TAG_COMPOUND);

switch (message.action) {
Expand Down Expand Up @@ -301,14 +325,16 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) {
StargateAddress address;
int originId;
if (message.index == 1) {
if (message.addresses == null) continue;
// gate is not generated - there is no tileEntity
StargateNetwork sgn = StargateNetwork.get(world);
/*StargateNetwork sgn = StargateNetwork.get(world);
Map<SymbolTypeEnum, StargateAddress> map = sgn.getMapNotGenerated().get(message.targetGatePos);
if(map == null){
JSG.info("Lol123");
continue;
}
address = StargateNetwork.get(world).getMapNotGenerated().get(message.targetGatePos).get(s);
address = map.get(s);*/
address = message.addresses.get(s);
originId = StargateClassicBaseTile.getOriginId(null, message.targetGatePos.dimensionID, -1);
} else {
address = message.targetGatePos.getTileEntity().getStargateAddress(s);
Expand Down

0 comments on commit 0eabc16

Please sign in to comment.