diff --git a/gradle.properties b/gradle.properties index 30f0021a9..0a8a69549 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,6 +12,6 @@ loader_version=0.14.21 fabric_version=0.83.0+1.20.1 # Mod Properties -mod_version=2.0.4a +mod_version=2.0.4b maven_group=com.greymerk archives_base_name=RoguelikeDungeons \ No newline at end of file diff --git a/src/main/java/com/greymerk/roguelike/Roguelike.java b/src/main/java/com/greymerk/roguelike/Roguelike.java index 4bc3166f8..80fb83efd 100644 --- a/src/main/java/com/greymerk/roguelike/Roguelike.java +++ b/src/main/java/com/greymerk/roguelike/Roguelike.java @@ -33,11 +33,8 @@ public void onInitialize() { ServerWorldEvents.LOAD.register(listener); ServerEntityEvents.ENTITY_LOAD.register(new EntityLoadEvent()); - ServerTickEvents.START_SERVER_TICK.register(new WorldTickGenerate()); + ServerTickEvents.START_WORLD_TICK.register(new WorldTickGenerate()); ServerChunkEvents.CHUNK_LOAD.register(new ChunkLoadRoomFlagEvent()); - //ServerChunkEvents.CHUNK_LOAD.register(new ChunkLoadGenerateDungeon()); - - //ServerTickEvents.START_WORLD_TICK.register(new WorldTickTest()); CommandRegistrationCallback.EVENT.register(RoguelikeCommand.getListener()); } diff --git a/src/main/java/com/greymerk/roguelike/dungeon/DungeonGenerationQueue.java b/src/main/java/com/greymerk/roguelike/dungeon/DungeonGenerationQueue.java deleted file mode 100644 index 0bba83f12..000000000 --- a/src/main/java/com/greymerk/roguelike/dungeon/DungeonGenerationQueue.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.greymerk.roguelike.dungeon; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import net.minecraft.registry.RegistryKey; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; - -public class DungeonGenerationQueue implements Iterable{ - - private static DungeonGenerationQueue instance; - - private Set locations; - - public static DungeonGenerationQueue getInstance() { - if(instance == null) { - instance = new DungeonGenerationQueue(); - } - - return instance; - } - - private DungeonGenerationQueue() { - this.locations = new HashSet(); - } - - public void add(RegistryKey key, ChunkPos cpos) { - this.locations.add(DungeonLocation.of(key, cpos)); - } - - public boolean has(RegistryKey key, ChunkPos cpos) { - DungeonLocation dl = DungeonLocation.of(key, cpos); - return this.locations.contains(dl); - } - - public void remove(DungeonLocation dl) { - this.locations.remove(dl); - } - - @Override - public Iterator iterator() { - return this.locations.iterator(); - } -} diff --git a/src/main/java/com/greymerk/roguelike/dungeon/DungeonLocation.java b/src/main/java/com/greymerk/roguelike/dungeon/DungeonLocation.java deleted file mode 100644 index 8dbcdfab9..000000000 --- a/src/main/java/com/greymerk/roguelike/dungeon/DungeonLocation.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.greymerk.roguelike.dungeon; - -import java.util.Objects; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtInt; -import net.minecraft.nbt.NbtString; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; - -public class DungeonLocation{ - - private RegistryKey worldKey; - private ChunkPos cpos; - - public static DungeonLocation of(RegistryKey worldKey, ChunkPos cpos) { - return new DungeonLocation(worldKey, cpos); - } - - public static DungeonLocation of(NbtCompound data) { - - String namespace = data.getCompound("worldkey").getString("namespace"); - String path = data.getCompound("worldkey").getString("path"); - Identifier id = Identifier.of(namespace, path); - RegistryKey key = RegistryKey.of(RegistryKeys.WORLD, id); - - ChunkPos cpos = new ChunkPos( - data.getCompound("chunkpos").getInt("x"), - data.getCompound("chunkpos").getInt("z")); - - return new DungeonLocation(key, cpos); - } - - private DungeonLocation(RegistryKey worldKey, ChunkPos cpos) { - this.worldKey = worldKey; - this.cpos = cpos; - } - - public RegistryKey getKey(){ - return this.worldKey; - } - - public ChunkPos getChunkPos() { - return this.cpos; - } - - @Override - public int hashCode() { - Identifier id = worldKey.getValue(); - return Objects.hash(cpos, id.hashCode()); - } - - public NbtCompound getNbt() { - NbtCompound data = new NbtCompound(); - Identifier id = this.worldKey.getValue(); - - NbtCompound wk = new NbtCompound(); - wk.put("namespace", NbtString.of(id.getNamespace())); - wk.put("path", NbtString.of(id.getPath())); - data.put("worldkey", wk); - - NbtCompound cp = new NbtCompound(); - cp.put("x", NbtInt.of(cpos.x)); - cp.put("z", NbtInt.of(cpos.z)); - data.put("chunkpos", cp); - - return data; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DungeonLocation other = (DungeonLocation) obj; - return Objects.equals(cpos, other.cpos) && Objects.equals(worldKey, other.worldKey); - } - - @Override - public String toString() { - return this.worldKey.getValue() + " : " + this.cpos; - } - -} diff --git a/src/main/java/com/greymerk/roguelike/editor/WorldEditor.java b/src/main/java/com/greymerk/roguelike/editor/WorldEditor.java index 12c8d9a6b..3ccb496f2 100644 --- a/src/main/java/com/greymerk/roguelike/editor/WorldEditor.java +++ b/src/main/java/com/greymerk/roguelike/editor/WorldEditor.java @@ -163,6 +163,8 @@ public boolean isGround(Coord pos) { tags.add(BlockTags.SAND); tags.add(BlockTags.SNOW); tags.add(BlockTags.STONE_ORE_REPLACEABLES); + tags.add(BlockTags.TERRACOTTA); + tags.add(BlockTags.SHOVEL_MINEABLE); MetaBlock m = getBlock(pos); diff --git a/src/main/java/com/greymerk/roguelike/events/ChunkLoadGenerateDungeon.java b/src/main/java/com/greymerk/roguelike/events/ChunkLoadGenerateDungeon.java deleted file mode 100644 index fe10dc46c..000000000 --- a/src/main/java/com/greymerk/roguelike/events/ChunkLoadGenerateDungeon.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.greymerk.roguelike.events; - -import com.greymerk.roguelike.dungeon.DungeonLocation; -import com.greymerk.roguelike.dungeon.DungeonPlacement; -import com.greymerk.roguelike.editor.Coord; -import com.greymerk.roguelike.editor.IWorldEditor; -import com.greymerk.roguelike.editor.WorldEditor; -import com.greymerk.roguelike.gamerules.RoguelikeRules; -import com.greymerk.roguelike.state.RoguelikeState; - -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents.Load; -import net.minecraft.registry.RegistryKey; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.WorldChunk; - -public class ChunkLoadGenerateDungeon implements Load{ - - @Override - public void onChunkLoad(ServerWorld sw, WorldChunk chunk) { - if(sw.isClient) return; - long inhabited = chunk.getInhabitedTime(); - if(inhabited != 0) return; - - IWorldEditor editor = new WorldEditor(sw); - if(!editor.getGameRules().getBoolean(RoguelikeRules.GEN_ROGUELIKE_DUNGEONS)) return; - - ChunkPos cpos = chunk.getPos(); - if(!DungeonPlacement.validChunkPos(editor, cpos)) return; - RegistryKey key = editor.getKey(); - RoguelikeState state = editor.getState(); - state.addPlacement(DungeonLocation.of(key, cpos)); - } - -} diff --git a/src/main/java/com/greymerk/roguelike/events/WorldTickGenerate.java b/src/main/java/com/greymerk/roguelike/events/WorldTickGenerate.java index bbfda363f..1ec20aaa1 100644 --- a/src/main/java/com/greymerk/roguelike/events/WorldTickGenerate.java +++ b/src/main/java/com/greymerk/roguelike/events/WorldTickGenerate.java @@ -7,26 +7,18 @@ import com.greymerk.roguelike.editor.WorldEditor; import com.greymerk.roguelike.state.RoguelikeState; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.StartTick; -import net.minecraft.server.MinecraftServer; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.StartWorldTick; import net.minecraft.server.world.ServerWorld; import net.minecraft.world.dimension.DimensionTypes; -public class WorldTickGenerate implements StartTick{ +public class WorldTickGenerate implements StartWorldTick{ @Override - public void onStartTick(MinecraftServer server) { - server.getWorlds().forEach(sw -> { - tick(sw); - }); - } - - public void tick(ServerWorld sw) { + public void onStartTick(ServerWorld sw) { if(sw.getDimensionKey() != DimensionTypes.OVERWORLD) return; if(!RoguelikeState.flagForGenerationCheck) return; IWorldEditor editor = new WorldEditor(sw); - //System.out.println("tick " + editor.getKey()); RoguelikeState state = editor.getState(); List rooms = state.getFromLoaded(editor); if(rooms.isEmpty()) return; @@ -38,6 +30,6 @@ public void tick(ServerWorld sw) { } state.update(); - RoguelikeState.flagForGenerationCheck = false; + RoguelikeState.flagForGenerationCheck = false; } } diff --git a/src/main/java/com/greymerk/roguelike/events/WorldTickGenerateDungeons.java b/src/main/java/com/greymerk/roguelike/events/WorldTickGenerateDungeons.java deleted file mode 100644 index bb92145c1..000000000 --- a/src/main/java/com/greymerk/roguelike/events/WorldTickGenerateDungeons.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.greymerk.roguelike.events; - -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndWorldTick; -import net.minecraft.server.world.ServerWorld; - -public class WorldTickGenerateDungeons implements EndWorldTick{ - - @Override - public void onEndTick(ServerWorld sw) { - - } - - - -} diff --git a/src/main/java/com/greymerk/roguelike/events/WorldTickTest.java b/src/main/java/com/greymerk/roguelike/events/WorldTickTest.java deleted file mode 100644 index a3d39591c..000000000 --- a/src/main/java/com/greymerk/roguelike/events/WorldTickTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.greymerk.roguelike.events; - -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.StartWorldTick; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.world.dimension.DimensionTypes; - -public class WorldTickTest implements StartWorldTick { - - @Override - public void onStartTick(ServerWorld world) { - if(world.getDimensionKey() != DimensionTypes.OVERWORLD) return; - - System.out.println(world.getRegistryKey()); - } - - - -} diff --git a/src/main/java/com/greymerk/roguelike/state/RoguelikeState.java b/src/main/java/com/greymerk/roguelike/state/RoguelikeState.java index 553c33e28..f22bfe5f7 100644 --- a/src/main/java/com/greymerk/roguelike/state/RoguelikeState.java +++ b/src/main/java/com/greymerk/roguelike/state/RoguelikeState.java @@ -1,14 +1,11 @@ package com.greymerk.roguelike.state; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import com.greymerk.roguelike.Roguelike; import com.greymerk.roguelike.dungeon.Dungeon; -import com.greymerk.roguelike.dungeon.DungeonLocation; import com.greymerk.roguelike.dungeon.room.IRoom; import com.greymerk.roguelike.editor.Coord; import com.greymerk.roguelike.editor.IWorldEditor; @@ -26,13 +23,11 @@ public class RoguelikeState extends PersistentState { public static boolean flagForGenerationCheck = true; private List dungeons; - private Set potentials; private RoguelikeState() { //because different threads may be concurrently writing //CopyOnWriteArrayList avoids concurrent modification error this.dungeons = new CopyOnWriteArrayList(); - this.potentials = new HashSet(); } public void addDungeon(Dungeon toAdd) { @@ -40,15 +35,6 @@ public void addDungeon(Dungeon toAdd) { this.markDirty(); } - public void addPlacement(DungeonLocation toAdd) { - this.potentials.add(toAdd); - this.markDirty(); - } - - public void removePlacement(DungeonLocation dl) { - this.potentials.remove(dl); - this.markDirty(); - } public void update() { this.markDirty(); @@ -70,19 +56,6 @@ public List getFromLoaded(IWorldEditor editor){ return loadedRooms; } - public List getLoadedPotentials(IWorldEditor editor){ - List placements = new ArrayList(); - if(this.potentials.isEmpty()) return List.of(); - this.potentials.forEach(dl -> { - if(!editor.getKey().equals(dl.getKey())) return; - Coord pos = Coord.of(dl.getChunkPos()); - if(editor.surroundingChunksLoaded(pos)) { - placements.add(dl); - } - }); - return placements; - } - @Override public NbtCompound writeNbt(NbtCompound nbt) { NbtList dungeonData = new NbtList(); @@ -94,13 +67,6 @@ public NbtCompound writeNbt(NbtCompound nbt) { nbt.put("dungeons", dungeonData); - NbtList placements = new NbtList(); - this.potentials.forEach(dl -> { - NbtCompound data = dl.getNbt(); - placements.add(data); - }); - - nbt.put("potentials", placements); return nbt; } @@ -109,9 +75,6 @@ public static RoguelikeState createFromNbt(NbtCompound tag) { NbtList dungeonList = tag.getList("dungeons", NbtElement.COMPOUND_TYPE); roguelikeState.dungeons = RoguelikeState.load(dungeonList); - NbtList potentials = tag.getList("potentials", NbtElement.COMPOUND_TYPE); - roguelikeState.potentials = RoguelikeState.loadPlacements(potentials); - return roguelikeState; } @@ -126,16 +89,6 @@ public static List load(NbtList dungeonList){ return dungeons; } - public static Set loadPlacements(NbtList placements){ - Set locations = new HashSet(); - for(int i = 0; i < placements.size(); i++) { - NbtCompound data = placements.getCompound(i); - DungeonLocation toAdd = DungeonLocation.of(data); - locations.add(toAdd); - } - return locations; - } - public static RoguelikeState getServerState(RegistryKey key, MinecraftServer server) { // First we get the persistentStateManager for the OVERWORLD PersistentStateManager persistentStateManager = server