Added packet for renaming and check if the ring is null before trying to open UI

This commit is contained in:
ReignOfFROZE committed 2025-03-22 13:09:00 -04:00
1 parent 82771d41b2
commit ba991659a4
5 files changed
+76 -11

No files matched your search

@@ -77,7 +77,8 @@ public class KeyHandler {
private static void ringOfLokiOpenUI() {
if(ItemLokiRing.isModularUIEnabled) {
ItemStack ring = ItemLokiRing.getLokiRing(Minecraft.getMinecraft().thePlayer);
GuiLokiSchematics.open(ring);
if(ring != null)
GuiLokiSchematics.open(ring);
}
}
}
@@ -29,6 +29,7 @@ import vazkii.botania.common.item.relic.ItemLokiRing;
import vazkii.botania.common.network.PacketHandler;
import vazkii.botania.common.network.PacketLokiChangeSchematic;
import vazkii.botania.common.network.PacketLokiDeleteSchematic;
import vazkii.botania.common.network.PacketLokiRenameSchematic;
import java.util.Arrays;
import java.util.Comparator;
@@ -159,7 +160,6 @@ public class GuiLokiSchematics extends CustomModularScreen {
return ModularPanel.defaultPanel("lokiSchematics")
.child(
new TextWidget(IKey.dynamic(() -> selectedSchematic == null ? StatCollector.translateToLocal("botaniamisc.select_schematic") : StatCollector.translateToLocal("botaniamisc.selected_schematic") + " " + selectedSchematic))
.style(EnumChatFormatting.BLACK)
.align(Alignment.TopCenter)
.marginTop(8)
.scale(0.5f))
@@ -190,12 +190,7 @@ public class GuiLokiSchematics extends CustomModularScreen {
}
public void persist() {
if (itemStack.getTagCompound().getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC).equals(schematicToBeRenamed)) {
itemStack.getTagCompound().setString(ItemLokiRing.TAG_CURRENT_SCHEMATIC, newValue);
}
NBTBase nbt = itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).getTag(schematicToBeRenamed.toString());
itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).removeTag(schematicToBeRenamed.toString());
itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).setTag(newValue, nbt);
PacketHandler.INSTANCE.sendToServer(new PacketLokiRenameSchematic(schematicToBeRenamed.toString(), newValue));
}
@Override
@@ -214,7 +209,6 @@ public class GuiLokiSchematics extends CustomModularScreen {
return ModularPanel.defaultPanel("rename")
.child(new TextWidget("Schematic Name:")
.style(EnumChatFormatting.BLACK)
.pos(10, 10)
.size(180, 20))
.child(new TextFieldWidget()
@@ -33,6 +33,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.AxisAlignedBB;
@@ -85,7 +86,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
public List<Object> schematicNames;
public enum HUD_MESSAGE {
public enum HUD_MESSAGE {
MODE, BREAKING, CLEAR, MIRROR, INSUFFICIENT_MANA, SCHEMATIC_SAVED
}
@@ -345,6 +346,15 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
stack.getTagCompound().setTag(TAG_CURRENT_SCHEMATIC, new NBTTagString(schematicName));
}
public static void renameSchematic(ItemStack lokiStack, String schematicToBeRenamed, String newName) {
if (lokiStack.getTagCompound().getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC).equals(schematicToBeRenamed)) {
lokiStack.getTagCompound().setString(ItemLokiRing.TAG_CURRENT_SCHEMATIC, newName);
}
NBTBase nbt = lokiStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).getTag(schematicToBeRenamed.toString());
lokiStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).removeTag(schematicToBeRenamed.toString());
lokiStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).setTag(newName, nbt);
}
@Optional.Method(modid = "modularui2")
public static void deleteSchematic(ItemStack lokiStack, String schematicName) {
NBTTagCompound map = lokiStack.getTagCompound().getCompoundTag(TAG_SAVED_SCHEMATICS);
@@ -19,6 +19,7 @@ public class PacketHandler {
INSTANCE.registerMessage(PacketLokiSaveSchematic.class, PacketLokiSaveSchematic.class, 4, Side.SERVER);
INSTANCE.registerMessage(PacketLokiChangeSchematic.class, PacketLokiChangeSchematic.class, 5, Side.SERVER);
INSTANCE.registerMessage(PacketLokiDeleteSchematic.class, PacketLokiDeleteSchematic.class, 6, Side.SERVER);
INSTANCE.registerMessage(PacketLokiHudNotificationAck.class, PacketLokiHudNotificationAck.class, 7, Side.CLIENT);
INSTANCE.registerMessage(PacketLokiRenameSchematic.class, PacketLokiRenameSchematic.class, 7, Side.SERVER);
INSTANCE.registerMessage(PacketLokiHudNotificationAck.class, PacketLokiHudNotificationAck.class, 8, Side.CLIENT);
}
}
@@ -0,0 +1,59 @@
package vazkii.botania.common.network;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import vazkii.botania.common.item.relic.ItemLokiRing;
public class PacketLokiRenameSchematic implements IMessage, IMessageHandler<PacketLokiRenameSchematic, IMessage> {
private String schematicToBeRenamed;
private String newName;
public PacketLokiRenameSchematic() {
}
public PacketLokiRenameSchematic(String schematicToBeRenamed, String newValue) {
this.schematicToBeRenamed = schematicToBeRenamed;
this.newName = newValue;
}
@Override
public void fromBytes(ByteBuf buf) {
int schematicToBeRenamedLength = buf.readInt();
this.schematicToBeRenamed = new String(buf.readBytes(schematicToBeRenamedLength).array());
if(schematicToBeRenamed.equals("null")) {
this.schematicToBeRenamed = null;
}
int newNameLength = buf.readInt();
this.newName = new String(buf.readBytes(newNameLength).array());
if(newName.equals("null")) {
this.newName = null;
}
}
@Override
public void toBytes(ByteBuf buf) {
schematicToBeRenamed = schematicToBeRenamed == null ? "null" : schematicToBeRenamed;
buf.writeInt(schematicToBeRenamed.length());
buf.writeBytes(schematicToBeRenamed.getBytes());
newName = newName == null ? "null" : newName;
buf.writeInt(newName.length());
buf.writeBytes(newName.getBytes());
}
@Override
public IMessage onMessage(PacketLokiRenameSchematic message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
ItemStack lokiStack = ItemLokiRing.getLokiRing(player);
if(lokiStack != null && lokiStack.getItem() instanceof ItemLokiRing) {
ItemLokiRing.renameSchematic(lokiStack, message.schematicToBeRenamed, message.newName);
ItemLokiRing.syncLokiRing(player);
}
return null;
}
}