Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/track move flyblocks #700

Merged
merged 9 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -73,6 +72,8 @@ private StatusUpdateTask(@NotNull Craft craft) {
int nonNegligibleBlocks = 0;
int nonNegligibleSolidBlocks = 0;
double fuel = 0;
final CraftType crafttype = craft.getType();

for (MovecraftLocation l : craft.getHitBox()) {
Material type = craft.getMovecraftWorld().getMaterial(l);
materials.add(type);
Expand All @@ -94,8 +95,30 @@ private StatusUpdateTask(@NotNull Craft craft) {
}
}

Counter<RequiredBlockEntry> flyblocks = new Counter<>();
Counter<RequiredBlockEntry> moveblocks = new Counter<>();
final var flyblocksList = crafttype.getRequiredBlockProperty(CraftType.FLY_BLOCKS);
final var moveblocksList = crafttype.getRequiredBlockProperty(CraftType.MOVE_BLOCKS);
for(Material material : materials.getKeySet()) {
for(RequiredBlockEntry entry : flyblocksList) {
if(entry.contains(material)) {
flyblocks.add(entry, materials.get(material) );
break;
}
}

for(RequiredBlockEntry entry : moveblocksList) {
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,17 @@ 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> flyblocks = craft.getDataTag(Craft.FLYBLOCKS);
Counter<RequiredBlockEntry> moveblocks = craft.getDataTag(Craft.MOVEBLOCKS);
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
Counter<RequiredBlockEntry> displayBlocks = new Counter<>();

displayBlocks.add(flyblocks);
displayBlocks.add(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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public void set(T item, int count) {
counter.put(item, count);
}

public void putIfAbsent(T item, int count) {
counter.putIfAbsent(item, count);
}

TylerS1066 marked this conversation as resolved.
Show resolved Hide resolved
public void add(T item, int count) {
counter.put(item, counter.getInt(item) + count);
}
Expand Down