Skip to content

Commit

Permalink
Feature/track move flyblocks (#700)
Browse files Browse the repository at this point in the history
* Tracking Moveblocks and Flyblocks

* Better save these in a variable

* Moving this out

* Changed var type to Counter<RequiredBlockEntry>

* Use new logic to StatusSign

* Move down variables

* Use Counter instead

* No region comments

* Clean up
  • Loading branch information
Intybyte authored Aug 25, 2024
1 parent 9ddedc7 commit 71e87b2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,11 +67,12 @@ private StatusUpdateTask(@NotNull Craft craft) {
}

@Override
public @Nullable Effect get() {
public @NotNull Effect get() {
Counter<Material> 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);
Expand All @@ -94,8 +94,28 @@ private StatusUpdateTask(@NotNull Craft craft) {
}
}

Counter<RequiredBlockEntry> flyblocks = new Counter<>();
Counter<RequiredBlockEntry> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -82,28 +69,14 @@ public final void onSignTranslate(SignTranslateEvent event) {
totalNonNegligibleWaterBlocks += add;
}
}
Object2IntMap<RequiredBlockEntry> 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<RequiredBlockEntry> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +47,8 @@ public interface Craft {
CraftDataTagKey<List<Craft>> CONTACTS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "contacts"), craft -> new ArrayList<>(0));
CraftDataTagKey<Double> FUEL = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "fuel"), craft -> 0D);
CraftDataTagKey<Counter<Material>> MATERIALS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "materials"), craft -> new Counter<>());
CraftDataTagKey<Counter<RequiredBlockEntry>> FLYBLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "flyblocks"), craft -> new Counter<>());
CraftDataTagKey<Counter<RequiredBlockEntry>> MOVEBLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "moveblocks"), craft -> new Counter<>());
CraftDataTagKey<Integer> NON_NEGLIGIBLE_BLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "non-negligible-blocks"), Craft::getOrigBlockCount);
CraftDataTagKey<Integer> NON_NEGLIGIBLE_SOLID_BLOCKS = CraftDataTagRegistry.INSTANCE.registerTagKey(new NamespacedKey("movecraft", "non-negligible-solid-blocks"), Craft::getOrigBlockCount);

Expand Down

0 comments on commit 71e87b2

Please sign in to comment.