Added Cardinal Components and converted Pocket and Rift Registry.

This commit is contained in:
Waterpicker 2021-01-15 10:19:12 -06:00
parent eb0ae960ec
commit 9e5860d3e8
8 changed files with 73 additions and 47 deletions

View file

@ -13,6 +13,10 @@ repositories {
maven { url = 'https://www.cursemaven.com' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://server.bbkr.space/artifactory/libs-release' }
maven {
name = "Ladysnake Libs"
url = "https://dl.bintray.com/ladysnake/libs"
}
}
def includeCompile(str) {
@ -36,6 +40,7 @@ dependencies {
includeCompile("io.github.boogiemonster1o1:libcbe:1.1.0")
includeCompile("io.github.cottonmc:LibGui:3.3.2+1.16.4")
includeCompile("me.shedaniel.cloth:config-2:4.8.3")
includeCompile("io.github.onyxstudios:Cardinal-Components-API:2.7.10")
// TODO: Add project id
// modImplementation("curse.maven:worldedit:3039223") // For saving schematics

View file

@ -0,0 +1,35 @@
package org.dimdev.dimdoors;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraft.world.WorldProperties;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentRegistryV3;
import dev.onyxstudios.cca.api.v3.level.LevelComponentFactory;
import dev.onyxstudios.cca.api.v3.level.LevelComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.level.LevelComponentInitializer;
import dev.onyxstudios.cca.api.v3.scoreboard.ScoreboardComponentFactory;
import dev.onyxstudios.cca.api.v3.scoreboard.ScoreboardComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.scoreboard.ScoreboardComponentInitializer;
import dev.onyxstudios.cca.api.v3.world.WorldComponentFactory;
import dev.onyxstudios.cca.api.v3.world.WorldComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.world.WorldComponentInitializer;
import nerdhub.cardinal.components.api.component.Component;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
public class DimensionalDoorsComponents implements ScoreboardComponentInitializer, WorldComponentInitializer {
public static final ComponentKey<RiftRegistry> RIFT_REGISTRY_COMPONENT_KEY = ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier("dimdoors:rift_registry"), RiftRegistry.class);
public static final ComponentKey<PocketRegistry> POCKET_REGISTRY_COMPONENT_KEY = ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier("dimdoors:pocket_registry"), PocketRegistry.class);
@Override
public void registerScoreboardComponentFactories(ScoreboardComponentFactoryRegistry registry) {
registry.register(RIFT_REGISTRY_COMPONENT_KEY, (ScoreboardComponentFactory<RiftRegistry>) scoreboard -> new RiftRegistry());
}
@Override
public void registerWorldComponentFactories(WorldComponentFactoryRegistry registry) {
registry.register(POCKET_REGISTRY_COMPONENT_KEY, world -> new PocketRegistry());
}
}

View file

@ -21,14 +21,6 @@ public class RiftData {
public RiftData() {
}
private RiftData(VirtualTarget destination, LinkProperties properties, boolean alwaysDelete, boolean forcedColor, RGBA color) {
this.destination = destination;
this.properties = properties;
this.alwaysDelete = alwaysDelete;
this.forcedColor = forcedColor;
this.color = color;
}
public VirtualTarget getDestination() {
return this.destination;
}

View file

@ -94,7 +94,6 @@ public class TemplateUtils {
VirtualTarget dest = rift.getDestination();
if (dest instanceof PocketEntranceMarker) {
if (rift == selectedEntrance) {
PocketRegistry.getInstance(world.getRegistryKey()).markDirty();
rift.setDestination(((PocketEntranceMarker) dest).getIfDestination());
rift.register();
RiftRegistry.instance().addPocketEntrance(pocket, new Location((ServerWorld) rift.getWorld(), rift.getPos()));

View file

@ -10,6 +10,9 @@ import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import dev.onyxstudios.cca.api.v3.component.ComponentV3;
import org.dimdev.dimdoors.DimensionalDoorsComponents;
import org.dimdev.dimdoors.util.GraphUtils;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.NbtUtil;
@ -26,9 +29,10 @@ import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import static net.minecraft.world.World.OVERWORLD;
import static org.dimdev.dimdoors.DimensionalDoorsInitializer.getServer;
import static org.dimdev.dimdoors.DimensionalDoorsInitializer.getWorld;
public class RiftRegistry extends PersistentState {
public class RiftRegistry implements ComponentV3 {
private static final Logger LOGGER = LogManager.getLogger();
private static final String DATA_NAME = "rifts";
@ -41,16 +45,12 @@ public class RiftRegistry extends PersistentState {
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld
public RiftRegistry() {
super(DATA_NAME);
}
public static RiftRegistry instance() {
return getWorld(OVERWORLD).getPersistentStateManager().getOrCreate(RiftRegistry::new, DATA_NAME);
return DimensionalDoorsComponents.RIFT_REGISTRY_COMPONENT_KEY.get(getServer().getScoreboard());
}
@Override
public void fromTag(CompoundTag nbt) {
public void readFromNbt(CompoundTag nbt) {
// Read rifts in this dimension
ListTag riftsNBT = (ListTag) nbt.get("rifts");
@ -86,9 +86,7 @@ public class RiftRegistry extends PersistentState {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
if (this == null) {
}
public void writeToNbt(CompoundTag tag) {
// Write rifts in this dimension
ListTag riftsNBT = new ListTag();
ListTag pocketsNBT = new ListTag();
@ -121,7 +119,6 @@ public class RiftRegistry extends PersistentState {
tag.put("lastPrivatePocketEntrances", this.writePlayerRiftPointers(this.lastPrivatePocketEntrances));
tag.put("lastPrivatePocketExits", this.writePlayerRiftPointers(this.lastPrivatePocketExits));
tag.put("overworldRifts", this.writePlayerRiftPointers(this.overworldRifts));
return tag;
}
private Map<UUID, PlayerRiftPointer> readPlayerRiftPointers(ListTag tag) {
@ -220,9 +217,8 @@ public class RiftRegistry extends PersistentState {
private void addEdge(RegistryVertex from, RegistryVertex to) {
this.graph.addEdge(from, to);
if (from instanceof PlayerRiftPointer) {
this.markDirty();
} else if (from instanceof Rift) {
if (from instanceof Rift) {
((Rift) from).markDirty();
}
if (to instanceof Rift) {
@ -232,10 +228,6 @@ public class RiftRegistry extends PersistentState {
private void removeEdge(RegistryVertex from, RegistryVertex to) {
this.graph.removeEdge(from, to);
if (from instanceof PlayerRiftPointer) {
this.markDirty();
}
}
public void addLink(Location locationFrom, Location locationTo) {

View file

@ -38,9 +38,10 @@ public final class Pocket {
}
public Pocket(int id, RegistryKey<World> world, int x, int z) {
int gridSize = PocketRegistry.getInstance(world).getGridSize() * 16;
this.id = id;
this.world = world;
this.box = new BlockBox(x * 16, 0, z * 16, (x + 1) * 16, 0, (z + 1) * 16);
this.box = new BlockBox(x * gridSize, 0, z * gridSize, (x + 1) * gridSize, 0, (z + 1) * gridSize);
this.virtualLocation = new VirtualLocation(world, x, z, 0);
}

View file

@ -4,6 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import dev.onyxstudios.cca.api.v3.component.Component;
import org.dimdev.dimdoors.DimensionalDoorsComponents;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.math.GridUtil;
@ -13,34 +15,28 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
public class PocketRegistry extends PersistentState {
private static final String DATA_NAME = "pocketlib_pockets";
public class PocketRegistry implements Component {
/*package-private*/ int gridSize; // Determines how much pockets in their dimension are spaced
/*package-private*/ int privatePocketSize;
/*package-private*/ int publicPocketSize;
/*package-private*/ Map<Integer, Pocket> pockets;
/*package-private*/ int nextID;
int gridSize; // Determines how much pockets in their dimension are spaced
int privatePocketSize;
int publicPocketSize;
Map<Integer, Pocket> pockets;
int nextID;
private ServerWorld world;
public PocketRegistry() {
super(DATA_NAME);
super();
this.gridSize = ModConfig.INSTANCE.getPocketsConfig().pocketGridSize;
this.nextID = 0;
this.pockets = new HashMap<>();
}
public PocketRegistry(String s) {
super(s);
}
@Override
public void fromTag(CompoundTag tag) {
public void readFromNbt(CompoundTag tag) {
this.gridSize = tag.getInt("gridSize");
this.privatePocketSize = tag.getInt("privatePocketSize");
this.publicPocketSize = tag.getInt("publicPocketSize");
@ -51,7 +47,7 @@ public class PocketRegistry extends PersistentState {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public void writeToNbt(CompoundTag tag) {
tag.putInt("gridSize", this.gridSize);
tag.putInt("privatePocketSize", this.privatePocketSize);
tag.putInt("publicPocketSize", this.publicPocketSize);
@ -60,7 +56,6 @@ public class PocketRegistry extends PersistentState {
this.pockets.forEach((key, value) -> pocketsTag.put(key.toString(), value.toTag()));
tag.put("pockets", pocketsTag);
tag.putInt("nextID", this.nextID);
return tag;
}
public static PocketRegistry getInstance(RegistryKey<World> key) {
@ -70,7 +65,7 @@ public class PocketRegistry extends PersistentState {
throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!");
}
PocketRegistry instance = world.getPersistentStateManager().getOrCreate(PocketRegistry::new, DATA_NAME);
PocketRegistry instance = DimensionalDoorsComponents.POCKET_REGISTRY_COMPONENT_KEY.get(world);
instance.world = world;
for (Pocket pocket : instance.pockets.values()) {
@ -102,13 +97,11 @@ public class PocketRegistry extends PersistentState {
Pocket pocket = new Pocket(id, this.world.getRegistryKey(), pos.x, pos.z);
this.pockets.put(id, pocket);
if (id >= this.nextID) this.nextID = id + 1;
this.markDirty();
return pocket;
}
public void removePocket(int id) {
this.pockets.remove(id);
this.markDirty();
}
/**

View file

@ -29,6 +29,9 @@
],
"modmenu": [
"org.dimdev.dimdoors.client.config.ModMenuImpl"
],
"cardinal-components": [
"org.dimdev.dimdoors.DimensionalDoorsComponents"
]
},
"mixins": [
@ -37,5 +40,11 @@
"depends": {
"fabricloader": ">=0.4.0",
"fabric": "*"
},
"custom": {
"cardinal-components": [
"dimdoors:rift_registry",
"dimdoors:pocket_registry"
]
}
}