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 5 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 @@ -50,10 +49,12 @@ public void run() {

private static final class StatusUpdateTask implements Supplier<Effect> {
private final Craft craft;
private final CraftType crafttype;
private final Map<Material, Double> fuelTypes;

private StatusUpdateTask(@NotNull Craft craft) {
this.craft = craft;
this.crafttype = craft.getType();

Object object = craft.getType().getObjectProperty(CraftType.FUEL_TYPES);
if(!(object instanceof Map<?, ?> map))
Expand All @@ -70,9 +71,13 @@ private StatusUpdateTask(@NotNull Craft craft) {
@Override
public @Nullable Effect get() {
Counter<Material> materials = new Counter<>();
Counter<RequiredBlockEntry> flyblocks = new Counter<>();
Counter<RequiredBlockEntry> moveblocks = new Counter<>();
int nonNegligibleBlocks = 0;
int nonNegligibleSolidBlocks = 0;
double fuel = 0;
final var flyblocksList = crafttype.getRequiredBlockProperty(CraftType.FLY_BLOCKS);
final var moveblocksList = crafttype.getRequiredBlockProperty(CraftType.MOVE_BLOCKS);
for (MovecraftLocation l : craft.getHitBox()) {
Material type = craft.getMovecraftWorld().getMaterial(l);
materials.add(type);
Expand All @@ -94,8 +99,26 @@ private StatusUpdateTask(@NotNull Craft craft) {
}
}

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
Expand Up @@ -2,15 +2,12 @@

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 +22,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,25 +71,21 @@ public final void onSignTranslate(SignTranslateEvent event) {
totalNonNegligibleWaterBlocks += add;
}
}
//region Add flyblocks and moveblocks to displayBlocks
Counter<RequiredBlockEntry> flyblocks = craft.getDataTag(Craft.FLYBLOCKS);
Counter<RequiredBlockEntry> moveblocks = craft.getDataTag(Craft.MOVEBLOCKS);
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);
}
}

for (RequiredBlockEntry entry : flyblocks.getKeySet()) {
int total = flyblocks.get(entry);
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);
}
}

for (RequiredBlockEntry entry : moveblocks.getKeySet()) {
int total = flyblocks.get(entry);
displayBlocks.putIfAbsent(entry, total);
}
//endregion
int signLine = 1;
int signColumn = 0;
for (RequiredBlockEntry entry : displayBlocks.keySet()) {
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