Skip to content

Commit

Permalink
Reworked jigsaw structure piece detection
Browse files Browse the repository at this point in the history
This is used for village detection and is now a datapack.
Probably breaks everything. On the over hand, other mods or server admins can add custom datapacks to customize.
  • Loading branch information
tyra314 committed Jan 7, 2023
1 parent 651fe84 commit a987106
Show file tree
Hide file tree
Showing 432 changed files with 2,566 additions and 160 deletions.
96 changes: 50 additions & 46 deletions common/src/main/java/hunternif/mc/impl/atlas/AntiqueAtlasMod.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package hunternif.mc.impl.atlas;

import dev.architectury.event.events.common.LifecycleEvent;
import hunternif.mc.impl.atlas.core.TileDataHandler;
import hunternif.mc.impl.atlas.core.scaning.TileDetectorBase;
import dev.architectury.registry.ReloadListenerRegistry;
import hunternif.mc.impl.atlas.core.AtlasIdData;
import hunternif.mc.impl.atlas.core.GlobalTileDataHandler;
import hunternif.mc.impl.atlas.core.PlayerEventHandler;
import hunternif.mc.impl.atlas.core.TileDataHandler;
import hunternif.mc.impl.atlas.core.scaning.TileDetectorBase;
import hunternif.mc.impl.atlas.core.scaning.WorldScanner;
import hunternif.mc.impl.atlas.event.RecipeCraftedCallback;
import hunternif.mc.impl.atlas.event.RecipeCraftedHandler;
import hunternif.mc.impl.atlas.core.GlobalTileDataHandler;
import hunternif.mc.impl.atlas.item.AntiqueAtlasItems;
import hunternif.mc.impl.atlas.marker.GlobalMarkersDataHandler;
import hunternif.mc.impl.atlas.marker.MarkersDataHandler;
Expand All @@ -18,70 +19,73 @@
import hunternif.mc.impl.atlas.structure.*;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.minecraft.resource.ResourceType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AntiqueAtlasMod {
public static final String ID = "antiqueatlas";
public static final String NAME = "Antique Atlas";
public class AntiqueAtlasMod {
public static final String ID = "antiqueatlas";
public static final String NAME = "Antique Atlas";

public static Logger LOG = LogManager.getLogger(NAME);

public static Logger LOG = LogManager.getLogger(NAME);
public static final WorldScanner worldScanner = new WorldScanner();
public static final TileDataHandler tileData = new TileDataHandler();
public static final MarkersDataHandler markersData = new MarkersDataHandler();

public static final WorldScanner worldScanner = new WorldScanner();
public static final TileDataHandler tileData = new TileDataHandler();
public static final MarkersDataHandler markersData = new MarkersDataHandler();
public static final GlobalTileDataHandler globalTileData = new GlobalTileDataHandler();
public static final GlobalMarkersDataHandler globalMarkersData = new GlobalMarkersDataHandler();

public static final GlobalTileDataHandler globalTileData = new GlobalTileDataHandler();
public static final GlobalMarkersDataHandler globalMarkersData = new GlobalMarkersDataHandler();
public static AntiqueAtlasConfig CONFIG = new AntiqueAtlasConfig();

public static AntiqueAtlasConfig CONFIG = new AntiqueAtlasConfig();
public static Identifier id(String... path) {
return path[0].contains(":") ? new Identifier(String.join(".", path)) : new Identifier(ID, String.join(".", path));
}

public static Identifier id(String... path) {
return path[0].contains(":") ? new Identifier(String.join(".", path)) : new Identifier(ID, String.join(".", path));
}
public static AtlasIdData getAtlasIdData(World world) {
if (world.isClient()) {
LOG.warn("Tried to access server only data from client.");
return null;
}

public static AtlasIdData getAtlasIdData(World world) {
if (world.isClient()) {
LOG.warn("Tried to access server only data from client.");
return null;
}
return ((ServerWorld) world).getPersistentStateManager().getOrCreate(AtlasIdData::fromNbt, AtlasIdData::new, "antiqueatlas:global_atlas_data");
}

return ((ServerWorld) world).getPersistentStateManager().getOrCreate(AtlasIdData::fromNbt, AtlasIdData::new, "antiqueatlas:global_atlas_data");
}
public static void init() {
TileDetectorBase.scanBiomeTypes();

public static void init() {
TileDetectorBase.scanBiomeTypes();
AutoConfig.register(AntiqueAtlasConfig.class, JanksonConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(AntiqueAtlasConfig.class).getConfig();

AutoConfig.register(AntiqueAtlasConfig.class, JanksonConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(AntiqueAtlasConfig.class).getConfig();
AntiqueAtlasItems.register();

AntiqueAtlasItems.register();
AntiqueAtlasNetworking.registerC2SListeners();

AntiqueAtlasNetworking.registerC2SListeners();
NewServerConnectionCallback.EVENT.register(tileData::onClientConnectedToServer);
NewServerConnectionCallback.EVENT.register(markersData::onClientConnectedToServer);
NewServerConnectionCallback.EVENT.register(globalMarkersData::onClientConnectedToServer);

NewServerConnectionCallback.EVENT.register(tileData::onClientConnectedToServer);
NewServerConnectionCallback.EVENT.register(markersData::onClientConnectedToServer);
NewServerConnectionCallback.EVENT.register(globalMarkersData::onClientConnectedToServer);
NewPlayerConnectionCallback.EVENT.register(globalMarkersData::onPlayerLogin);
NewPlayerConnectionCallback.EVENT.register(globalTileData::onPlayerLogin);
NewPlayerConnectionCallback.EVENT.register(PlayerEventHandler::onPlayerLogin);

NewPlayerConnectionCallback.EVENT.register(globalMarkersData::onPlayerLogin);
NewPlayerConnectionCallback.EVENT.register(globalTileData::onPlayerLogin);
NewPlayerConnectionCallback.EVENT.register(PlayerEventHandler::onPlayerLogin);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalMarkersData::onWorldLoad);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalTileData::onWorldLoad);

LifecycleEvent.SERVER_LEVEL_LOAD.register(globalMarkersData::onWorldLoad);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalTileData::onWorldLoad);
RecipeCraftedCallback.EVENT.register(new RecipeCraftedHandler());

RecipeCraftedCallback.EVENT.register(new RecipeCraftedHandler());
StructurePieceAddedCallback.EVENT.register(StructureHandler::resolve);
StructureAddedCallback.EVENT.register(StructureHandler::resolve);

StructurePieceAddedCallback.EVENT.register(StructureHandler::resolve);
StructureAddedCallback.EVENT.register(StructureHandler::resolve);
NetherFortress.registerPieces();
EndCity.registerMarkers();
Village.registerMarkers();
Overworld.registerPieces();

NetherFortress.registerPieces();
EndCity.registerMarkers();
Village.registerMarkers();
Village.registerPieces();
Overworld.registerPieces();
}
JigsawConfig jigsawConfig = new JigsawConfig();
ReloadListenerRegistry.register(ResourceType.SERVER_DATA, jigsawConfig, jigsawConfig.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@
@Environment(EnvType.CLIENT)
public class AntiqueAtlasModClient {

private static GuiAtlas guiAtlas;

public static GuiAtlas getAtlasGUI() {
if (guiAtlas == null) {
guiAtlas = new GuiAtlas();
guiAtlas.setMapScale(AntiqueAtlasMod.CONFIG.defaultScale);
}
return guiAtlas;
}

public static void openAtlasGUI(ItemStack stack) {
openAtlasGUI(getAtlasGUI().prepareToOpen(stack));
}

public static void openAtlasGUI() {
openAtlasGUI(getAtlasGUI().prepareToOpen());
}

private static void openAtlasGUI(GuiAtlas gui) {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc.currentScreen == null) { // In-game screen
guiAtlas.updateL18n();
mc.setScreen(gui);
}
}

public static void init() {
ClientProxy clientProxy = new ClientProxy();
clientProxy.initClient();

AntiqueAtlasNetworking.registerS2CListeners();
}
private static GuiAtlas guiAtlas;

public static GuiAtlas getAtlasGUI() {
if (guiAtlas == null) {
guiAtlas = new GuiAtlas();
guiAtlas.setMapScale(AntiqueAtlasMod.CONFIG.defaultScale);
}
return guiAtlas;
}

public static void openAtlasGUI(ItemStack stack) {
openAtlasGUI(getAtlasGUI().prepareToOpen(stack));
}

public static void openAtlasGUI() {
openAtlasGUI(getAtlasGUI().prepareToOpen());
}

private static void openAtlasGUI(GuiAtlas gui) {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc.currentScreen == null) { // In-game screen
guiAtlas.updateL18n();
mc.setScreen(gui);
}
}

public static void init() {
ClientProxy clientProxy = new ClientProxy();
clientProxy.initClient();

AntiqueAtlasNetworking.registerS2CListeners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.client.texture.ITexture;
import hunternif.mc.impl.atlas.client.texture.TileTexture;
import hunternif.mc.impl.atlas.resource.ResourceReloadListener;
import hunternif.mc.impl.atlas.util.Log;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -27,7 +28,7 @@
* - The logical identifier modid:tex referenced by TextureSets
*/
@Environment(EnvType.CLIENT)
public class TextureConfig implements IResourceReloadListener<Map<Identifier, ITexture>> {
public class TextureConfig implements ResourceReloadListener<Map<Identifier, ITexture>> {
public static final Identifier ID = AntiqueAtlasMod.id("textures");
private final Map<Identifier, ITexture> texture_map;

Expand Down Expand Up @@ -72,11 +73,6 @@ public CompletableFuture<Void> apply(Map<Identifier, ITexture> textures, Resourc
}, executor);
}

@Override
public String getName() {
return ID.toString();
}

@Override
public Identifier getId() {
return ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.resource.ResourceReloadListener;
import hunternif.mc.impl.atlas.util.Log;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -23,7 +24,7 @@
* Saves texture set names with the lists of texture variations.
*/
@Environment(EnvType.CLIENT)
public class TextureSetConfig implements IResourceReloadListener<Collection<TextureSet>> {
public class TextureSetConfig implements ResourceReloadListener<Collection<TextureSet>> {
public static final Identifier ID = AntiqueAtlasMod.id("texture_sets");
private static final int VERSION = 1;
private static final JsonParser PARSER = new JsonParser();
Expand Down Expand Up @@ -128,8 +129,7 @@ public CompletableFuture<Void> apply(Collection<TextureSet> sets, ResourceManage
textureSetMap.register(set);
if (AntiqueAtlasMod.CONFIG.resourcePackLogging)
Log.info("Loaded texture set %s with %d custom texture(s)", set.name, set.getTexturePaths().length);
}
catch (Throwable e) {
} catch (Throwable e) {
Log.error(e, "Failed to load the texture set `%s`:", set.name);
}

Expand All @@ -148,11 +148,6 @@ public CompletableFuture<Void> apply(Collection<TextureSet> sets, ResourceManage
}, executor);
}

@Override
public String getName() {
return ID.toString();
}

@Override
public Identifier getId() {
return ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import hunternif.mc.impl.atlas.AntiqueAtlasConfig;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.core.scaning.TileHeightType;
import hunternif.mc.impl.atlas.resource.ResourceReloadListener;
import hunternif.mc.impl.atlas.util.Log;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -29,7 +29,7 @@
* @author Hunternif
*/
@Environment(EnvType.CLIENT)
public class TileTextureConfig implements IResourceReloadListener<Map<Identifier, Identifier>> {
public class TileTextureConfig implements ResourceReloadListener<Map<Identifier, Identifier>> {
public static final Identifier ID = AntiqueAtlasMod.id("tile_textures");
private final TileTextureMap tileTextureMap;
private final TextureSetMap textureSetMap;
Expand Down Expand Up @@ -119,12 +119,7 @@ public CompletableFuture<Void> apply(Map<Identifier, Identifier> tileMap, Resour
}
}, executor);
}

@Override
public String getName() {
return ID.toString();
}


@Override
public Identifier getId() {
return ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.client.IResourceReloadListener;
import hunternif.mc.impl.atlas.resource.ResourceReloadListener;
import hunternif.mc.impl.atlas.registry.MarkerType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -27,7 +27,7 @@
* @author Hunternif
*/
@Environment(EnvType.CLIENT)
public class MarkerTextureConfig implements IResourceReloadListener<Map<Identifier, MarkerType>> {
public class MarkerTextureConfig implements ResourceReloadListener<Map<Identifier, MarkerType>> {
public static final Identifier ID = AntiqueAtlasMod.id("markers");
private static final int VERSION = 1;
private static final JsonParser parser = new JsonParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hunternif.mc.impl.atlas.client;
package hunternif.mc.impl.atlas.resource;

import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
Expand All @@ -9,8 +9,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

public interface IResourceReloadListener<T> extends ResourceReloader
{
public interface ResourceReloadListener<T> extends ResourceReloader {

CompletableFuture<T> load(ResourceManager manager, Profiler profiler, Executor executor);

Expand All @@ -25,14 +24,17 @@ default CompletableFuture<Void> reload(ResourceReloader.Synchronizer synchronize
Profiler prepareProfiler,
Profiler applyProfiler,
Executor prepareExecutor,
Executor applyExecutor)
{
Executor applyExecutor) {
CompletableFuture<T> load = load(manager, prepareProfiler, prepareExecutor);

return load.thenCompose(synchronizer::whenPrepared)
.thenCompose(t -> apply(t, manager, applyProfiler, applyExecutor));
}

default String getName() {
return getId().toString();
}

Identifier getId();

Collection<Identifier> getDependencies();
Expand Down
Loading

0 comments on commit a987106

Please sign in to comment.