Merge pull request #175 from BoogieMonster1O1/1.16-fabric

Fixes to limbo world generation
This commit is contained in:
Waterpicker 2020-09-29 03:07:18 -05:00 committed by GitHub
commit 46f9dcd9e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 224 additions and 333 deletions

View file

@ -1,4 +0,0 @@
package org.dimdev.annotatednbt;
public @interface Saved {
}

View file

@ -366,7 +366,7 @@ public class Schematic implements BlockView {
// Place the schematic's blocks
this.setBlocks(world, xBase, yBase, zBase);
// Set BlockEntity data
// Set BlockEntity data
for (CompoundTag BlockEntityNBT : tileEntities) {
Vec3i schematicPos = new BlockPos(BlockEntityNBT.getInt("x"), BlockEntityNBT.getInt("y"), BlockEntityNBT.getInt("z"));
BlockPos pos = new BlockPos(xBase, yBase, zBase).add(schematicPos);
@ -469,7 +469,7 @@ public class Schematic implements BlockView {
ServerWorld w;
if(world instanceof ServerWorldAccess) {
if (world instanceof ServerWorldAccess) {
w = ((ServerWorldAccess) world).toServerWorld();
} else {
w = (ServerWorld) world;

View file

@ -76,7 +76,7 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
if (block instanceof ConditionalBlockEntityProvider && ((ConditionalBlockEntityProvider) block).hasBlockEntity(this.getBlockState(pos)) && ((ConditionalBlockEntityProvider) block).hasBlockEntity(pos, this)) {
return ((ConditionalBlockEntityProvider) block).createBlockEntity(this.world);
} else {
return ((BlockEntityProvider)block).createBlockEntity(this.world);
return ((BlockEntityProvider) block).createBlockEntity(this.world);
}
}
return null;

View file

@ -35,7 +35,7 @@ public class Schematic {
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.CODEC).optionalFieldOf("BlockEntities", ImmutableList.of()).forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities)
).apply(instance, Schematic::new);
).apply(instance, Schematic::new);
});
private final int version;

View file

