From 71e87b2b73fea8d942a3a82e569f7391e6a87685 Mon Sep 17 00:00:00 2001 From: Vaan1310 <61906290+Intybyte@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:46:58 +0200 Subject: [PATCH] Feature/track move flyblocks (#700) * Tracking Moveblocks and Flyblocks * Better save these in a variable * Moving this out * Changed var type to Counter * Use new logic to StatusSign * Move down variables * Use Counter instead * No region comments * Clean up --- .../features/status/StatusManager.java | 24 +++++++++++- .../movecraft/features/status/StatusSign.java | 39 +++---------------- .../countercraft/movecraft/craft/Craft.java | 4 +- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusManager.java b/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusManager.java index ed48e75d4..761acd77b 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusManager.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusManager.java @@ -5,7 +5,6 @@ import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.craft.CraftManager; import net.countercraft.movecraft.craft.SinkingCraft; -import net.countercraft.movecraft.craft.datatag.CraftDataTagContainer; import net.countercraft.movecraft.craft.datatag.CraftDataTagKey; import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry; import net.countercraft.movecraft.craft.type.CraftType; @@ -68,11 +67,12 @@ private StatusUpdateTask(@NotNull Craft craft) { } @Override - public @Nullable Effect get() { + public @NotNull Effect get() { Counter materials = new Counter<>(); int nonNegligibleBlocks = 0; int nonNegligibleSolidBlocks = 0; double fuel = 0; + for (MovecraftLocation l : craft.getHitBox()) { Material type = craft.getMovecraftWorld().getMaterial(l); materials.add(type); @@ -94,8 +94,28 @@ private StatusUpdateTask(@NotNull Craft craft) { } } + Counter flyblocks = new Counter<>(); + Counter moveblocks = new Counter<>(); + for(Material material : materials.getKeySet()) { + for(RequiredBlockEntry entry : craft.getType().getRequiredBlockProperty(CraftType.FLY_BLOCKS)) { + if(entry.contains(material)) { + flyblocks.add(entry, materials.get(material) ); + break; + } + } + + for(RequiredBlockEntry entry : craft.getType().getRequiredBlockProperty(CraftType.MOVE_BLOCKS)) { + if(entry.contains(material)) { + moveblocks.add(entry, materials.get(material) ); + break; + } + } + } + craft.setDataTag(Craft.FUEL, fuel); craft.setDataTag(Craft.MATERIALS, materials); + craft.setDataTag(Craft.FLYBLOCKS, flyblocks); + craft.setDataTag(Craft.MOVEBLOCKS, moveblocks); craft.setDataTag(Craft.NON_NEGLIGIBLE_BLOCKS, nonNegligibleBlocks); craft.setDataTag(Craft.NON_NEGLIGIBLE_SOLID_BLOCKS, nonNegligibleSolidBlocks); craft.setDataTag(LAST_STATUS_CHECK, System.currentTimeMillis()); diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusSign.java b/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusSign.java index 1246c1381..d8a488576 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusSign.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/features/status/StatusSign.java @@ -1,16 +1,11 @@ package net.countercraft.movecraft.features.status; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.craft.BaseCraft; import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.craft.type.CraftType; import net.countercraft.movecraft.craft.type.RequiredBlockEntry; import net.countercraft.movecraft.events.CraftDetectEvent; import net.countercraft.movecraft.events.SignTranslateEvent; -import net.countercraft.movecraft.features.status.StatusManager; import net.countercraft.movecraft.util.Counter; import net.countercraft.movecraft.util.Tags; import org.bukkit.ChatColor; @@ -25,16 +20,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; - public final class StatusSign implements Listener { @EventHandler @@ -82,28 +69,14 @@ public final void onSignTranslate(SignTranslateEvent event) { totalNonNegligibleWaterBlocks += add; } } - Object2IntMap displayBlocks = new Object2IntOpenHashMap<>(); - for (RequiredBlockEntry entry : craft.getType().getRequiredBlockProperty(CraftType.FLY_BLOCKS)) { - int total = 0; - for (Material material : entry.getMaterials()) { - if (materials.getKeySet().contains(material)) { - total += materials.get(material); - } - } - displayBlocks.putIfAbsent(entry, total); - } - for (RequiredBlockEntry entry : craft.getType().getRequiredBlockProperty(CraftType.MOVE_BLOCKS)) { - int total = 0; - for (Material material : entry.getMaterials()) { - if (materials.getKeySet().contains(material)) { - total += materials.get(material); - } - } - displayBlocks.putIfAbsent(entry, total); - } + + Counter displayBlocks = new Counter<>(); + displayBlocks.add(craft.getDataTag(Craft.FLYBLOCKS)); + displayBlocks.add(craft.getDataTag(Craft.MOVEBLOCKS)); + int signLine = 1; int signColumn = 0; - for (RequiredBlockEntry entry : displayBlocks.keySet()) { + for (RequiredBlockEntry entry : displayBlocks.getKeySet()) { if (entry.getMin() == 0.0) { continue; } diff --git a/api/src/main/java/net/countercraft/movecraft/craft/Craft.java b/api/src/main/java/net/countercraft/movecraft/craft/Craft.java index 2c13ad657..a1a44ee69 100644 --- a/api/src/main/java/net/countercraft/movecraft/craft/Craft.java +++ b/api/src/main/java/net/countercraft/movecraft/craft/Craft.java @@ -21,10 +21,10 @@ import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; import net.countercraft.movecraft.TrackedLocation; -import net.countercraft.movecraft.craft.datatag.CraftDataTagContainer; import net.countercraft.movecraft.craft.datatag.CraftDataTagKey; import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry; import net.countercraft.movecraft.craft.type.CraftType; +import net.countercraft.movecraft.craft.type.RequiredBlockEntry; import net.countercraft.movecraft.processing.MovecraftWorld; import net.countercraft.movecraft.util.Counter; import net.countercraft.movecraft.util.MathUtils; @@ -47,6 +47,8 @@ public interface Craft { CraftDataTagKey> CONTACTS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "contacts"), craft -> new ArrayList<>(0)); CraftDataTagKey FUEL = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "fuel"), craft -> 0D); CraftDataTagKey> MATERIALS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "materials"), craft -> new Counter<>()); + CraftDataTagKey> FLYBLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "flyblocks"), craft -> new Counter<>()); + CraftDataTagKey> MOVEBLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "moveblocks"), craft -> new Counter<>()); CraftDataTagKey NON_NEGLIGIBLE_BLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "non-negligible-blocks"), Craft::getOrigBlockCount); CraftDataTagKey NON_NEGLIGIBLE_SOLID_BLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "non-negligible-solid-blocks"), Craft::getOrigBlockCount);