Start work on DungeonTarget and splitting stuff

This commit is contained in:
SD 2021-05-10 11:13:25 +05:30
parent 7f6239201e
commit 0b5264c40b
5 changed files with 153 additions and 12 deletions

View file

@ -16,6 +16,15 @@ import net.minecraft.server.world.ServerWorld;
public final class PocketGenerator {
private static final Logger LOGGER = LogManager.getLogger();
public static final Identifier ALL_DUNGEONS = new Identifier("dimdoors", "dungeon");
public static final Identifier NETHER_DUNGEONS = new Identifier("dimdoors", "nether");
public static final Identifier RUINS_DUNGEONS = new Identifier("dimdoors", "ruins");
public static final Identifier ATLANTIS_DUNGEONS = new Identifier("dimdoors", "atlantis");
public static final Identifier JUNGLE_DUNGEONS = new Identifier("dimdoors", "jungle");
public static final Identifier SNOW_DUNGEONS = new Identifier("dimdoors", "snow");
public static final Identifier PYRAMID_DUNGEONS = new Identifier("dimdoors", "pyramid");
public static final Identifier END_DUNGEONS = new Identifier("dimdoors", "end");
/*
private static Pocket prepareAndPlacePocket(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
LOGGER.info("Generating pocket from template " + pocketTemplate.getId() + " at virtual location " + virtualLocation);
@ -49,6 +58,10 @@ public final class PocketGenerator {
return generateFromPocketGroupV2(DimensionalDoorsInitializer.getWorld(ModDimensions.DUNGEON), new Identifier("dimdoors", "dungeon"), virtualLocation, linkTo, linkProperties);
}
public static Pocket generateDungeonPocketV2(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties, Identifier group) {
return generateFromPocketGroupV2(DimensionalDoorsInitializer.getWorld(ModDimensions.DUNGEON), group, virtualLocation, linkTo, linkProperties);
}
/*
/**
* Create a dungeon pockets at a certain depth.

View file

@ -0,0 +1,120 @@
package org.dimdev.dimdoors.rift.targets;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import org.dimdev.dimdoors.api.rift.target.Target;
import org.dimdev.dimdoors.pockets.PocketGenerator;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
public class DungeonTarget extends RandomTarget {
private final Identifier dungeonGroup;
public DungeonTarget(float newRiftWeight, double weightMaximum, double coordFactor, double positiveDepthFactor, double negativeDepthFactor, Set<Integer> acceptedGroups, boolean noLink, boolean noLinkBack, Identifier dungeonGroup) {
super(newRiftWeight, weightMaximum, coordFactor, positiveDepthFactor, negativeDepthFactor, acceptedGroups, noLink, noLinkBack);
this.dungeonGroup = dungeonGroup;
}
@Override
protected Pocket generatePocket(VirtualLocation location, GlobalReference linkTo, LinkProperties props) {
return PocketGenerator.generateDungeonPocketV2(location, linkTo, props, this.dungeonGroup);
}
public static NbtCompound toNbt(DungeonTarget target) {
NbtCompound nbt = RandomTarget.toNbt(target);
nbt.putString("dungeonGroup", target.dungeonGroup.toString());
return nbt;
}
public static DungeonTargetBuilder builder() {
return new DungeonTargetBuilder();
}
public static DungeonTarget fromNbt(NbtCompound nbt) {
return new DungeonTarget(
nbt.getFloat("newRiftWeight"),
nbt.getDouble("weightMaximum"),
nbt.getDouble("coordFactor"),
nbt.getDouble("positiveDepthFactor"),
nbt.getDouble("negativeDepthFactor"),
Arrays.stream(nbt.getIntArray("acceptedGroups")).boxed().collect(Collectors.toSet()),
nbt.getBoolean("noLink"),
nbt.getBoolean("noLinkBack"),
new Identifier(nbt.getString("dungeonGroup"))
);
}
@Override
public VirtualTargetType<? extends VirtualTarget> getType() {
return VirtualTargetType.DUNGEON;
}
@Override
public Target receiveOther() {
return super.receiveOther();
}
public static class DungeonTargetBuilder extends RandomTarget.RandomTargetBuilder {
private Identifier dungeonGroup = PocketGenerator.ALL_DUNGEONS;
DungeonTargetBuilder() {
}
public void dungeonGroup(Identifier dungeonGroup) {
this.dungeonGroup = dungeonGroup;
}
@Override
public DungeonTargetBuilder newRiftWeight(float newRiftWeight) {
return (DungeonTargetBuilder) super.newRiftWeight(newRiftWeight);
}
@Override
public DungeonTargetBuilder weightMaximum(double weightMaximum) {
return (DungeonTargetBuilder) super.weightMaximum(weightMaximum);
}
@Override
public DungeonTargetBuilder coordFactor(double coordFactor) {
return (DungeonTargetBuilder) super.coordFactor(coordFactor);
}
@Override
public DungeonTargetBuilder positiveDepthFactor(double positiveDepthFactor) {
return (DungeonTargetBuilder) super.positiveDepthFactor(positiveDepthFactor);
}
@Override
public DungeonTargetBuilder negativeDepthFactor(double negativeDepthFactor) {
return (DungeonTargetBuilder) super.negativeDepthFactor(negativeDepthFactor);
}
@Override
public DungeonTargetBuilder acceptedGroups(Set<Integer> acceptedGroups) {
return (DungeonTargetBuilder) super.acceptedGroups(acceptedGroups);
}
@Override
public DungeonTargetBuilder noLink(boolean noLink) {
return (DungeonTargetBuilder) super.noLink(noLink);
}
@Override
public DungeonTargetBuilder noLinkBack(boolean noLinkBack) {
return (DungeonTargetBuilder) super.noLinkBack(noLinkBack);
}
@Override
public DungeonTarget build() {
return new DungeonTarget(this.newRiftWeight, this.weightMaximum, this.coordFactor, this.positiveDepthFactor, this.negativeDepthFactor, this.acceptedGroups, this.noLink, this.noLinkBack, this.dungeonGroup);
}
}
}

View file

@ -2,6 +2,7 @@ package org.dimdev.dimdoors.rift.targets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -173,6 +174,10 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
}
}
protected Pocket generatePocket(VirtualLocation location, GlobalReference linkTo, LinkProperties props) {
return PocketGenerator.generateDungeonPocketV2(location, linkTo, props);
}
private static void linkRifts(Location from, Location to) {
RiftBlockEntity fromBe = (RiftBlockEntity) from.getBlockEntity();
RiftBlockEntity toBe = (RiftBlockEntity) to.getBlockEntity();
@ -254,14 +259,14 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
}
public static class RandomTargetBuilder {
private float newRiftWeight;
private double weightMaximum;
private double coordFactor;
private double positiveDepthFactor;
private double negativeDepthFactor;
private Set<Integer> acceptedGroups;
private boolean noLink;
private boolean noLinkBack;
protected float newRiftWeight;
protected double weightMaximum;
protected double coordFactor;
protected double positiveDepthFactor;
protected double negativeDepthFactor;
protected Set<Integer> acceptedGroups = Collections.emptySet();
protected boolean noLink;
protected boolean noLinkBack;
RandomTargetBuilder() {
}

View file

@ -86,6 +86,7 @@ public abstract class VirtualTarget implements Target {
public interface VirtualTargetType<T extends VirtualTarget> {
VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("dimdoors:available_link", RandomTarget::fromNbt, RandomTarget::toNbt, VirtualTarget.COLOR);
VirtualTargetType<RandomTarget> DUNGEON = register("dimdoors:dungeon", DungeonTarget::fromNbt, DungeonTarget::toNbt, VirtualTarget.COLOR);
VirtualTargetType<EscapeTarget> ESCAPE = register("dimdoors:escape", EscapeTarget::fromNbt, EscapeTarget::toNbt, VirtualTarget.COLOR);
VirtualTargetType<GlobalReference> GLOBAL = register("dimdoors:global", GlobalReference::fromNbt, GlobalReference::toNbt, VirtualTarget.COLOR);
VirtualTargetType<LimboTarget> LIMBO = register("dimdoors:limbo", a -> LimboTarget.INSTANCE, a -> new NbtCompound(), VirtualTarget.COLOR);

View file

@ -1,4 +1,6 @@
{
[
{
"path": "dimdoors:dungeon/",
"type": "dimdoors:path"
}
}
]