@ -7,8 +7,6 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.UnboundedMapCodec;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.block.BaseBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Property;
@ -28,7 +26,7 @@ public class SchematicBlockPalette {
static DataResult<BlockState> to(String string) {
if (!string.contains("[") && !string.contains("]")) {
BlockState state = Registry.BLOCK.get(new Identifier(string)).getDefaultState();
BlockState state = Registry.BLOCK.get(new Identifier(string)).getDefaultState();
return DataResult.success(state);
} else {
Block block = Objects.requireNonNull(Registry.BLOCK.get(new Identifier(string.substring(0, string.indexOf("[")))));
@ -39,7 +37,7 @@ public class SchematicBlockPalette {
String[] stateArray = string.substring(string.indexOf("[") + 1, string.length() - 1).split(",");
for (String stateString : stateArray) {
Property<?> property = Objects.requireNonNull(block.getStateManager().getProperty(stateString.split("=")[0]));
state = process(property,stateString.split("=")[1], state);
state = process(property, stateString.split("=")[1], state);
}
System.out.println(state);
@ -54,7 +52,7 @@ public class SchematicBlockPalette {
// Ensures that [ and ] are only added when properties are present
boolean flag = true;
Iterator<Property<?>> iterator = state.getProperties().iterator();
while(iterator.hasNext()) {
while (iterator.hasNext()) {
if (flag) {
builder.append("[");
flag = false;

View file

@ -56,7 +56,7 @@ public final class SchematicPlacer {
List<CompoundTag> entityTags = schematic.getEntities();
for (CompoundTag tag : entityTags) {
// Ensures compatibility with worldedit schematics
if (SchematicPlacer.fixId(tag)){
if (SchematicPlacer.fixId(tag)) {
System.err.println("An unexpected error occurred parsing this entity");
System.err.println(tag.toString());
throw new IllegalStateException("Entity in schematic \"" + schematic.getMetadata().getName() + "\" did not have an Id tag, nor an id tag!");
@ -93,7 +93,7 @@ public final class SchematicPlacer {
DoubleTag.of(x + originX),
DoubleTag.of(y + originY),
DoubleTag.of(z + originZ)
),
),
(byte) 6
)
);

View file

@ -4,12 +4,11 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.IntStream;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.mojang.serialization.DataResult;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlastFurnaceBlockEntity;

View file

@ -58,13 +58,13 @@ public class DimensionalDoorsInitializer implements ModInitializer {
ModBlocks.init();
ModItems.init();
ModFeatures.init();
ModBiomes.init();
ModDimensions.init();
ModEntityTypes.init();
ModBiomes.init();
ModBlockEntityTypes.init();
ModCommands.init();
ModSoundEvents.init();
ModFeatures.init();
ModConfig.deserialize();

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.block.entity;
import java.util.Random;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.util.TeleportUtil;
@ -22,13 +21,9 @@ import net.fabricmc.api.Environment;
public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable {
private static final Random random = new Random();
@Saved
public boolean closing = false;
@Saved
public boolean stabilized = false;
@Saved
public int spawnedEndermanId = 0;
@Saved
public float size = 0;
private boolean unregisterDisabled = false;

View file

@ -2,10 +2,10 @@ package org.dimdev.dimdoors.block.entity;
import java.util.function.Supplier;
import com.google.common.collect.Sets;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer;
import org.dimdev.dimdoors.client.EntranceRiftBlockEntityRenderer;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.block.entity;
import java.util.Objects;
import com.mojang.serialization.Codec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.pockets.PocketTemplate;
@ -19,6 +18,7 @@ import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.NbtUtil;
import org.dimdev.dimdoors.util.RGBA;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import com.mojang.serialization.Codec;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@ -173,8 +173,8 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
EntityTarget target = this.getTarget().as(Targets.ENTITY);
if (target.receiveEntity(entity, entity.yaw)) {
VirtualLocation vloc = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos()));
EntityUtils.chat(entity, new LiteralText("You are at x = " + vloc.x + ", y = ?, z = " + vloc.z + ", w = " + vloc.depth));
VirtualLocation vLoc = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos()));
EntityUtils.chat(entity, new LiteralText("You are at x = " + vLoc.getX() + ", y = ?, z = " + vLoc.getZ() + ", w = " + vLoc.getDepth()));
return true;
}
} catch (Exception e) {

View file

@ -1,10 +1,10 @@
package org.dimdev.dimdoors.block.entity;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.util.RGBA;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public class RiftData {
public static Codec<RiftData> CODEC = RecordCodecBuilder.create(instance -> {

View file

@ -1,10 +1,10 @@
package org.dimdev.dimdoors.client;
import com.flowpowered.math.TrigMath;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.tesseract.Tesseract;
import org.dimdev.dimdoors.util.RGBA;
import com.flowpowered.math.TrigMath;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;

View file

@ -2,13 +2,10 @@ package org.dimdev.dimdoors.client;
import java.util.List;
import java.util.Random;
import java.util.stream.Collector;
import java.util.stream.IntStream;
import com.google.common.collect.ImmutableList;
import it.unimi.dsi.fastutil.ints.AbstractInt2FloatMap;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.util.RGBA;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;

View file

@ -2,8 +2,8 @@ package org.dimdev.dimdoors.client;
import java.util.List;
import com.google.common.collect.Lists;
import org.dimdev.dimdoors.entity.MonolithEntity;
import com.google.common.collect.Lists;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.LivingEntityRenderer;

View file

@ -3,12 +3,12 @@ package org.dimdev.dimdoors.client;
import java.util.Arrays;
import java.util.Random;
import org.dimdev.dimdoors.mixin.DirectionAccessor;
import org.lwjgl.opengl.GL11;
import com.flowpowered.math.vector.VectorNi;
import com.mojang.blaze3d.systems.RenderSystem;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.mixin.DirectionAccessor;
import org.dimdev.dimdoors.util.RGBA;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR;
import static org.lwjgl.opengl.GL11.GL_ZERO;
import net.minecraft.block.enums.DoorHinge;
import net.minecraft.client.render.RenderLayer;
@ -20,12 +20,6 @@ import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR;
import static org.lwjgl.opengl.GL11.GL_ZERO;
public class MyRenderLayer extends RenderLayer {
public static final Identifier WARP_PATH = new Identifier("dimdoors:textures/other/warp.png");
@ -60,26 +54,6 @@ public class MyRenderLayer extends RenderLayer {
.texture(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH, false, false))
.alpha(Alpha.HALF_ALPHA)
.build(false));
//
// public static RenderLayer getDimensionalPortal(int phase, EntranceRiftBlockEntity blockEntity) {
// Direction orientation = blockEntity.getOrientation();
// Texture tex = new Texture(WARP_PATH, false, false);
// Vec3d offset = new Vec3d(orientation.getOpposite().getUnitVector());
// return of("dimensional_portal",
// VertexFormats.POSITION_COLOR,
// 7, 256,
// false,
// true,
// RenderLayer.MultiPhaseParameters.builder()
// .transparency(ADDITIVE_TRANSPARENCY)
// .texture(tex)
// .texturing(new DimensionalPortalTexturing(phase,
// blockEntity,
// blockEntity.getPos().getX() + offset.x,
// blockEntity.getPos().getY() + offset.y,
// blockEntity.getPos().getZ() + offset.z))
// .fog(BLACK_FOG).build(false));
// }
public static RenderLayer getPortal(int layer) {
RenderPhase.Transparency transparency;
@ -94,40 +68,4 @@ public class MyRenderLayer extends RenderLayer {
return of("dimensional_portal", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(transparency).texture(texture).texturing(new RenderPhase.PortalTexturing(layer)).fog(BLACK_FOG).build(false));
}
// public static class DimensionalPortalTexturing extends RenderPhase.Texturing {
// public final int layer;
//
// public DimensionalPortalTexturing(int layer, EntranceRiftBlockEntity blockEntity, double x, double y, double z) {
// super("dimensional_portal_texturing", () -> {
// float translationScale = 16 - layer;
// float scale = 0.3625F;
// float offset = Util.getMeasuringTimeNano() % 200000L / 200000.0F;
// if (layer == 0) {
// translationScale = 25.0F;
// scale = 0.125F;
// }
// if (layer == 1) {
// scale = 0.5F;
// }
// RenderSystem.matrixMode(GL11.GL_TEXTURE);
// RenderSystem.pushMatrix();
// RenderSystem.loadIdentity();
// RenderSystem.translatef(0.1F, offset * translationScale, 0.1F);
// RenderSystem.scalef(scale, scale, scale);
// RenderSystem.translatef(0.5F, 0.5F, 0.5F);
// RenderSystem.rotatef((layer * layer * 4321 + layer) * 9 * 2.0F, 0.0F, 0.0F, 1.0F);
// RenderSystem.scalef(4.5F - (float)layer / 4.0F, 4.5F - (float)layer / 4.0F, 1.0F);
// RenderSystem.mulTextureByProjModelView();
// RenderSystem.matrixMode(GL11.GL_MODELVIEW);
// RenderSystem.setupEndPortalTexGen();
// }, () -> {
// RenderSystem.matrixMode(GL11.GL_TEXTURE);
// RenderSystem.popMatrix();
// RenderSystem.matrixMode(GL11.GL_MODELVIEW);
// RenderSystem.clearTexGen();
// });
// this.layer = layer;
// }
// }
}

View file

@ -1,9 +1,9 @@
package org.dimdev.dimdoors.client.tesseract;
import org.dimdev.dimdoors.util.RGBA;
import com.flowpowered.math.matrix.Matrix4f;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector4f;
import org.dimdev.dimdoors.util.RGBA;
import net.minecraft.client.render.VertexConsumer;

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.client.tesseract;
import com.flowpowered.math.vector.Vector4f;
import org.dimdev.dimdoors.util.RGBA;
import com.flowpowered.math.vector.Vector4f;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.util.math.Matrix4f;

View file

@ -1,7 +1,6 @@
package org.dimdev.dimdoors.command;
import com.mojang.brigadier.CommandDispatcher;
import org.dimdev.dimdoors.util.TeleportUtil;
import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.command.argument.Vec3ArgumentType;
@ -10,8 +9,6 @@ import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
public class DimTeleportCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {

View file

@ -1,10 +1,5 @@
package org.dimdev.dimdoors.command;
import com.flowpowered.math.vector.Vector3i;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.dimdev.dimdoors.command.arguments.GroupArugmentType;
import org.dimdev.dimdoors.command.arguments.NameArugmentType;
import org.dimdev.dimdoors.pockets.PocketGenerator;
@ -16,6 +11,11 @@ import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.Pocket;
import com.flowpowered.math.vector.Vector3i;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.CommandException;
import net.minecraft.server.command.CommandManager;

View file

@ -2,14 +2,14 @@ package org.dimdev.dimdoors.command.arguments;
import java.util.concurrent.CompletableFuture;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import net.minecraft.server.command.CommandSource;

View file

@ -2,13 +2,13 @@ package org.dimdev.dimdoors.command.arguments;
import java.util.concurrent.CompletableFuture;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import net.minecraft.server.command.CommandSource;

View file

@ -9,6 +9,7 @@ import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.entity.MonolithEntity;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import static org.dimdev.dimdoors.entity.MonolithEntity.MAX_AGGRO;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.ai.goal.Goal;
@ -20,7 +21,6 @@ import net.minecraft.util.math.BlockPos;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import static net.minecraft.predicate.entity.EntityPredicates.EXCEPT_SPECTATOR;
import static org.dimdev.dimdoors.entity.MonolithEntity.MAX_AGGRO;
public class MonolithAggroGoal extends Goal {
protected final MonolithEntity mob;

View file

@ -9,7 +9,6 @@ import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

View file

@ -2,9 +2,9 @@ package org.dimdev.dimdoors.mixin.client;
import java.nio.FloatBuffer;
import com.mojang.blaze3d.platform.GlStateManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import com.mojang.blaze3d.platform.GlStateManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

View file

@ -1,11 +1,11 @@
package org.dimdev.dimdoors.mixin.client;
import com.mojang.blaze3d.systems.RenderSystem;
import org.dimdev.dimdoors.world.ModBiomes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.entity.Entity;

View file

@ -57,8 +57,8 @@ public final class PocketGenerator {
* @return The newly-generated dungeon pockets
*/
public static Pocket generateDungeonPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
int depth = virtualLocation.depth;
float netherProbability = WorldUtil.getWorld(virtualLocation.world).getDimension().isUltrawarm() ? 1 : (float) depth / 200; // TODO: improve nether probability
int depth = virtualLocation.getDepth();
float netherProbability = WorldUtil.getWorld(virtualLocation.getWorld()).getDimension().isUltrawarm() ? 1 : (float) depth / 200; // TODO: improve nether probability
Random random = new Random();
String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, ModConfig.INSTANCE.getPocketsConfig().maxPocketSize, false);

View file

@ -23,10 +23,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -34,6 +30,10 @@ import org.dimdev.dimcore.schematic.Schematic;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.math.MathUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;

View file

@ -4,10 +4,9 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.dimdev.dimdoors.util.Codecs;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.util.Codecs;
public class LinkProperties {
@ -39,11 +38,8 @@ public class LinkProperties {
public float floatingWeight; // TODO: depend on rift properties (ex. size, stability, or maybe a getWeightFactor method) rather than rift type
public float entranceWeight;
@Saved
public Set<Integer> groups = new HashSet<>();
@Saved
public int linksRemaining;
@Saved
public boolean oneWay;
public LinkProperties(float floatingWeight, float entranceWeight, Set<Integer> groups, int linksRemaining, boolean oneWay) {

View file

@ -4,7 +4,6 @@ import java.util.UUID;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import net.minecraft.util.dynamic.DynamicSerializableUuid;
@ -20,7 +19,6 @@ public class PlayerRiftPointer extends RegistryVertex {
});
});
@Saved
public UUID player;
public PlayerRiftPointer(UUID player) {

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.rift.registry;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import net.minecraft.util.dynamic.DynamicSerializableUuid;
import net.minecraft.util.registry.RegistryKey;
@ -21,9 +20,7 @@ public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftP
});
});
@Saved
public RegistryKey<World> pocketDim;
@Saved
public int pocketId;
public PocketEntrancePointer(RegistryKey<World> pocketDim, int pocketId) {

View file

@ -3,7 +3,6 @@ package org.dimdev.dimdoors.rift.registry;
import java.util.UUID;
import com.mojang.serialization.Codec;
import org.dimdev.annotatednbt.Saved;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
@ -20,7 +19,6 @@ public abstract class RegistryVertex {
public static final Codec<RegistryVertex> CODEC = registry.dispatch(RegistryVertex::getType, RegistryVertexType::codec);
@Saved
public UUID id = UUID.randomUUID(); // Used to create pointers to registry vertices. Should not be used for anything other than saving.
public void sourceGone(RegistryVertex source) {

View file

@ -1,12 +1,11 @@
package org.dimdev.dimdoors.rift.registry;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.util.Location;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.dynamic.DynamicSerializableUuid;
@ -25,11 +24,8 @@ public class Rift extends RegistryVertex {
});
private static final Logger LOGGER = LogManager.getLogger();
@Saved
public Location location;
@Saved
public boolean isDetached;
@Saved
public LinkProperties properties;
public Rift(Location location) {

View file

@ -1,8 +1,8 @@
package org.dimdev.dimdoors.rift.registry;
import com.mojang.serialization.Codec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mojang.serialization.Codec;
import net.minecraft.util.dynamic.DynamicSerializableUuid;

View file

@ -18,6 +18,7 @@ import org.dimdev.dimdoors.world.pocket.PocketRegistry;
import org.dimdev.dimdoors.world.pocket.PrivatePocketData;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import static org.dimdev.dimdoors.DimensionalDoorsInitializer.getWorld;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@ -26,7 +27,6 @@ import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import static net.minecraft.world.World.OVERWORLD;
import static org.dimdev.dimdoors.DimensionalDoorsInitializer.getWorld;
public class RiftRegistry extends PersistentState {
private static final Logger LOGGER = LogManager.getLogger();

View file

@ -2,21 +2,20 @@ package org.dimdev.dimdoors.rift.targets;
import java.util.UUID;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import static org.dimdev.dimdoors.util.EntityUtils.chat;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import static org.dimdev.dimdoors.util.EntityUtils.chat;
public class EscapeTarget extends VirtualTarget implements EntityTarget { // TODO: createRift option
public static final Codec<EscapeTarget> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(

View file

@ -1,31 +1,28 @@
package org.dimdev.dimdoors.rift.targets;
import java.util.HashMap;
import java.util.Map;
import org.dimdev.annotatednbt.AnnotatedNbt;
import org.dimdev.annotatednbt.Saved;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
/**
* Helps flow (fluid, redstone, power) senders to keep track of flow received by the
* target rift.
*/
public class FlowTracker { // TODO
//@Saved public Map<Direction, Map<Fluid, Integer>> fluids = new HashMap<>();
@Saved
public Map<Direction, Integer> redstone = new HashMap<>();
@Saved
public Map<Direction, Integer> power = new HashMap<>();
public void fromTag(CompoundTag nbt) {
AnnotatedNbt.load(this, nbt);
}
public CompoundTag toTag(CompoundTag nbt) {
return AnnotatedNbt.serialize(this);
}
}
//package org.dimdev.dimdoors.rift.targets;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import org.dimdev.dimdoors.util.AnnotatedNbt;
//
//import net.minecraft.nbt.CompoundTag;
//import net.minecraft.util.math.Direction;
//
///**
// * Helps flow (fluid, redstone, power) senders to keep track of flow received by the
// * target rift.
// */
//
//public class FlowTracker { // TODO
// //@Saved public Map<Direction, Map<Fluid, Integer>> fluids = new HashMap<>();
// public Map<Direction, Integer> redstone = new HashMap<>();
// public Map<Direction, Integer> power = new HashMap<>();
//
// public void fromTag(CompoundTag nbt) {
// AnnotatedNbt.load(this, nbt);
// }
//
// public CompoundTag toTag(CompoundTag nbt) {
// return AnnotatedNbt.serialize(this);
// }
//}

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.util.Location;
import com.mojang.serialization.Codec;
public class GlobalReference extends RiftReference {
public static Codec<GlobalReference> CODEC = Location.CODEC.fieldOf("location").xmap(GlobalReference::new, GlobalReference::getReferencedLocation).codec();

View file

@ -1,15 +1,13 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.util.Location;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
public class LocalReference extends RiftReference {
public static final Codec<LocalReference> CODEC = BlockPos.CODEC.xmap(LocalReference::new, LocalReference::getTarget).fieldOf("target").codec();
@Saved
protected BlockPos target;
public LocalReference(BlockPos target) {

View file

@ -1,8 +1,8 @@
package org.dimdev.dimdoors.rift.targets;
import org.dimdev.dimdoors.util.EntityUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.text.TranslatableText;

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.util.EntityUtils;
import com.mojang.serialization.Codec;
import net.minecraft.entity.Entity;
import net.minecraft.text.TranslatableText;

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.rift.targets;
import java.util.UUID;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.util.EntityUtils;
@ -12,6 +11,7 @@ import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
import org.dimdev.dimdoors.world.pocket.PrivatePocketData;
import com.mojang.serialization.Codec;
import net.minecraft.entity.Entity;
import net.minecraft.text.TranslatableText;

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.rift.targets;
import java.util.UUID;
import com.mojang.serialization.Codec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.pockets.PocketGenerator;
@ -13,6 +12,7 @@ import org.dimdev.dimdoors.util.RGBA;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.PrivatePocketData;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import com.mojang.serialization.Codec;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
@ -34,15 +34,15 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
public boolean receiveEntity(Entity entity, float yawOffset) {
// TODO: make this recursive
UUID uuid = EntityUtils.getOwner(entity).getUuid();
VirtualLocation virtualLocation = VirtualLocation.fromLocation(location);
VirtualLocation virtualLocation = VirtualLocation.fromLocation(this.location);
if (uuid != null) {
Pocket pocket = PrivatePocketData.instance().getPrivatePocket(uuid);
if (pocket == null) { // generate the private pocket and get its entrances
// set to where the pocket was first created
pocket = PocketGenerator.generatePrivatePocket(new VirtualLocation(virtualLocation.world, virtualLocation.x, virtualLocation.z, -1));
pocket = PocketGenerator.generatePrivatePocket(new VirtualLocation(virtualLocation.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
processEntity(pocket, RiftRegistry.instance().getPocketEntrance(pocket).getBlockEntity(), entity, uuid, yawOffset);
this.processEntity(pocket, RiftRegistry.instance().getPocketEntrance(pocket).getBlockEntity(), entity, uuid, yawOffset);
return true;
} else {
Location destLoc = RiftRegistry.instance().getPrivatePocketEntrance(uuid); // get the last used entrances
@ -50,13 +50,13 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
destLoc = RiftRegistry.instance().getPocketEntrance(pocket); // if there's none, then set the target to the main entrances
if (destLoc == null) { // if the pocket entrances is gone, then create a new private pocket
LOGGER.info("All entrances are gone, creating a new private pocket!");
pocket = PocketGenerator.generatePrivatePocket(new VirtualLocation(virtualLocation.world, virtualLocation.x, virtualLocation.z, -1));
pocket = PocketGenerator.generatePrivatePocket(new VirtualLocation(virtualLocation.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
destLoc = RiftRegistry.instance().getPocketEntrance(pocket);
}
processEntity(pocket, destLoc.getBlockEntity(), entity, uuid, yawOffset);
this.processEntity(pocket, destLoc.getBlockEntity(), entity, uuid, yawOffset);
return true;
}
} else {
@ -76,7 +76,7 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
}
} else {
((EntityTarget) BlockEntity).receiveEntity(entity, relativeYaw);
RiftRegistry.instance().setLastPrivatePocketExit(uuid, location);
RiftRegistry.instance().setLastPrivatePocketExit(uuid, this.location);
}
}

View file

@ -1,12 +1,12 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.pockets.PocketGenerator;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public class PublicPocketTarget extends RestoringTarget {
public final static Codec<PublicPocketTarget> CODEC = RecordCodecBuilder.create(instance -> {
@ -27,7 +27,7 @@ public class PublicPocketTarget extends RestoringTarget {
@Override
protected VirtualTarget getTarget() {
return wrappedDestination;
return this.wrappedDestination;
}
@Override
@ -37,11 +37,11 @@ public class PublicPocketTarget extends RestoringTarget {
@Override
public Location makeLinkTarget() {
VirtualLocation riftVirtualLocation = VirtualLocation.fromLocation(location);
VirtualLocation riftVirtualLocation = VirtualLocation.fromLocation(this.location);
VirtualLocation newVirtualLocation;
int depth = Math.max(riftVirtualLocation.depth, 1);
newVirtualLocation = new VirtualLocation(riftVirtualLocation.world, riftVirtualLocation.x, riftVirtualLocation.z, depth);
Pocket pocket = PocketGenerator.generatePublicPocket(newVirtualLocation, new GlobalReference(location), null);
int depth = Math.max(riftVirtualLocation.getDepth(), 1);
newVirtualLocation = new VirtualLocation(riftVirtualLocation.getWorld(), riftVirtualLocation.getX(), riftVirtualLocation.getZ(), depth);
Pocket pocket = PocketGenerator.generatePublicPocket(newVirtualLocation, new GlobalReference(this.location), null);
return RiftRegistry.instance().getPocketEntrance(pocket);
}

View file

@ -5,11 +5,6 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.common.collect.Sets;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
@ -22,6 +17,10 @@ import org.dimdev.dimdoors.util.WorldUtil;
import org.dimdev.dimdoors.util.math.MathUtil;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import com.google.common.collect.Sets;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
@ -36,27 +35,19 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
Codec.DOUBLE.fieldOf("coordFactor").forGetter(location -> location.coordFactor),
Codec.DOUBLE.fieldOf("positiveDepthFactor").forGetter(location -> location.positiveDepthFactor),
Codec.DOUBLE.fieldOf("negativeDepthFactor").forGetter(location -> location.negativeDepthFactor),
Codec.INT_STREAM.<Set<Integer>>comapFlatMap(a -> DataResult.success(a.boxed().collect(Collectors.toSet())), a -> a.stream().mapToInt(Integer::intValue)).fieldOf("acceptedGroups").forGetter(target -> target.acceptedGroups),
Codec.INT_STREAM.comapFlatMap(a -> DataResult.success(a.boxed().collect(Collectors.toSet())), a -> a.stream().mapToInt(Integer::intValue)).fieldOf("acceptedGroups").forGetter(target -> target.acceptedGroups),
Codec.BOOL.fieldOf("noLink").forGetter(target -> target.noLink),
Codec.BOOL.fieldOf("noLinkBack").forGetter(target -> target.noLinkBack)
).apply(instance, RandomTarget::new);
});
@Saved
protected float newRiftWeight;
@Saved
protected double weightMaximum;
@Saved
protected double coordFactor;
@Saved
protected double positiveDepthFactor;
@Saved
protected double negativeDepthFactor;
@Saved
protected Set<Integer> acceptedGroups;
@Saved
protected boolean noLink;
@Saved
protected boolean noLinkBack;
public RandomTarget(float newRiftWeight, double weightMaximum, double coordFactor, double positiveDepthFactor, double negativeDepthFactor, Set<Integer> acceptedGroups, boolean noLink, boolean noLinkBack) {
@ -76,24 +67,24 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
@Override
public Target receiveOther() { // TODO: Wrap rather than replace
VirtualLocation virtualLocationHere = VirtualLocation.fromLocation(location);
VirtualLocation virtualLocationHere = VirtualLocation.fromLocation(this.location);
Map<Location, Float> riftWeights = new HashMap<>();
if (newRiftWeight > 0) riftWeights.put(null, newRiftWeight);
if (this.newRiftWeight > 0) riftWeights.put(null, this.newRiftWeight);
for (Rift otherRift : RiftRegistry.instance().getRifts()) {
VirtualLocation otherVirtualLocation = VirtualLocation.fromLocation(otherRift.location);
if (otherRift.properties == null) continue;
double otherWeight = otherRift.isDetached ? otherRift.properties.floatingWeight : otherRift.properties.entranceWeight;
if (otherWeight == 0 || Sets.intersection(acceptedGroups, otherRift.properties.groups).isEmpty()) continue;
if (otherWeight == 0 || Sets.intersection(this.acceptedGroups, otherRift.properties.groups).isEmpty()) continue;
// Calculate the distance as sqrt((coordFactor * coordDistance)^2 + (depthFactor * depthDifference)^2)
if (otherVirtualLocation == null || otherRift.properties.linksRemaining == 0) continue;
double depthDifference = otherVirtualLocation.depth - virtualLocationHere.depth;
double coordDistance = Math.sqrt(sq(otherVirtualLocation.x - virtualLocationHere.x)
+ sq(otherVirtualLocation.z - virtualLocationHere.z));
double depthFactor = depthDifference > 0 ? positiveDepthFactor : negativeDepthFactor;
double distance = Math.sqrt(sq(coordFactor * coordDistance) + sq(depthFactor * depthDifference));
if (otherRift.properties.linksRemaining == 0) continue;
double depthDifference = otherVirtualLocation.getDepth() - virtualLocationHere.getDepth();
double coordDistance = Math.sqrt(this.sq(otherVirtualLocation.getX() - virtualLocationHere.getX())
+ this.sq(otherVirtualLocation.getZ() - virtualLocationHere.getZ()));
double depthFactor = depthDifference > 0 ? this.positiveDepthFactor : this.negativeDepthFactor;
double distance = Math.sqrt(this.sq(this.coordFactor * coordDistance) + this.sq(depthFactor * depthDifference));
// Calculate the weight as 4m/pi w/(m^2/d + d)^2. This is similar to how gravitational/electromagnetic attraction
// works in physics (G m1 m2/d^2 and k_e m1 m2/d^2). Even though we add a depth dimension to the world, we keep
@ -103,13 +94,13 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
// of f((m^(a+1)/a)/d^a). m is the location of f's maximum. The constant 4m/pi makes it such that a newRiftWeight
// of 1 is equivalent to having a total link weight of 1 distributed equally across all layers.
// TODO: We might want an a larger than 1 to make the function closer to 1/d^2
double weight = 4 * weightMaximum / Math.PI * otherWeight / sq(sq(weightMaximum) / distance + distance);
double weight = 4 * this.weightMaximum / Math.PI * otherWeight / this.sq(this.sq(this.weightMaximum) / distance + distance);
riftWeights.put(otherRift.location, (float) weight);
}
Location selectedLink;
if (riftWeights.size() == 0) {
if (newRiftWeight == -1) {
if (this.newRiftWeight == -1) {
selectedLink = null;
} else {
return null;
@ -139,48 +130,48 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
// Clear[m];
// inverseCummulativeNormalizedDistribution = Normal[fit]
double r = Math.random();
double distance = weightMaximum * (2 * Math.tan(Math.PI / 2 * r) - 0.5578284481138029 * Math.sqrt(r) * Math.log(r));
double distance = this.weightMaximum * (2 * Math.tan(Math.PI / 2 * r) - 0.5578284481138029 * Math.sqrt(r) * Math.log(r));
// Randomly split the vector into depth, x, and z components
// TODO: Two random angles isn't a uniformly random direction! Use random vector, normalize, add depth offset, scale xz, scale depth.
double theta = Math.random() * Math.PI; // Angle between vector and xz plane
double phi = Math.random() * Math.PI; // Angle of the vector on the xz plane relative to the x axis
double depth = distance * Math.sin(theta);
depth /= depth > 0 ? positiveDepthFactor : negativeDepthFactor;
double x = Math.cos(theta) * Math.cos(phi) * distance / coordFactor;
double z = Math.cos(theta) * Math.sin(phi) * distance / coordFactor;
VirtualLocation virtualLocation = new VirtualLocation(virtualLocationHere.world,
virtualLocationHere.x + (int) Math.round(x),
virtualLocationHere.z + (int) Math.round(z),
virtualLocationHere.depth + (int) Math.round(depth));
depth /= depth > 0 ? this.positiveDepthFactor : this.negativeDepthFactor;
double x = Math.cos(theta) * Math.cos(phi) * distance / this.coordFactor;
double z = Math.cos(theta) * Math.sin(phi) * distance / this.coordFactor;
VirtualLocation virtualLocation = new VirtualLocation(virtualLocationHere.getWorld(),
virtualLocationHere.getX() + (int) Math.round(x),
virtualLocationHere.getZ() + (int) Math.round(z),
virtualLocationHere.getDepth() + (int) Math.round(depth));
if (virtualLocation.depth <= 0) {
if (virtualLocation.getDepth() <= 0) {
// This will lead to the overworld
World world = WorldUtil.getWorld(virtualLocation.world);
BlockPos pos = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, new BlockPos(virtualLocation.x, 0, virtualLocation.z));
ServerWorld world = WorldUtil.getWorld(virtualLocation.getWorld());
BlockPos pos = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, new BlockPos(virtualLocation.getX(), 0, virtualLocation.getZ()));
if (pos.getY() == -1) {
// No blocks at that XZ (hole in bedrock)
pos = new BlockPos(virtualLocation.x, 0, virtualLocation.z);
pos = new BlockPos(virtualLocation.getX(), 0, virtualLocation.getX());
}
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
RiftBlockEntity thisRift = (RiftBlockEntity) location.getBlockEntity();
RiftBlockEntity thisRift = (RiftBlockEntity) this.location.getBlockEntity();
DetachedRiftBlockEntity riftEntity = (DetachedRiftBlockEntity) world.getBlockEntity(pos);
// TODO: Should the rift not be configured like the other link
riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build());
if (!noLinkBack && !riftEntity.getProperties().oneWay)
linkRifts(new Location((ServerWorld) world, pos), location);
if (!noLink) linkRifts(location, new Location((ServerWorld) world, pos));
if (!this.noLinkBack && !riftEntity.getProperties().oneWay)
linkRifts(new Location(world, pos), this.location);
if (!this.noLink) linkRifts(this.location, new Location(world, pos));
return riftEntity.as(Targets.ENTITY);
} else {
// Make a new dungeon pocket
RiftBlockEntity thisRift = (RiftBlockEntity) location.getBlockEntity();
RiftBlockEntity thisRift = (RiftBlockEntity) this.location.getBlockEntity();
LinkProperties newLink = thisRift.getProperties() != null ? thisRift.getProperties().toBuilder().linksRemaining(0).build() : null;
Pocket pocket = PocketGenerator.generateDungeonPocket(virtualLocation, new GlobalReference(!noLinkBack ? location : null), newLink); // TODO make the generated dungeon of the same type, but in the overworld
Pocket pocket = PocketGenerator.generateDungeonPocket(virtualLocation, new GlobalReference(!this.noLinkBack ? this.location : null), newLink); // TODO make the generated dungeon of the same type, but in the overworld
// Link the rift if necessary and teleport the entity
if (!noLink) linkRifts(location, RiftRegistry.instance().getPocketEntrance(pocket));
if (!this.noLink) linkRifts(this.location, RiftRegistry.instance().getPocketEntrance(pocket));
return (Target) RiftRegistry.instance().getPocketEntrance(pocket).getBlockEntity();
}
} else {
@ -188,8 +179,8 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
RiftBlockEntity riftEntity = (RiftBlockEntity) selectedLink.getBlockEntity();
// Link the rifts if necessary and teleport the entity
if (!noLink) linkRifts(location, selectedLink);
if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(selectedLink, location);
if (!this.noLink) linkRifts(this.location, selectedLink);
if (!this.noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(selectedLink, this.location);
return riftEntity;
}
}
@ -301,7 +292,7 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
}
public RandomTarget build() {
return new RandomTarget(newRiftWeight, weightMaximum, coordFactor, positiveDepthFactor, negativeDepthFactor, acceptedGroups, noLink, noLinkBack);
return new RandomTarget(this.newRiftWeight, this.weightMaximum, this.coordFactor, this.positiveDepthFactor, this.negativeDepthFactor, this.acceptedGroups, this.noLink, this.noLinkBack);
}
}
}

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.util.Location;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.Vec3i;

View file

@ -1,9 +1,9 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.NbtUtil;
import org.dimdev.dimdoors.util.RGBA;
import com.mojang.serialization.Codec;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;

View file

@ -1,9 +1,8 @@
package org.dimdev.annotatednbt;
package org.dimdev.dimdoors.util;
import com.google.gson.Gson;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.JsonOps;
import org.dimdev.dimdoors.util.RotatedLocation;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;

View file

@ -1,8 +1,8 @@
package org.dimdev.dimdoors.util;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
@ -20,9 +19,7 @@ public class RotatedLocation extends Location {
).apply(instance, RotatedLocation::new);
});
@Saved
public final float yaw;
@Saved
public final float pitch;
public RotatedLocation(RegistryKey<World> world, BlockPos pos, float yaw, float pitch) {

View file

@ -80,6 +80,7 @@ public final class ModBiomes {
.build())
.generationSettings(new GenerationSettings.Builder()
.feature(GenerationStep.Feature.SURFACE_STRUCTURES, ModFeatures.LIMBO_GATEWAY_CONFIGURED_FEATURE)
.feature(GenerationStep.Feature.LAKES, ModFeatures.ETERNAL_FLUID_LAKE)
.surfaceBuilder(SurfaceBuilder.NETHER.method_30478(new TernarySurfaceConfig(ModBlocks.UNRAVELLED_FABRIC.getDefaultState(), ModBlocks.UNRAVELLED_FABRIC.getDefaultState(), ModBlocks.ETERNAL_FLUID.getDefaultState())))
.build())
.precipitation(Biome.Precipitation.NONE)

View file

@ -3,13 +3,13 @@ package org.dimdev.dimdoors.world;
import java.util.Optional;
import java.util.OptionalLong;
import com.google.common.collect.ImmutableMap;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.mixin.ChunkGeneratorSettingsAccessor;
import org.dimdev.dimdoors.mixin.DimensionTypeAccessor;
import org.dimdev.dimdoors.world.limbo.LimboBiomeSource;
import org.dimdev.dimdoors.world.limbo.LimboChunkGenerator;
import org.dimdev.dimdoors.world.pocket.BlankChunkGenerator;
import com.google.common.collect.ImmutableMap;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.BlockTags;

View file

@ -1,6 +1,7 @@
package org.dimdev.dimdoors.world.feature;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.world.feature.gateway.LimboGatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SandstonePillarsV2Gateway;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2Gateway;
@ -10,10 +11,13 @@ import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2GatewayFea
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.SingleStateFeatureConfig;
import net.fabricmc.loader.api.FabricLoader;
@ -23,11 +27,13 @@ public final class ModFeatures {
public static final SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsV2Gateway();
public static final ConfiguredFeature<?, ?> SANDSTONE_PILLARS_FEATURE;
public static final ConfiguredFeature<?, ?> LIMBO_GATEWAY_CONFIGURED_FEATURE;
public static ConfiguredFeature<?, ?> ETERNAL_FLUID_LAKE;
public static void init() {
SANDSTONE_PILLARS_GATEWAY.init();
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "limbo_gateway"), LIMBO_GATEWAY_CONFIGURED_FEATURE);
ETERNAL_FLUID_LAKE = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "eternal_fluid_lake"), Feature.LAKE.configure(new SingleStateFeatureConfig(ModBlocks.ETERNAL_FLUID.getDefaultState())).decorate(Decorator.RANGE.configure(new RangeDecoratorConfig(5, 70, 128)).applyChance(20)));
}
static {

View file

@ -2,10 +2,10 @@ package org.dimdev.dimdoors.world.limbo;
import java.util.Set;
import org.dimdev.dimdoors.world.ModBiomes;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.world.ModBiomes;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;

View file

@ -9,11 +9,11 @@ import java.util.stream.IntStream;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.mixin.ChunkGeneratorAccessor;
import org.dimdev.dimdoors.world.ModDimensions;
import org.jetbrains.annotations.Nullable;
import com.mojang.serialization.Codec;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -376,29 +376,21 @@ public class LimboChunkGenerator extends ChunkGenerator {
}
}
this.buildFluid(chunk, chunkRandom);
this.buildAncientFabricFloor(chunk, chunkRandom);
}
private void buildFluid(Chunk chunk, Random random) {
private void buildAncientFabricFloor(Chunk chunk, Random random) {
BlockPos.Mutable mutable = new BlockPos.Mutable();
int i = chunk.getPos().getStartX();
int j = chunk.getPos().getStartZ();
ChunkGeneratorSettings chunkGeneratorSettings = this.settings.get();
int k = chunkGeneratorSettings.getBedrockFloorY();
boolean bl2 = k + 4 >= 0 && k < this.worldHeight;
int startX = chunk.getPos().getStartX();
int startZ = chunk.getPos().getStartZ();
ChunkGeneratorSettings settings = this.settings.get();
int bedrockFloorY = settings.getBedrockFloorY();
boolean bl2 = bedrockFloorY + 4 >= 0 && bedrockFloorY < this.worldHeight;
if (bl2) {
Iterator<BlockPos> iterator = BlockPos.iterate(i, 0, j, i + 15, 0, j + 15).iterator();
while (true) {
BlockPos blockPos;
int o;
if (!iterator.hasNext()) {
return;
}
blockPos = iterator.next();
for (o = 4; o >= 0; --o) {
for (BlockPos blockPos : BlockPos.iterate(startX, 0, startZ, startX + 15, 0, startZ + 15)) {
for (int o = 4; o >= 0; --o) {
if (o <= random.nextInt(5)) {
chunk.setBlockState(mutable.set(blockPos.getX(), k + o, blockPos.getZ()), ModBlocks.ETERNAL_FLUID.getDefaultState(), false);
chunk.setBlockState(mutable.set(blockPos.getX(), bedrockFloorY + o, blockPos.getZ()), ModBlocks.BLACK_ANCIENT_FABRIC.getDefaultState(), false);
}
}
}
@ -406,8 +398,8 @@ public class LimboChunkGenerator extends ChunkGenerator {
}
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
ObjectList<StructurePiece> objectList = new ObjectArrayList<>(10);
ObjectList<JigsawJunction> objectList2 = new ObjectArrayList<>(32);
ObjectList<StructurePiece> structurePieces = new ObjectArrayList<>(10);
ObjectList<JigsawJunction> jigsawJunctions = new ObjectArrayList<>(32);
ChunkPos chunkPos = chunk.getPos();
int posX = chunkPos.x;
int posZ = chunkPos.z;
@ -431,18 +423,18 @@ public class LimboChunkGenerator extends ChunkGenerator {
PoolStructurePiece poolStructurePiece = (PoolStructurePiece) structurePiece;
StructurePool.Projection projection = poolStructurePiece.getPoolElement().getProjection();
if (projection == StructurePool.Projection.RIGID) {
objectList.add(poolStructurePiece);
structurePieces.add(poolStructurePiece);
}
for (JigsawJunction jigsawJunction : poolStructurePiece.getJunctions()) {
int kx = jigsawJunction.getSourceX();
int lx = jigsawJunction.getSourceZ();
if (kx > k - 12 && lx > l - 12 && kx < k + 15 + 12 && lx < l + 15 + 12) {
objectList2.add(jigsawJunction);
jigsawJunctions.add(jigsawJunction);
}
}
} else {
objectList.add(structurePiece);
structurePieces.add(structurePiece);
}
}
});
@ -460,8 +452,8 @@ public class LimboChunkGenerator extends ChunkGenerator {
Heightmap heightmap = protoChunk.getHeightmap(Heightmap.Type.OCEAN_FLOOR_WG);
Heightmap heightmap2 = protoChunk.getHeightmap(Heightmap.Type.WORLD_SURFACE_WG);
BlockPos.Mutable mutable = new BlockPos.Mutable();
ObjectListIterator<StructurePiece> objectListIterator = objectList.iterator();
ObjectListIterator<JigsawJunction> objectListIterator2 = objectList2.iterator();
ObjectListIterator<StructurePiece> objectListIterator = structurePieces.iterator();
ObjectListIterator<JigsawJunction> objectListIterator2 = jigsawJunctions.iterator();
for (int n = 0; n < this.noiseSizeX; ++n) {
int p;
@ -524,7 +516,7 @@ public class LimboChunkGenerator extends ChunkGenerator {
ar = Math.max(0, Math.max(blockBox.minZ - ak, ak - blockBox.maxZ));
}
objectListIterator.back(objectList.size());
objectListIterator.back(structurePieces.size());
while (objectListIterator2.hasNext()) {
JigsawJunction jigsawJunction = objectListIterator2.next();
@ -534,7 +526,7 @@ public class LimboChunkGenerator extends ChunkGenerator {
ao += getNoiseWeight(as, at, au) * 0.4D;
}
objectListIterator2.back(objectList2.size());
objectListIterator2.back(jigsawJunctions.size());
BlockState blockState = this.getBlockState(ao, v);
if (blockState != Blocks.AIR.getDefaultState()) {
if (blockState.getLuminance() != 0) {
@ -573,7 +565,7 @@ public class LimboChunkGenerator extends ChunkGenerator {
public void populateEntities(ChunkRegion region) {
int i = region.getCenterChunkX();
int j = region.getCenterChunkZ();
Biome biome = region.getBiome((new ChunkPos(i, j)).getStartPos());
Biome biome = region.getBiome(new ChunkPos(i, j).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), i << 4, j << 4);
SpawnHelper.populateEntities(region, biome, i, j, chunkRandom);

View file

@ -6,14 +6,6 @@ import java.util.Random;
import java.util.function.BiConsumer;
import org.dimdev.dimdoors.ModConfig;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import static net.minecraft.block.Blocks.*;
import static org.dimdev.dimdoors.block.ModBlocks.DETACHED_RIFT;
import static org.dimdev.dimdoors.block.ModBlocks.DIMENSIONAL_PORTAL;
import static org.dimdev.dimdoors.block.ModBlocks.ETERNAL_FLUID;
@ -24,6 +16,14 @@ import static org.dimdev.dimdoors.block.ModBlocks.OAK_DIMENSIONAL_DOOR;
import static org.dimdev.dimdoors.block.ModBlocks.QUARTZ_DOOR;
import static org.dimdev.dimdoors.block.ModBlocks.UNRAVELLED_FABRIC;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import static net.minecraft.block.Blocks.*;
/**
* Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo
* naturally change into stone, then cobble, then gravel, and finally Unraveled Fabric as time passes.

View file

@ -1,11 +1,10 @@
package org.dimdev.dimdoors.world.pocket;
import org.dimdev.dimdoors.util.Codecs;
import org.dimdev.dimdoors.util.EntityUtils;
import com.flowpowered.math.vector.Vector3i;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.util.Codecs;
import org.dimdev.dimdoors.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.text.TranslatableText;
@ -29,17 +28,11 @@ public final class Pocket {
});
private static final int BLOCKS_PAINTED_PER_DYE = 1106;
@Saved
public final int id;
@Saved
public BlockBox box;
@Saved
public VirtualLocation virtualLocation;
@Saved
public PocketColor dyeColor = PocketColor.WHITE;
@Saved
public PocketColor nextDyeColor = PocketColor.NONE;
@Saved
public int count = 0;
public RegistryKey<World> world;

View file

@ -3,13 +3,12 @@ package org.dimdev.dimdoors.world.pocket;
import java.util.HashMap;
import java.util.Map;
import com.mojang.serialization.Codec;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.NbtUtil;
import org.dimdev.dimdoors.util.WorldUtil;
import org.dimdev.dimdoors.util.math.GridUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import com.mojang.serialization.Codec;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
@ -23,11 +22,11 @@ public class PocketRegistry extends PersistentState {
private static final String DATA_NAME = "pocketlib_pockets";
@Saved /*package-private*/ int gridSize; // Determines how much pockets in their dimension are spaced
@Saved /*package-private*/ int privatePocketSize;
@Saved /*package-private*/ int publicPocketSize;
@Saved /*package-private*/ Map<Integer, Pocket> pockets;
@Saved /*package-private*/ int nextID;
/*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;
private ServerWorld world;

View file

@ -2,13 +2,12 @@ package org.dimdev.dimdoors.world.pocket;
import java.util.UUID;
import org.dimdev.dimdoors.util.NbtUtil;
import org.dimdev.dimdoors.util.WorldUtil;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.util.NbtUtil;
import org.dimdev.dimdoors.util.WorldUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.dynamic.DynamicSerializableUuid;
@ -27,9 +26,7 @@ public class PrivatePocketData extends PersistentState {
).apply(instance, PocketInfo::new);
});
@Saved
public final RegistryKey<World> world;
@Saved
public final int id;
public PocketInfo(RegistryKey<World> world, int id) {
@ -42,7 +39,6 @@ public class PrivatePocketData extends PersistentState {
private static final String DATA_NAME = "dimdoors_private_pockets";
@Saved
protected BiMap<UUID, PocketInfo> privatePocketMap = HashBiMap.create(); // Player UUID -> Pocket Info TODO: fix AnnotatedNBT and use UUID rather than String
public PrivatePocketData(String name) {

View file

@ -1,14 +1,14 @@
package org.dimdev.dimdoors.world.pocket;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.annotatednbt.AnnotatedNbt;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.world.ModDimensions;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
@ -27,14 +27,10 @@ public class VirtualLocation {
).apply(instance, VirtualLocation::new)
);
public final RegistryKey<World> world;
public final int x;
public final int z;
public final int depth;
private RegistryKey<World> world;
private int x;
private int z;
private int depth;
public VirtualLocation(RegistryKey<World> world, int x, int z, int depth) {
this.world = world;
@ -43,13 +39,20 @@ public class VirtualLocation {
this.depth = depth;
}
public void fromTag(CompoundTag nbt) {
AnnotatedNbt.load(this, nbt);
public void fromTag(CompoundTag tag) {
VirtualLocation location = CODEC.decode(NbtOps.INSTANCE, tag).getOrThrow(false, System.err::println).getFirst();
this.x = location.x;
this.z = location.z;
this.depth = location.depth;
this.world = location.world;
}
public CompoundTag toTag(CompoundTag nbt) {
AnnotatedNbt.save(this, nbt);
return nbt;
public CompoundTag toTag(CompoundTag tag) {
CompoundTag encodedTag = (CompoundTag) CODEC.encodeStart(NbtOps.INSTANCE, this).getOrThrow(false, System.err::println);
for (String key : encodedTag.getKeys()) {
tag.put(key, encodedTag.get(key));
}
return tag;
}
public static VirtualLocation fromLocation(Location location) {
@ -86,4 +89,20 @@ public class VirtualLocation {
BlockPos pos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, new BlockPos(newX, 0, newZ));
return new Location(world, pos);
}
public RegistryKey<World> getWorld() {
return this.world;
}
public int getX() {
return this.x;
}
public int getZ() {
return this.z;
}
public int getDepth() {
return this.depth;
}
}