From 12dc3ee398365f5f5da10cbea7cbdce3b0371102 Mon Sep 17 00:00:00 2001 From: Eccentric Devotion Date: Thu, 7 Dec 2023 17:42:36 +1300 Subject: [PATCH] Use the first non-air block of the shell as the GUI icon --- .../java/me/eccentric_nz/TARDIS/TARDIS.java | 4 +++ .../shell/TARDISPlayerShellListener.java | 2 +- .../chameleon/shell/TARDISShellInventory.java | 35 ++++++++++++++++--- .../TARDIS/control/TARDISControlListener.java | 15 +++----- .../custommodeldata/GUIChameleonPresets.java | 1 + 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/eccentric_nz/TARDIS/TARDIS.java b/src/main/java/me/eccentric_nz/TARDIS/TARDIS.java index 6acdadc10..edff94f6f 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/TARDIS.java +++ b/src/main/java/me/eccentric_nz/TARDIS/TARDIS.java @@ -489,6 +489,10 @@ public void onEnable() { new TARDISWallSignConverter(this).convertSignBlocks(); getConfig().set("conversions.block_wall_signs", true); } + if (!getConfig().getBoolean("conversions.short_grass")) { + new TARDISGrassConverter(this).checkBlockData(); + getConfig().set("conversions.short_grass", true); + } TARDISBlockLoader bl = new TARDISBlockLoader(this); bl.loadGravityWells(); bl.loadProtectedBlocks(); diff --git a/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISPlayerShellListener.java b/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISPlayerShellListener.java index cbcf75dad..3f976e75b 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISPlayerShellListener.java +++ b/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISPlayerShellListener.java @@ -246,7 +246,7 @@ private int getChameleonId(InventoryView view, int slot) { ItemStack shell = view.getItem(slot); ItemMeta im = shell.getItemMeta(); PersistentDataContainer pdc = im.getPersistentDataContainer(); - if (!pdc.has(plugin.getCustomBlockKey())) { + if (!pdc.has(plugin.getCustomBlockKey(), PersistentDataType.INTEGER)) { return -1; } return pdc.get(plugin.getCustomBlockKey(), PersistentDataType.INTEGER); diff --git a/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISShellInventory.java b/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISShellInventory.java index 03db7ce8d..a000799a1 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISShellInventory.java +++ b/src/main/java/me/eccentric_nz/TARDIS/chameleon/shell/TARDISShellInventory.java @@ -16,12 +16,15 @@ */ package me.eccentric_nz.TARDIS.chameleon.shell; +import com.google.gson.JsonArray; +import com.google.gson.JsonParser; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.custommodeldata.GUIChameleonPresets; import me.eccentric_nz.TARDIS.database.resultset.ResultSetShells; import me.eccentric_nz.TARDIS.utility.TARDISNumberParsers; import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; +import org.bukkit.block.data.BlockData; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; @@ -69,7 +72,27 @@ private ItemStack[] getItemStack() { int i = 0; ArrayList> data = rss.getData(); for (HashMap map : data) { - ItemStack saved = new ItemStack(Material.BOWL, 1); + // get the first non-air block of the shell + Material material = null; + String blueprint = map.get("blueprintData"); + JsonArray json = JsonParser.parseString(blueprint).getAsJsonArray(); + outer: + for (int k = 0; k < 10; k++) { + JsonArray inner = json.get(k).getAsJsonArray(); + for (int j = 0; j < 4; j++) { + String block = inner.get(j).getAsString(); + plugin.debug(block); + if (!block.equals("minecraft:air")) { + BlockData blockData = plugin.getServer().createBlockData(block); + material = blockData.getMaterial(); + break outer; + } + } + } + if (material == null) { + material = Material.BOWL; + } + ItemStack saved = new ItemStack(material, 1); ItemMeta con = saved.getItemMeta(); con.setDisplayName("Saved Construct"); List lore = new ArrayList<>(); @@ -81,7 +104,9 @@ private ItemStack[] getItemStack() { lore.add(ChatColor.AQUA + "Active shell"); } con.setLore(lore); - con.setCustomModelData(GUIChameleonPresets.SAVED.getCustomModelData()); + if (material == Material.BOWL) { + con.setCustomModelData(GUIChameleonPresets.SAVED.getCustomModelData()); + } con.getPersistentDataContainer().set(plugin.getCustomBlockKey(), PersistentDataType.INTEGER, TARDISNumberParsers.parseInt(map.get("chameleon_id"))); saved.setItemMeta(con); stacks[i] = saved; @@ -96,6 +121,7 @@ private ItemStack[] getItemStack() { ItemStack use = new ItemStack(Material.BOWL, 1); ItemMeta uim = use.getItemMeta(); uim.setDisplayName("Use selected shell"); + uim.setLore(List.of("Will apply shell to", "the Chameleon Circuit", "and rebuild the exterior.")); uim.setCustomModelData(GUIChameleonPresets.USE_SELECTED.getCustomModelData()); use.setItemMeta(uim); stacks[45] = use; @@ -107,7 +133,7 @@ private ItemStack[] getItemStack() { delete.setItemMeta(dim); stacks[46] = delete; // update selected shell - ItemStack update = new ItemStack(Material.BUCKET, 1); + ItemStack update = new ItemStack(Material.BOWL, 1); ItemMeta upim = update.getItemMeta(); upim.setDisplayName("Update selected shell"); upim.setCustomModelData(GUIChameleonPresets.UPDATE_SELECTED.getCustomModelData()); @@ -125,7 +151,8 @@ private ItemStack[] getItemStack() { ItemStack save = new ItemStack(Material.BOWL, 1); ItemMeta pre = save.getItemMeta(); pre.setDisplayName("Save Chameleon shell"); - pre.setCustomModelData(GUIChameleonPresets.CURRENT.getCustomModelData()); + ns.setLore(List.of("Will save shell and", "rebuild the exterior.")); + pre.setCustomModelData(GUIChameleonPresets.SAVE.getCustomModelData()); save.setItemMeta(pre); stacks[50] = save; // Cancel / close diff --git a/src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlListener.java b/src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlListener.java index 97e6ffa10..a9e203452 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlListener.java +++ b/src/main/java/me/eccentric_nz/TARDIS/control/TARDISControlListener.java @@ -157,8 +157,7 @@ public void onControlInteract(PlayerInteractEvent event) { if (action == Action.RIGHT_CLICK_BLOCK) { switch (type) { // random location button - case 1 -> - new RandomAction(plugin).process(cooldown, player, id, tardis, rsc.getSecondary()); + case 1 -> new RandomAction(plugin).process(cooldown, player, id, tardis, rsc.getSecondary()); // console repeaters case 2, 3, 4, 5 -> new RepeaterAction(plugin).announce(player, block, type); // fast return button @@ -170,8 +169,7 @@ public void onControlInteract(PlayerInteractEvent event) { // Temporal Locator sign case 11 -> new TemporarlLocatorAction(plugin).openGUI(player, tcc); // Control room light switch - case 12 -> - new LightSwitchAction(plugin, id, lights, player, tardis.getSchematic().getLights()).flickSwitch(); + case 12 -> new LightSwitchAction(plugin, id, lights, player, tardis.getSchematic().getLights()).flickSwitch(); // TIS case 13 -> new TARDISInfoMenuButton(plugin, player).clickButton(); // Disk Storage @@ -196,8 +194,7 @@ public void onControlInteract(PlayerInteractEvent event) { new CustardCreamAction(plugin, player, block, id).dispense(); } // force field - case 29 -> - new ForceFieldAction(plugin).toggleSheilds(player, blockLocation, tardis.getArtron_level()); + case 29 -> new ForceFieldAction(plugin).toggleSheilds(player, blockLocation, tardis.getArtron_level()); // flight mode button case 30 -> new FlightModeAction(plugin).setMode(ownerUUID.toString(), player); // chameleon sign @@ -211,8 +208,7 @@ public void onControlInteract(PlayerInteractEvent event) { } } // scanner - case 33 -> - new TARDISScanner(plugin).scan(player, id, tardis.getRenderer(), tardis.getArtron_level()); + case 33 -> new TARDISScanner(plugin).scan(player, id, tardis.getRenderer(), tardis.getArtron_level()); // cloister bell case 35 -> new CloisterBellAction(plugin).ring(id, tardis); // weather menu @@ -227,8 +223,7 @@ public void onControlInteract(PlayerInteractEvent event) { // zero room entry case 16 -> new ZeroRoomAction(plugin).doEntry(player, tardis, id); // maze exits - case 40, 41, 42, 43 -> - new MazeAction(plugin).reconfigure(type, player, id, blockLocation); + case 40, 41, 42, 43 -> new MazeAction(plugin).reconfigure(type, player, id, blockLocation); default -> { } } diff --git a/src/main/java/me/eccentric_nz/TARDIS/custommodeldata/GUIChameleonPresets.java b/src/main/java/me/eccentric_nz/TARDIS/custommodeldata/GUIChameleonPresets.java index 666249e57..6f629ae75 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/custommodeldata/GUIChameleonPresets.java +++ b/src/main/java/me/eccentric_nz/TARDIS/custommodeldata/GUIChameleonPresets.java @@ -24,6 +24,7 @@ public enum GUIChameleonPresets { // Chameleon Presets GO_TO_PAGE_2(12, 52, Material.ARROW), NEW(151, 49, Material.BOWL), + SAVE(74, 50, Material.BOWL), USE_SELECTED(152, 45, Material.BOWL), UPDATE_SELECTED(153, 45, Material.BOWL), DELETE_SELECTED(1, 46, Material.BUCKET),