simplify survival, map and plugin code: map palette built once in a static initializer instead of a synchronized check per dither lookup, film colour as a constant, one blit for blank film and develop, shared crafting result for prepare and craft, unused photo scan state and dead null checks removed, non-italic text helper for item names, pdc getOrDefault, private map file paths, single map-init attach path, listener registration in one loop, unused image constructor removed (pptest dithers itself), comments trimmed
This commit is contained in:
1 parent
44f2b3c59c
commit
b242adb6d2
13 files changed
+209
-378
No files matched your search
@@ -23,13 +23,15 @@ import eu.mhsl.minecraft.pixelpics.survival.JoinListener;
|
||||
import eu.mhsl.minecraft.pixelpics.survival.SurvivalRecipes;
|
||||
import eu.mhsl.minecraft.pixelpics.utils.MapColorPalette;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
@@ -40,13 +42,10 @@ public final class Main extends JavaPlugin {
|
||||
private DefaultScreenRenderer screenRenderer;
|
||||
private RenderManager renderManager;
|
||||
|
||||
// PDC keys: photo picture id (STRING), camera/film markers (BYTE), loaded film on a camera (INTEGER)
|
||||
public final NamespacedKey pictureIdFlag = new NamespacedKey(this, "imageid");
|
||||
|
||||
/** Marks a {@code PLAYER_HEAD} as a camera (BYTE 1). */
|
||||
public final NamespacedKey cameraMarker = new NamespacedKey(this, "camera");
|
||||
/** Loaded film count stored on a camera (INTEGER, 0..{@code CameraItems.MAX_FILM}). */
|
||||
public final NamespacedKey filmCountKey = new NamespacedKey(this, "filmcount");
|
||||
/** Marks a {@code PLAYER_HEAD} as a film roll (BYTE 1). */
|
||||
public final NamespacedKey filmMarker = new NamespacedKey(this, "film");
|
||||
|
||||
@Override
|
||||
@@ -56,12 +55,11 @@ public final class Main extends JavaPlugin {
|
||||
saveDefaultConfig();
|
||||
initRenderManager();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new OnMapInitialize(), this);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("pixelPic")).setExecutor(new PixelPicsCommand());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new CameraListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
|
||||
Objects.requireNonNull(getCommand("pixelPic")).setExecutor(new PixelPicsCommand());
|
||||
for (Listener listener :
|
||||
List.of(new OnMapInitialize(), new CameraListener(), new CraftingListener(), new JoinListener())) {
|
||||
Bukkit.getPluginManager().registerEvents(listener, this);
|
||||
}
|
||||
SurvivalRecipes.register();
|
||||
|
||||
initRenderer();
|
||||
@@ -114,7 +112,7 @@ public final class Main extends JavaPlugin {
|
||||
// optional newer dump in the data folder (no recompile on MC updates), else the bundled copy.
|
||||
File dump = new File(getDataFolder(), "vanilla_entity_models.json");
|
||||
try (InputStream in =
|
||||
dump.isFile() ? new java.io.FileInputStream(dump) : getResource("cem/vanilla_entity_models.json")) {
|
||||
dump.isFile() ? new FileInputStream(dump) : getResource("cem/vanilla_entity_models.json")) {
|
||||
if (in != null) {
|
||||
long t0 = System.nanoTime();
|
||||
int n = cemLoader.load(in, getLogger());
|
||||
@@ -125,8 +123,8 @@ public final class Main extends JavaPlugin {
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Failed to load vanilla entity models: " + e.getMessage());
|
||||
}
|
||||
List<File> worldFolders = new ArrayList<>();
|
||||
for (org.bukkit.World w : getServer().getWorlds()) worldFolders.add(w.getWorldFolder());
|
||||
List<File> worldFolders =
|
||||
getServer().getWorlds().stream().map(World::getWorldFolder).toList();
|
||||
int datapackVariants = DatapackVariants.load(cemLoader, worldFolders, getLogger());
|
||||
if (datapackVariants > 0) getLogger().info("Loaded " + datapackVariants + " datapack mob variants.");
|
||||
SkinCache skinCache = new SkinCache();
|
||||
@@ -143,7 +141,7 @@ public final class Main extends JavaPlugin {
|
||||
blockEntityBaker,
|
||||
getLogger(),
|
||||
renderManager.tracePool());
|
||||
// Warm the map palette on the main thread so off-thread dithering never triggers its first init.
|
||||
// Initialise the map palette on the main thread (MapPalette) before any off-thread dithering.
|
||||
MapColorPalette.size();
|
||||
getLogger().info("PixelPics renderer initialized with resource pack assets.");
|
||||
}
|
||||
@@ -166,7 +164,6 @@ public final class Main extends JavaPlugin {
|
||||
return this.screenRenderer;
|
||||
}
|
||||
|
||||
/** The render queue/limiter; always available after {@code onEnable}. */
|
||||
public RenderManager getRenderManager() {
|
||||
return this.renderManager;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user