Skip to content

Commit

Permalink
Use the first non-air block of the shell as the GUI icon
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricdevotion committed Dec 7, 2023
1 parent 8e754c9 commit 12dc3ee
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/main/java/me/eccentric_nz/TARDIS/TARDIS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +72,27 @@ private ItemStack[] getItemStack() {
int i = 0;
ArrayList<HashMap<String, String>> data = rss.getData();
for (HashMap<String, String> 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<String> lore = new ArrayList<>();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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());
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 -> {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 12dc3ee

Please sign in to comment.