Skip to content

Commit

Permalink
version 2.0.4b and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Greymerk committed Jun 16, 2024
1 parent 765af39 commit 2fbc52a
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 269 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/main/java/com/greymerk/roguelike/Roguelike.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

This file was deleted.

90 changes: 0 additions & 90 deletions src/main/java/com/greymerk/roguelike/dungeon/DungeonLocation.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/com/greymerk/roguelike/editor/WorldEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

This file was deleted.

16 changes: 4 additions & 12 deletions src/main/java/com/greymerk/roguelike/events/WorldTickGenerate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRoom> rooms = state.getFromLoaded(editor);
if(rooms.isEmpty()) return;
Expand All @@ -38,6 +30,6 @@ public void tick(ServerWorld sw) {
}

state.update();
RoguelikeState.flagForGenerationCheck = false;
RoguelikeState.flagForGenerationCheck = false;
}
}

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/com/greymerk/roguelike/events/WorldTickTest.java

This file was deleted.

47 changes: 0 additions & 47 deletions src/main/java/com/greymerk/roguelike/state/RoguelikeState.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,29 +23,18 @@ public class RoguelikeState extends PersistentState {

public static boolean flagForGenerationCheck = true;
private List<Dungeon> dungeons;
private Set<DungeonLocation> potentials;

private RoguelikeState() {
//because different threads may be concurrently writing
//CopyOnWriteArrayList avoids concurrent modification error
this.dungeons = new CopyOnWriteArrayList<Dungeon>();
this.potentials = new HashSet<DungeonLocation>();
}

public void addDungeon(Dungeon toAdd) {
this.dungeons.add(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();
Expand All @@ -70,19 +56,6 @@ public List<IRoom> getFromLoaded(IWorldEditor editor){
return loadedRooms;
}

public List<DungeonLocation> getLoadedPotentials(IWorldEditor editor){
List<DungeonLocation> placements = new ArrayList<DungeonLocation>();
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();
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -126,16 +89,6 @@ public static List<Dungeon> load(NbtList dungeonList){
return dungeons;
}

public static Set<DungeonLocation> loadPlacements(NbtList placements){
Set<DungeonLocation> locations = new HashSet<DungeonLocation>();
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<World> key, MinecraftServer server) {
// First we get the persistentStateManager for the OVERWORLD
PersistentStateManager persistentStateManager = server
Expand Down

0 comments on commit 2fbc52a

Please sign in to comment.