diff --git a/dependencies.gradle b/dependencies.gradle index 59c17fcc4..24ca3b09f 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -5,6 +5,9 @@ dependencies { api('com.github.GTNewHorizons:GTNHLib:0.6.22:dev') compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.42:api') {transitive=false} + compileOnly('com.github.GTNewHorizons:ModularUI2:2.2.4-1.7.10:dev') +// runtimeOnlyNonPublishable('com.github.GTNewHorizons:ModularUI2:2.2.4-1.7.10:dev') + compileOnly('com.github.GTNewHorizons:ForgeMultipart:1.6.2:dev') {transitive=false} devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.7.44-GTNH:dev') compileOnly('com.github.GTNewHorizons:Railcraft:9.16.26:api') {transitive=false} diff --git a/src/main/java/vazkii/botania/client/core/handler/KeyHandler.java b/src/main/java/vazkii/botania/client/core/handler/KeyHandler.java index 4eb34f0ef..60a57cfd8 100644 --- a/src/main/java/vazkii/botania/client/core/handler/KeyHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/KeyHandler.java @@ -1,28 +1,40 @@ package vazkii.botania.client.core.handler; -import net.minecraft.client.settings.KeyBinding; -import vazkii.botania.common.network.PacketHandler; -import vazkii.botania.common.network.PacketLokiClear; -import vazkii.botania.common.network.PacketLokiMirror; -import vazkii.botania.common.network.PacketLokiToggle; +import com.cleanroommc.modularui.factory.ClientGUI; +import com.cleanroommc.modularui.factory.GuiData; +import com.cleanroommc.modularui.factory.GuiFactories; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.item.ItemStack; +import vazkii.botania.client.gui.loki.GuiLokiSchematics; +import vazkii.botania.common.item.relic.ItemLokiRing; +import vazkii.botania.common.network.PacketHandler; +import vazkii.botania.common.network.PacketLokiClear; +import vazkii.botania.common.network.PacketLokiMirror; +import vazkii.botania.common.network.PacketLokiSaveSchematic; +import vazkii.botania.common.network.PacketLokiToggle; public class KeyHandler { private static final KeyBinding keyToggleRingOfLoki= new KeyBinding("botaniamisc.toggleLoki", 0, "botaniamisc.keyCategory"); private static final KeyBinding keyRingOfLokiClear= new KeyBinding("botaniamisc.ringOfLokiClear", 0, "botaniamisc.keyCategory"); private static final KeyBinding keyRingOfLokiMirror= new KeyBinding("botaniamisc.ringOfLokiMirror", 0, "botaniamisc.keyCategory"); + private static final KeyBinding keyRingOfLokiSaveSchematic= new KeyBinding("botaniamisc.ringOfLokiSaveSchematic", 0, "botaniamisc.keyCategory"); + private static final KeyBinding keyRingOfLokiOpenUI= new KeyBinding("botaniamisc.ringOfLokiOpenUI", 0, "botaniamisc.keyCategory"); public KeyHandler() { FMLCommonHandler.instance().bus().register(this); ClientRegistry.registerKeyBinding(keyToggleRingOfLoki); ClientRegistry.registerKeyBinding(keyRingOfLokiClear); ClientRegistry.registerKeyBinding(keyRingOfLokiMirror); + ClientRegistry.registerKeyBinding(keyRingOfLokiSaveSchematic); + ClientRegistry.registerKeyBinding(keyRingOfLokiOpenUI); } @SideOnly(Side.CLIENT) @@ -41,16 +53,32 @@ public class KeyHandler { if(keyRingOfLokiMirror.isPressed()){ toggleRingLokiMirroring(); } + if(keyRingOfLokiSaveSchematic.isPressed()){ + ringOfLokiSaveSchematic(); + } + if(keyRingOfLokiOpenUI.isPressed()) { + ringOfLokiOpenUI(); + } } + private static void toggleRingLoki() { PacketHandler.INSTANCE.sendToServer(new PacketLokiToggle()); } - private static void ringOfLokiClear() { PacketHandler.INSTANCE.sendToServer(new PacketLokiClear()); } private static void toggleRingLokiMirroring() { PacketHandler.INSTANCE.sendToServer(new PacketLokiMirror()); } + private static void ringOfLokiSaveSchematic() { + PacketHandler.INSTANCE.sendToServer(new PacketLokiSaveSchematic()); + } + private static void ringOfLokiOpenUI() { + if(ItemLokiRing.isModularUIEnabled) { + ItemStack ring = ItemLokiRing.getLokiRing(Minecraft.getMinecraft().thePlayer); + if(ring != null) + GuiLokiSchematics.open(ring); + } + } } diff --git a/src/main/java/vazkii/botania/client/gui/loki/GuiLokiSchematics.java b/src/main/java/vazkii/botania/client/gui/loki/GuiLokiSchematics.java new file mode 100644 index 000000000..5c09223e4 --- /dev/null +++ b/src/main/java/vazkii/botania/client/gui/loki/GuiLokiSchematics.java @@ -0,0 +1,243 @@ +package vazkii.botania.client.gui.loki; + +import com.cleanroommc.modularui.api.drawable.IKey; +import com.cleanroommc.modularui.api.value.IStringValue; +import com.cleanroommc.modularui.drawable.AdaptableUITexture; +import com.cleanroommc.modularui.drawable.Rectangle; +import com.cleanroommc.modularui.drawable.UITexture; +import com.cleanroommc.modularui.factory.ClientGUI; +import com.cleanroommc.modularui.screen.CustomModularScreen; +import com.cleanroommc.modularui.screen.ModularPanel; +import com.cleanroommc.modularui.screen.RichTooltip; +import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.utils.Alignment; +import com.cleanroommc.modularui.utils.Color; +import com.cleanroommc.modularui.value.sync.InteractionSyncHandler; +import com.cleanroommc.modularui.widget.ParentWidget; +import com.cleanroommc.modularui.widget.ScrollWidget; +import com.cleanroommc.modularui.widget.scroll.VerticalScrollData; +import com.cleanroommc.modularui.widgets.ButtonWidget; +import com.cleanroommc.modularui.widgets.TextWidget; +import com.cleanroommc.modularui.widgets.layout.Row; +import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget; +import cpw.mods.fml.common.Optional; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +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; +import java.util.HashSet; +import java.util.Set; + +public class GuiLokiSchematics extends CustomModularScreen { + + public static void open(ItemStack ring) { + GuiLokiSchematics.itemStack = ring; + ClientGUI.open(new GuiLokiSchematics(ring)); + } + + public static ItemStack itemStack; + + public GuiLokiSchematics(ItemStack itemStack) { + this.itemStack = itemStack; + } + + private static Object selectedSchematic; + + private static Object schematicToBeRenamed; + + private static final int WINDOW_WIDTH = 350, WINDOW_HEIGHT = 225, SCROLL_AREA_WIDTH = 350, SCROLL_AREA_HEIGHT = 200, SAVED_SCHEMATICS_HEADER_HEIGHT = 25, X_PADDING = 5, Y_PADDING = 5; + + @Override + @Optional.Method(modid = "modularui2") + public ModularPanel buildUI(ModularGuiContext context) { + + final UITexture backgroundTexture = AdaptableUITexture + .builder() + .location("botania:textures/gui/croppedPaper") + .imageSize(330, 252) + .adaptable(12) + .build(); + final UITexture checkIcon = UITexture + .builder() + .location("botania:textures/gui/check") + .imageSize(20, 20) + .build(); + final UITexture deleteIcon = UITexture + .builder() + .location("botania:textures/gui/delete") + .imageSize(20, 20) + .build(); + final UITexture renameIcon = UITexture + .builder() + .location("botania:textures/gui/rename") + .imageSize(20, 20) + .build(); + + selectedSchematic = itemStack.getTagCompound().getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC); + + ItemLokiRing ring = (ItemLokiRing) itemStack.getItem(); + ring.schematicNames = Arrays.asList(itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet().stream().sorted(Comparator.comparing(Object::toString)).toArray()); + + Set deleted = new HashSet<>(); + + final ScrollWidget scrollWidget = new ScrollWidget<>(new VerticalScrollData()); + scrollWidget.getScrollArea().getScrollY().setScrollSize(ring.schematicNames.size() * (SCROLL_AREA_HEIGHT / 5 + 1)); + int idx = 0; + for(Object key : itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet()) { + scrollWidget.child( + new Row() + .sizeRel(1f, 0.2f) + .pos(0, ring.schematicNames.indexOf(key) * (SCROLL_AREA_HEIGHT / 5 + 1)) + .padding(5, 0, 5, 5) + .setEnabledIf((w) -> !deleted.contains(key)) + .background(new Rectangle() + .setColor(idx % 2 == 0 ? Color.ORANGE.brighter(3) : Color.ORANGE.brighter(2))) + .child( + new TextWidget(key.toString()) + .widthRel(0.72f)) + .child( + new ParentWidget<>() + .tooltip(new RichTooltip(new TextWidget("Activate Schematic"))) + .widthRel(0.083f) + .heightRel(1f) + .setEnabledIf((w) -> !key.equals(selectedSchematic)) + .child( + new ButtonWidget<>() + .onMousePressed(ignored -> { + PacketHandler.INSTANCE.sendToServer(new PacketLokiChangeSchematic(key.toString())); + selectedSchematic = key; + return true; + }) + .background(checkIcon) + .hoverBackground(checkIcon) + .size(20,20) + .center())) + .child( + new ParentWidget<>() + .widthRel(0.083f) + .heightRel(1f) + .child( + new ButtonWidget<>() + .tooltip(new RichTooltip(new TextWidget("Rename Schematic"))) + .onMousePressed(ignored -> { + this.schematicToBeRenamed = key; + ClientGUI.open(new RenameGui()); + return true; + }) + .background(renameIcon) + .hoverBackground(renameIcon) + .size(20, 20) + .center())) + .child( + new ParentWidget<>() + .widthRel(0.083f) + .heightRel(1f) + .child( + new ButtonWidget<>() + .tooltip(new RichTooltip(new TextWidget("Delete Schematic"))) + .onMousePressed(ignored -> { + PacketHandler.INSTANCE.sendToServer(new PacketLokiDeleteSchematic(key.toString())); + deleted.add(key); + if(key.equals(selectedSchematic)) + selectedSchematic = null; + return true; + }) + .background(deleteIcon) + .hoverBackground(deleteIcon) + .size(20, 20) + .center()))); + idx++; + } + + return ModularPanel.defaultPanel("lokiSchematics") + .child( + new TextWidget(IKey.dynamic(() -> selectedSchematic == null ? StatCollector.translateToLocal("botaniamisc.select_schematic") : StatCollector.translateToLocal("botaniamisc.selected_schematic") + " " + selectedSchematic)) + .align(Alignment.TopCenter) + .marginTop(8) + .scale(0.5f)) + .child( + scrollWidget + .pos(10, 20) + .widthRel(SCROLL_AREA_WIDTH - 20) + .margin(10, 0) + .height(SCROLL_AREA_HEIGHT - 10)) + .background(backgroundTexture) + .size(WINDOW_WIDTH, WINDOW_HEIGHT); + } + + public static class RenameGui extends CustomModularScreen { + + private String newValue = ""; + + @Override + public void close() { + super.close(); + this.persist(); + } + + @Override + public void close(boolean force) { + super.close(force); + this.persist(); + } + + public void persist() { + PacketHandler.INSTANCE.sendToServer(new PacketLokiRenameSchematic(schematicToBeRenamed.toString(), newValue)); + } + + @Override + public ModularPanel buildUI(ModularGuiContext context) { + final UITexture BACKGROUND = AdaptableUITexture.builder() + .location("botania:textures/gui/croppedPaper") + .imageSize(330, 252) + .adaptable(12) + .build(); + + InteractionSyncHandler handler = new InteractionSyncHandler(); + + handler.setOnKeyPressed((key) -> { + System.out.println(key.character); + }); + + return ModularPanel.defaultPanel("rename") + .child(new TextWidget("Schematic Name:") + .pos(10, 10) + .size(180, 20)) + .child(new TextFieldWidget() + .value(new IStringValue() { + @Override + public String getStringValue() { + return newValue; + } + + @Override + public void setStringValue(String val) { + newValue = val; + } + + @Override + public String getValue() { + return newValue; + } + + @Override + public void setValue(String value) { + newValue = value; + } + }) + .disableHoverBackground() + .size(150, 20) + .pos(25, 40)) + .background(BACKGROUND) + .size(200, 100); + } + } +} diff --git a/src/main/java/vazkii/botania/common/item/relic/ItemLokiRing.java b/src/main/java/vazkii/botania/common/item/relic/ItemLokiRing.java index 9665e9c45..28f1d5ba7 100644 --- a/src/main/java/vazkii/botania/common/item/relic/ItemLokiRing.java +++ b/src/main/java/vazkii/botania/common/item/relic/ItemLokiRing.java @@ -11,10 +11,16 @@ package vazkii.botania.common.item.relic; -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; +import baubles.api.BaubleType; +import baubles.common.container.InventoryBaubles; +import baubles.common.lib.PlayerHandler; +import baubles.common.network.PacketSyncBauble; import com.gtnewhorizon.gtnhlib.GTNHLib; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; @@ -27,8 +33,9 @@ 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; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; @@ -52,31 +59,35 @@ import vazkii.botania.common.core.helper.LokiCursor; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.tool.ToolCommons; import vazkii.botania.common.lib.LibItemNames; -import baubles.api.BaubleType; -import baubles.common.container.InventoryBaubles; -import baubles.common.lib.PlayerHandler; -import baubles.common.network.PacketSyncBauble; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import vazkii.botania.common.network.PacketLokiHudNotificationAck; +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeCoordinateListProvider, IManaUsingItem, IInWorldRenderable { - private static final String TAG_CURSOR_LIST = "cursorList"; - private static final String TAG_CURSOR_PREFIX = "cursor"; - private static final String TAG_CURSOR_COUNT = "cursorCount"; - private static final String TAG_X_ORIGIN = "xOrigin"; - private static final String TAG_Y_ORIGIN = "yOrigin"; - private static final String TAG_Z_ORIGIN = "zOrigin"; - private static final String TAG_MODE = "mode"; - private static final String TAG_BREAKING_MODE = "breaking"; - private static final String TAG_MIRROR_MODE = "mirror"; + public static final boolean isModularUIEnabled = Loader.isModLoaded("modularui2"); + + public static final String TAG_CURSOR_LIST = "cursorList"; + public static final String TAG_CURSOR_PREFIX = "cursor"; + public static final String TAG_CURSOR_COUNT = "cursorCount"; + public static final String TAG_X_ORIGIN = "xOrigin"; + public static final String TAG_Y_ORIGIN = "yOrigin"; + public static final String TAG_Z_ORIGIN = "zOrigin"; + public static final String TAG_MODE = "mode"; + public static final String TAG_BREAKING_MODE = "breaking"; + public static final String TAG_MIRROR_MODE = "mirror"; + public static final String TAG_SAVED_SCHEMATICS = "savedSchematics"; + public static final String TAG_CURRENT_SCHEMATIC = "currentSchematic"; private boolean recursion = false; - public static enum HUD_MESSAGE { - MODE, BREAKING, CLEAR, MIRROR, INSUFFICIENT_MANA + public Object window; + + public List schematicNames; + + public enum HUD_MESSAGE { + MODE, BREAKING, CLEAR, MIRROR, INSUFFICIENT_MANA, SCHEMATIC_SAVED } public ItemLokiRing() { @@ -127,23 +138,23 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC syncLokiRing(player); } else { addCursor : { - int relX = lookPos.blockX - originCoords.posX; - int relY = lookPos.blockY - originCoords.posY; - int relZ = lookPos.blockZ - originCoords.posZ; + int relX = lookPos.blockX - originCoords.posX; + int relY = lookPos.blockY - originCoords.posY; + int relZ = lookPos.blockZ - originCoords.posZ; - for(LokiCursor cursor : cursors) - if(cursor.getX() == relX && cursor.getY() == relY && cursor.getZ() == relZ) { - cursors.remove(cursor); - setCursorList(lokiRing, cursors); - if(player instanceof EntityPlayerMP) - syncLokiRing(player); - break addCursor; - } + for(LokiCursor cursor : cursors) + if(cursor.getX() == relX && cursor.getY() == relY && cursor.getZ() == relZ) { + cursors.remove(cursor); + setCursorList(lokiRing, cursors); + if(player instanceof EntityPlayerMP) + syncLokiRing(player); + break addCursor; + } - addCursor(lokiRing, relX, relY, relZ, getRingMirrorMode(lokiRing) ); - if(player instanceof EntityPlayerMP) - syncLokiRing(player); - } + addCursor(lokiRing, relX, relY, relZ, getRingMirrorMode(lokiRing) ); + if(player instanceof EntityPlayerMP) + syncLokiRing(player); + } } } } else if (heldItemStack != null && event.action == Action.RIGHT_CLICK_BLOCK && lookPos != null && isRingEnabled(lokiRing)) { @@ -278,6 +289,84 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC stack.stackTagCompound.setByte(TAG_MIRROR_MODE, state); } + public static void saveCurrentSelectionAsSchematic(ItemStack stack) { + if(!stack.getTagCompound().tagMap.containsKey(TAG_SAVED_SCHEMATICS)) { + stack.getTagCompound().setTag(TAG_SAVED_SCHEMATICS, new NBTTagCompound()); + } + NBTTagCompound map = (NBTTagCompound) stack.getTagCompound().getTag(TAG_SAVED_SCHEMATICS); + NBTTagCompound currentState = new NBTTagCompound(); + for(String s : new String[]{ + TAG_CURSOR_LIST, + TAG_CURSOR_PREFIX, + TAG_CURSOR_COUNT, + TAG_X_ORIGIN, + TAG_Y_ORIGIN, + TAG_Z_ORIGIN, + TAG_BREAKING_MODE, + TAG_MIRROR_MODE + }) { + if(stack.getTagCompound().getTag(s) != null) + currentState.setTag(s, stack.getTagCompound().getTag(s)); + } + String newSchematicName = "New Schematic"; + int idx = 1; + if(map.hasKey(newSchematicName)) { + do { + newSchematicName = "New Schematic (" + idx + ")"; + idx++; + } while (map.hasKey(newSchematicName)); + } + map.setTag(newSchematicName, currentState); + stack.getTagCompound().setTag(TAG_CURRENT_SCHEMATIC, new NBTTagString(newSchematicName)); + } + + public static void changeSchematic(ItemStack stack, String schematicName) { + if(!stack.getTagCompound().tagMap.containsKey(TAG_SAVED_SCHEMATICS)) { + return; + } + NBTTagCompound map = (NBTTagCompound) stack.getTagCompound().getTag(TAG_SAVED_SCHEMATICS); + if(!map.tagMap.containsKey(schematicName)) { + return; + } + NBTTagCompound schematic = (NBTTagCompound) map.getTag(schematicName); + for(String s : new String[]{ + TAG_CURSOR_LIST, + TAG_CURSOR_PREFIX, + TAG_CURSOR_COUNT, + TAG_X_ORIGIN, + TAG_Y_ORIGIN, + TAG_Z_ORIGIN, + TAG_BREAKING_MODE, + TAG_MIRROR_MODE + }) { + if(schematic.getTag(s) != null) { + stack.getTagCompound().setTag(s, schematic.getTag(s)); + } + } + 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); + if(map != null) { + if(map.hasKey(schematicName)) { + map.removeTag(schematicName); + } + } + if(schematicName.equals(lokiStack.getTagCompound().getString(TAG_CURRENT_SCHEMATIC))) { + lokiStack.getTagCompound().removeTag(TAG_CURRENT_SCHEMATIC); + } + } @SideOnly(Side.CLIENT) public static void renderHUDNotification(HUD_MESSAGE type){ @@ -291,7 +380,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC text = getLokiBreakingModeText(getLokiRing(mc.thePlayer)); break; case CLEAR: - text = getLokiCearText(getLokiRing(mc.thePlayer)); + text = getLokiClearText(); break; case MIRROR: text = getLokiMirrorText(getLokiRing(mc.thePlayer)); @@ -299,6 +388,9 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC case INSUFFICIENT_MANA: text = EnumChatFormatting.RED + StatCollector.translateToLocal("botaniamisc.insufficient_mana"); break; + case SCHEMATIC_SAVED: + text = EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.schematic_saved"); + break; default: return; @@ -329,7 +421,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC getAxisString(getRingMirrorMode(stack)); } - public static String getLokiCearText(ItemStack stack){ + public static String getLokiClearText(){ return EnumChatFormatting.GOLD + StatCollector.translateToLocal("botaniamisc.lokiClear"); } @@ -445,7 +537,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC addStringToTooltip(StatCollector.translateToLocal("botaniamisc.lokiMirror") + getAxisString(getRingMirrorMode(stack)), list); addStringToTooltip("", list); addStringToTooltip(StatCollector.translateToLocal("botaniamisc.lokiToggleDescription") + " " + getOnOffString(true) + EnumChatFormatting.RESET + "/"+ getOnOffString(false), list); - addStringToTooltip(StatCollector.translateToLocal("botaniamisc.lokiBreakingDescription") + " " + getOnOffString(true) + EnumChatFormatting.RESET+"/" + getOnOffString(false), list); + addStringToTooltip(StatCollector.translateToLocal("botaniamisc.lokiBreakingDescription") + " " + getOnOffString(true) + EnumChatFormatting.RESET+"/" + getOnOffString(false), list); super.addInformation(stack, player, list, adv); } @@ -516,7 +608,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC baubles.common.network.PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, getLokiRingSlot(player)), (EntityPlayerMP) player); } - private static boolean isLokiRing(ItemStack stack) { + public static boolean isLokiRing(ItemStack stack) { return stack != null && (stack.getItem() == ModItems.lokiRing || stack.getItem() == ModItems.aesirRing); } diff --git a/src/main/java/vazkii/botania/common/network/GuiHandler.java b/src/main/java/vazkii/botania/common/network/GuiHandler.java index 1d08bad85..d292e8c3a 100644 --- a/src/main/java/vazkii/botania/common/network/GuiHandler.java +++ b/src/main/java/vazkii/botania/common/network/GuiHandler.java @@ -45,17 +45,17 @@ public class GuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(ID) { - case LibGuiIDs.LEXICON : - GuiLexicon lex = GuiLexicon.currentOpenLexicon; - return lex; - case LibGuiIDs.CRAFTING_HALO : - return new GuiCraftingHalo(player.inventory, world); - case LibGuiIDs.FLOWER_BAG : - return new GuiFlowerBag(player); - case LibGuiIDs.SHROOM_BAG: - return new GuiShroomBag(player); - case LibGuiIDs.BAUBLE_BOX : - return new GuiBaubleBox(player); + case LibGuiIDs.LEXICON : + GuiLexicon lex = GuiLexicon.currentOpenLexicon; + return lex; + case LibGuiIDs.CRAFTING_HALO : + return new GuiCraftingHalo(player.inventory, world); + case LibGuiIDs.FLOWER_BAG : + return new GuiFlowerBag(player); + case LibGuiIDs.SHROOM_BAG: + return new GuiShroomBag(player); + case LibGuiIDs.BAUBLE_BOX : + return new GuiBaubleBox(player); } return null; diff --git a/src/main/java/vazkii/botania/common/network/PacketHandler.java b/src/main/java/vazkii/botania/common/network/PacketHandler.java index 9352cb8b1..23344a243 100644 --- a/src/main/java/vazkii/botania/common/network/PacketHandler.java +++ b/src/main/java/vazkii/botania/common/network/PacketHandler.java @@ -1,9 +1,9 @@ package vazkii.botania.common.network; -import vazkii.botania.common.lib.LibMisc; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; +import vazkii.botania.common.lib.LibMisc; public class PacketHandler { @@ -16,6 +16,10 @@ public class PacketHandler { INSTANCE.registerMessage(PacketLokiToggle.class, PacketLokiToggle.class, 1, Side.SERVER); INSTANCE.registerMessage(PacketLokiClear.class, PacketLokiClear.class, 2, Side.SERVER); INSTANCE.registerMessage(PacketLokiMirror.class, PacketLokiMirror.class, 3, Side.SERVER); - INSTANCE.registerMessage(PacketLokiHudNotificationAck.class, PacketLokiHudNotificationAck.class, 4, Side.CLIENT); + 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(PacketLokiRenameSchematic.class, PacketLokiRenameSchematic.class, 7, Side.SERVER); + INSTANCE.registerMessage(PacketLokiHudNotificationAck.class, PacketLokiHudNotificationAck.class, 8, Side.CLIENT); } } diff --git a/src/main/java/vazkii/botania/common/network/PacketLokiChangeSchematic.java b/src/main/java/vazkii/botania/common/network/PacketLokiChangeSchematic.java new file mode 100644 index 000000000..b19f0e3d1 --- /dev/null +++ b/src/main/java/vazkii/botania/common/network/PacketLokiChangeSchematic.java @@ -0,0 +1,48 @@ +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 PacketLokiChangeSchematic implements IMessage, IMessageHandler { + + private String schematicName; + + public PacketLokiChangeSchematic() { + } + + public PacketLokiChangeSchematic(String schematicName) { + this.schematicName = schematicName; + } + + @Override + public void fromBytes(ByteBuf buf) { + int schematicNameLength = buf.readInt(); + this.schematicName = new String(buf.readBytes(schematicNameLength).array()); + if(schematicName.equals("null")) { + schematicName = null; + } + } + + @Override + public void toBytes(ByteBuf buf) { + schematicName = schematicName == null ? "null" : schematicName; + buf.writeInt(schematicName.length()); + buf.writeBytes(schematicName.getBytes()); + } + + @Override + public IMessage onMessage(PacketLokiChangeSchematic message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + ItemStack lokiStack = ItemLokiRing.getLokiRing(player); + if(lokiStack != null && lokiStack.getItem() instanceof ItemLokiRing) { + ItemLokiRing.changeSchematic(lokiStack, message.schematicName); + ItemLokiRing.syncLokiRing(player); + } + return null; + } +} diff --git a/src/main/java/vazkii/botania/common/network/PacketLokiDeleteSchematic.java b/src/main/java/vazkii/botania/common/network/PacketLokiDeleteSchematic.java new file mode 100644 index 000000000..864653d81 --- /dev/null +++ b/src/main/java/vazkii/botania/common/network/PacketLokiDeleteSchematic.java @@ -0,0 +1,49 @@ +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 PacketLokiDeleteSchematic implements IMessage, IMessageHandler { + + private String schematicName; + + public PacketLokiDeleteSchematic() { + + } + + public PacketLokiDeleteSchematic(String schematicName) { + this.schematicName = schematicName; + } + + @Override + public void fromBytes(ByteBuf buf) { + int schematicNameLength = buf.readInt(); + this.schematicName = new String(buf.readBytes(schematicNameLength).array()); + if(schematicName.equals("null")) { + schematicName = null; + } + } + + @Override + public void toBytes(ByteBuf buf) { + schematicName = schematicName == null ? "null" : schematicName; + buf.writeInt(schematicName.length()); + buf.writeBytes(schematicName.getBytes()); + } + + @Override + public IMessage onMessage(PacketLokiDeleteSchematic message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + ItemStack lokiStack = ItemLokiRing.getLokiRing(player); + if(lokiStack != null && lokiStack.getItem() instanceof ItemLokiRing) { + ItemLokiRing.deleteSchematic(lokiStack, message.schematicName); + ItemLokiRing.syncLokiRing(player); + } + return null; + } +} diff --git a/src/main/java/vazkii/botania/common/network/PacketLokiRenameSchematic.java b/src/main/java/vazkii/botania/common/network/PacketLokiRenameSchematic.java new file mode 100644 index 000000000..91dac9608 --- /dev/null +++ b/src/main/java/vazkii/botania/common/network/PacketLokiRenameSchematic.java @@ -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 { + + 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; + } +} diff --git a/src/main/java/vazkii/botania/common/network/PacketLokiSaveSchematic.java b/src/main/java/vazkii/botania/common/network/PacketLokiSaveSchematic.java new file mode 100644 index 000000000..6241582da --- /dev/null +++ b/src/main/java/vazkii/botania/common/network/PacketLokiSaveSchematic.java @@ -0,0 +1,33 @@ +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 PacketLokiSaveSchematic implements IMessage, IMessageHandler { + @Override + public void fromBytes(ByteBuf buf) { + + } + + @Override + public void toBytes(ByteBuf buf) { + + } + + @Override + public IMessage onMessage(PacketLokiSaveSchematic message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + final ItemStack aRing = ItemLokiRing.getLokiRing(player); + if (aRing != null) { + ItemLokiRing.saveCurrentSelectionAsSchematic(aRing); + ItemLokiRing.syncLokiRing(player); + PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE.SCHEMATIC_SAVED), player); + } + return null; + } +} diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 5f032b2d9..d4faa1828 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -160,6 +160,8 @@ botaniamisc.keyCategory=Botania #LOKI botaniamisc.toggleLoki=Ring of Loki Switch Key botaniamisc.ringOfLokiClear=Clear Ring of Loki Selection +botaniamisc.ringOfLokiSaveSchematic=Save Ring of Loki Schematic +botaniamisc.ringOfLokiOpenUI=Open Ring of Loki Schematic GUI botaniamisc.lokiOn=On botaniamisc.lokiOff=Off botaniamisc.breaking=Breaking @@ -172,6 +174,12 @@ botaniamisc.lokiCurrent=Current botaniamisc.lokiState=Ring botaniamisc.lokiMirror=Current mirror: botaniamisc.insufficient_mana=Not enough mana! +botaniamisc.schematic_saved=Schematic successfully saved! + +#LOKI UI +botaniamisc.saved_schematics=Saved Schematics +botaniamisc.select_schematic=Select a Schematic! +botaniamisc.selected_schematic=Currently selected schematic: # NEI INTEGRATION botania.nei.brewery=Botanical Brewery diff --git a/src/main/resources/assets/botania/textures/gui/check.png b/src/main/resources/assets/botania/textures/gui/check.png new file mode 100644 index 000000000..5e1216cf8 Binary files /dev/null and b/src/main/resources/assets/botania/textures/gui/check.png differ diff --git a/src/main/resources/assets/botania/textures/gui/croppedPaper.png b/src/main/resources/assets/botania/textures/gui/croppedPaper.png new file mode 100644 index 000000000..21c6f0c7f Binary files /dev/null and b/src/main/resources/assets/botania/textures/gui/croppedPaper.png differ diff --git a/src/main/resources/assets/botania/textures/gui/delete.png b/src/main/resources/assets/botania/textures/gui/delete.png new file mode 100644 index 000000000..c6601c46d Binary files /dev/null and b/src/main/resources/assets/botania/textures/gui/delete.png differ diff --git a/src/main/resources/assets/botania/textures/gui/rename.png b/src/main/resources/assets/botania/textures/gui/rename.png new file mode 100644 index 000000000..3e0991164 Binary files /dev/null and b/src/main/resources/assets/botania/textures/gui/rename.png differ