Merge pull request #176 from BoogieMonster1O1/1.16-fabric

Pocket generation for v2 schematics
This commit is contained in:
Waterpicker 2020-10-03 05:34:26 -05:00 committed by GitHub
commit 53bc3806a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 1040 additions and 2155 deletions

View file

@ -1,5 +1,5 @@
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.1
yarn_mappings=1.16.3+build.26
loader_version=0.9.3+build.207
fabric_version=0.21.0+build.407-1.16

File diff suppressed because one or more lines are too long

View file

@ -2,13 +2,14 @@ package org.dimdev.dimdoors;
import java.io.IOException;
import org.dimdev.dimcore.schematic.v2.SchematicTest;
import org.dimdev.dimdoors.util.schematic.v2.SchematicTest;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.command.ModCommands;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import org.dimdev.dimdoors.pockets.SchematicV2Handler;
import org.dimdev.dimdoors.rift.targets.Targets;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.world.ModBiomes;
@ -36,7 +37,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
if (server != null) {
return server;
}
throw new IllegalStateException("Accessed server too early!");
throw new UnsupportedOperationException("Accessed server too early!");
}
public static ServerWorld getWorld(RegistryKey<World> key) {
@ -70,6 +71,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
Targets.registerDefaultTargets();
SchematicV2Handler.getInstance().load();
SchematicHandler.INSTANCE.loadSchematics();
}
}

View file

@ -11,6 +11,8 @@ import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.util.Codecs;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
@ -21,6 +23,7 @@ import net.fabricmc.loader.api.FabricLoader;
public final class ModConfig {
public static ModConfig INSTANCE;
private static final Path CONFIG_PATH;
private static final Gson GSON;
private static final Codec<ModConfig> CODEC;
private static final String DEFAULT;
private static final ModConfig FALLBACK;
@ -33,7 +36,7 @@ public final class ModConfig {
private final Limbo limbo;
private final Graphics graphics;
protected ModConfig(General general, Pockets pockets, World world, Dungeons dungeons, Monoliths monoliths, Limbo limbo, Graphics graphics) {
private ModConfig(General general, Pockets pockets, World world, Dungeons dungeons, Monoliths monoliths, Limbo limbo, Graphics graphics) {
this.general = general;
this.pockets = pockets;
this.world = world;
@ -247,7 +250,7 @@ public final class ModConfig {
).getOrThrow(false, System.err::println).getFirst();
return 1;
} catch (IOException e) {
System.err.println("An Unexpected error occured when deserializing the Config. Using default values for now.");
LOGGER.error("An Unexpected error occured when deserializing the Config. Using default values for now.");
e.printStackTrace();
INSTANCE = FALLBACK;
return -1;
@ -265,6 +268,7 @@ public final class ModConfig {
Graphics.CODEC.fieldOf("graphics").forGetter(ModConfig::getGraphicsConfig)
).apply(instance, ModConfig::new));
CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("dimensional_doors.json");
GSON = new GsonBuilder().setLenient().setPrettyPrinting().create();
FALLBACK = new ModConfig(
new General(),
new Pockets(),
@ -275,9 +279,7 @@ public final class ModConfig {
new Graphics()
);
INSTANCE = FALLBACK;
DEFAULT = CODEC.encodeStart(JsonOps.INSTANCE, INSTANCE)
.getOrThrow(false, System.err::println)
.toString();
LOGGER = LogManager.getLogger();
DEFAULT = GSON.toJson(CODEC.encodeStart(JsonOps.INSTANCE, INSTANCE).getOrThrow(false, System.err::println));
LOGGER = LogManager.getLogger(ModConfig.class);
}
}

View file

@ -35,7 +35,7 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
BlockState doorState = world.getBlockState(state.get(HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos);
if (doorState.getBlock() == this && doorState.get(DoorBlock.OPEN)) { // '== this' to check if not half-broken
getRift(world, pos, state).teleport(entity);
this.getRift(world, pos, state).teleport(entity);
}
}
@ -43,7 +43,7 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
state = state.cycle(OPEN);
world.setBlockState(pos, state, 10);
world.syncWorldEvent(player, state.get(OPEN) ? material == Material.METAL ? 1005 : 1006 : material == Material.METAL ? 1011 : 1012, pos, 0);
world.syncWorldEvent(player, state.get(OPEN) ? this.material == Material.METAL ? 1005 : 1006 : this.material == Material.METAL ? 1011 : 1012, pos, 0);
return ActionResult.SUCCESS;
}

View file

@ -1,11 +1,15 @@
package org.dimdev.dimdoors.block;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
@ -29,4 +33,15 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (world.isClient) {
return;
}
if (ModDimensions.isLimboDimension(entity.getEntityWorld())) {
TeleportUtil.teleport(entity, DimensionalDoorsInitializer.getWorld(World.OVERWORLD), entity.getPos().subtract(0, entity.getPos().y, 0).add(0, 384, 0), 0);
}
super.onEntityCollision(state, world, pos, entity);
}
}

View file

@ -27,7 +27,7 @@ public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvi
@SuppressWarnings("deprecation")
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (!world.isClient && state.get(TrapdoorBlock.OPEN)) {
getRift(world, pos, state).teleport(entity);
this.getRift(world, pos, state).teleport(entity);
}
}
@ -46,7 +46,7 @@ public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvi
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
playToggleSound(player, world, pos, state.get(OPEN));
this.playToggleSound(player, world, pos, state.get(OPEN));
return ActionResult.SUCCESS;
}

View file

@ -1,9 +1,6 @@
package org.dimdev.dimdoors.block.entity;
import java.util.Random;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.RGBA;
import org.dimdev.dimdoors.util.TeleportUtil;
import net.minecraft.block.BlockState;
@ -11,10 +8,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class EntranceRiftBlockEntity extends RiftBlockEntity {
public EntranceRiftBlockEntity() {
@ -27,9 +20,9 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
}
@Override
public CompoundTag toTag(CompoundTag nbt) {
nbt = super.toTag(nbt);
return nbt;
public CompoundTag toTag(CompoundTag tag) {
tag = super.toTag(tag);
return tag;
}
@Override
@ -51,36 +44,7 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
}
public Direction getOrientation() {
return Direction.NORTH; // TODO
}
@Environment(EnvType.CLIENT)
public RGBA[] getColors(int count) {
Random rand = new Random(31100L);
float[][] colors = new float[count][];
for (int i = 0; i < count; i++) {
colors[i] = this.getEntranceRenderColor(rand);
}
return RGBA.fromFloatArrays(colors);
}
@Environment(EnvType.CLIENT)
protected float[] getEntranceRenderColor(Random rand) {
float red, green, blue;
if (this.world.getRegistryKey() == World.NETHER) {
red = rand.nextFloat() * 0.5F + 0.4F;
green = rand.nextFloat() * 0.05F;
blue = rand.nextFloat() * 0.05F;
} else {
red = rand.nextFloat() * 0.5F + 0.1F;
green = rand.nextFloat() * 0.4F + 0.4F;
blue = rand.nextFloat() * 0.6F + 0.5F;
}
return new float[]{red, green, blue, 1};
return Direction.NORTH;
}
@Override

View file

@ -65,7 +65,7 @@ public class ModRendering {
*/
@Override
public void apply(ResourceManager resourceManager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}

View file

@ -3,8 +3,8 @@ package org.dimdev.dimdoors.command;
import java.io.IOException;
import java.io.InputStream;
import org.dimdev.dimcore.schematic.Schematic;
import org.dimdev.dimcore.schematic.SchematicConverter;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.util.schematic.SchematicConverter;
import org.dimdev.dimdoors.command.arguments.SchematicNamespaceArgumentType;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;

View file

@ -5,8 +5,8 @@ import java.io.InputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimcore.schematic.v2.Schematic;
import org.dimdev.dimcore.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.util.schematic.v2.Schematic;
import org.dimdev.dimdoors.util.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.command.arguments.SchematicNamespaceArgumentType;
import com.mojang.brigadier.CommandDispatcher;

View file

@ -11,7 +11,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
public class GroupArugmentType implements ArgumentType<String> {
@Override

View file

@ -10,7 +10,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
public class NameArugmentType implements ArgumentType<String> {
@Override

View file

@ -13,7 +13,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.text.TranslatableText;
public class SchematicNamespaceArgumentType implements ArgumentType<String> {

View file

@ -2,13 +2,13 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.rift.targets.RiftReference;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.RotatedLocation;
import org.dimdev.dimdoors.util.WorldUtil;
import org.jetbrains.annotations.NotNull;
import net.minecraft.client.item.TooltipContext;
@ -80,7 +80,7 @@ public class RiftSignatureItem extends Item {
clearSource(stack); // TODO: But is this fair? It's a rather hidden way of unbinding your signature!
return ActionResult.FAIL;
}
World sourceWorld = WorldUtil.getWorld(target.world);
World sourceWorld = DimensionalDoorsInitializer.getWorld(target.world);
sourceWorld.setBlockState(target.getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity();
rift1.setDestination(RiftReference.tryMakeRelative(target, new Location((ServerWorld) world, pos)));

View file

@ -2,13 +2,13 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.rift.targets.RiftReference;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.RotatedLocation;
import org.dimdev.dimdoors.util.WorldUtil;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
@ -75,7 +75,7 @@ public class StabilizedRiftSignatureItem extends Item { // TODO: common supercla
// Don't clear source, stabilized signatures always stay bound
return ActionResult.FAIL;
}
World targetWorld = WorldUtil.getWorld(target.world);
World targetWorld = DimensionalDoorsInitializer.getWorld(target.world);
targetWorld.setBlockState(target.getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity();
rift1.register();

View file

@ -0,0 +1,55 @@
package org.dimdev.dimdoors.mixin;
import java.util.Objects;
import org.dimdev.dimdoors.util.EntityExtensions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
@Mixin(Entity.class)
public class EntityMixin implements EntityExtensions {
@Shadow
public World world;
@Unique
private boolean dimdoors_readyToTeleport = false;
private TeleportTarget dimdoors_teleportTarget = null;
@Inject(at = @At("HEAD"), cancellable = true, method = "getTeleportTarget")
public void interceptTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> cir) {
if (destination.getRegistryKey().getValue().getNamespace().equals("dimdoors")) {
if (this.dimdoors_isReadyToTeleport()) {
cir.setReturnValue(Objects.requireNonNull(this.dimdoors_teleportTarget));
}
}
}
@Inject(at = @At("TAIL"), method = "moveToWorld")
public void cleanup(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> cir) {
this.dimdoors_teleportTarget = null;
this.dimdoors_setReadyToTeleport(false);
}
@Override
public boolean dimdoors_isReadyToTeleport() {
return this.dimdoors_readyToTeleport;
}
@Override
public void dimdoors_setReadyToTeleport(boolean value) {
this.dimdoors_readyToTeleport = value;
}
@Override
public void dimdoors_setTeleportTarget(TeleportTarget target) {
this.dimdoors_teleportTarget = target;
}
}

View file

@ -0,0 +1,16 @@
package org.dimdev.dimdoors.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.block.enums.WireConnection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
@Mixin(RedstoneWireBlock.class)
public interface RedstoneWireBlockAccessor {
@Invoker
WireConnection invokeGetRenderConnectionType(BlockView blockView, BlockPos blockPos, Direction direction);
}

View file

@ -10,59 +10,58 @@ import org.dimdev.dimdoors.rift.targets.RandomTarget;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
public final class DefaultDungeonDestinations { // TODO: lower weights?
public static final LinkProperties pocketLinkProperties = LinkProperties
.builder()
public static final LinkProperties POCKET_LINK_PROPERTIES = LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.linksRemaining(1).build();
.linksRemaining(1)
.build();
public static final LinkProperties overworldLinkProperties = LinkProperties
.builder()
public static final LinkProperties OVERWORLD_LINK_PROPERTIES = LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.entranceWeight(50)
.linksRemaining(1).build();
.linksRemaining(1)
.build();
public static final VirtualTarget deeperDungeonDestination = RandomTarget
.builder()
public static final VirtualTarget DEEPER_DUNGEON_DESTINATION = RandomTarget.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(10000)
.positiveDepthFactor(160)
.weightMaximum(100)
.newRiftWeight(1).build();
.newRiftWeight(1)
.build();
public static final VirtualTarget shallowerDungeonDestination = RandomTarget
.builder()
public static final VirtualTarget SHALLOWER_DUNGEON_DESTINATION = RandomTarget.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(160)
.positiveDepthFactor(10000)
.weightMaximum(100)
.newRiftWeight(1).build();
.newRiftWeight(1)
.build();
public static final VirtualTarget overworldDestination = RandomTarget
.builder()
public static final VirtualTarget OVERWORLD_DESTINATION = RandomTarget.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(0.00000000001) // The division result is cast to an int, so Double.MIN_VALUE would cause an overflow
.positiveDepthFactor(Double.POSITIVE_INFINITY)
.weightMaximum(100)
.newRiftWeight(1).build();
.newRiftWeight(1)
.build();
public static final VirtualTarget twoWayPocketEntrance = PocketEntranceMarker
.builder()
public static final VirtualTarget TWO_WAY_POCKET_ENTRANCE = PocketEntranceMarker.builder()
.weight(1)
.ifDestination(new PocketEntranceMarker())
.otherwiseDestination(RandomTarget
.builder()
.otherwiseDestination(RandomTarget.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1)
.negativeDepthFactor(80)
.positiveDepthFactor(10000)
.weightMaximum(100)
.newRiftWeight(1).build()).build();
.newRiftWeight(1)
.build())
.build();
public static final VirtualTarget gatewayDestination = RandomTarget
.builder()
public static final VirtualTarget GATEWAY_DESTINATION = RandomTarget.builder()
.acceptedGroups(Collections.singleton(0))
.coordFactor(1) // TODO: lower value?
.negativeDepthFactor(Double.POSITIVE_INFINITY)

View file

@ -4,10 +4,10 @@ import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.util.WorldUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
@ -21,33 +21,67 @@ public final class PocketGenerator {
private static Pocket prepareAndPlacePocket(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
LOGGER.info("Generating pocket from template " + pocketTemplate.getId() + " at virtual location " + virtualLocation);
Pocket pocket = PocketRegistry.instance(world.getRegistryKey()).newPocket();
Pocket pocket = PocketRegistry.getInstance(world.getRegistryKey()).newPocket();
pocketTemplate.place(pocket, setup);
pocket.virtualLocation = virtualLocation;
return pocket;
}
private static Pocket prepareAndPlaceV2Pocket(ServerWorld world, PocketTemplateV2 pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
LOGGER.info("Generating pocket from template " + pocketTemplate.getId() + " at virtual location " + virtualLocation);
Pocket pocket = PocketRegistry.getInstance(world.getRegistryKey()).newPocket();
pocketTemplate.place(pocket);
pocket.virtualLocation = virtualLocation;
return pocket;
}
public static Pocket generatePocketFromTemplate(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
Pocket pocket = prepareAndPlacePocket(world, pocketTemplate, virtualLocation, setup);
if (setup) pocketTemplate.setup(pocket, null, null);
return pocket;
}
public static Pocket generateV2PocketFromTemplate(ServerWorld world, PocketTemplateV2 pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
Pocket pocket = prepareAndPlaceV2Pocket(world, pocketTemplate, virtualLocation, setup);
if (setup) {
pocketTemplate.setup(pocket, null, null);
}
return pocket;
}
public static Pocket generatePocketFromTemplate(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
Pocket pocket = prepareAndPlacePocket(world, pocketTemplate, virtualLocation, true);
pocketTemplate.setup(pocket, linkTo, linkProperties);
return pocket;
}
public static Pocket generateV2PocketFromTemplate(ServerWorld world, PocketTemplateV2 pocketTemplate, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
Pocket pocket = prepareAndPlaceV2Pocket(world, pocketTemplate, virtualLocation, true);
pocketTemplate.setup(pocket, linkTo, linkProperties);
return pocket;
}
public static Pocket generatePrivatePocket(VirtualLocation virtualLocation) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate();
return generatePocketFromTemplate(WorldUtil.getWorld(ModDimensions.PERSONAL), pocketTemplate, virtualLocation, true);
return generatePocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.PERSONAL), pocketTemplate, virtualLocation, true);
}
public static Pocket generatePrivatePocketV2(VirtualLocation virtualLocation) {
PocketTemplateV2 pocketTemplate = SchematicV2Handler.getInstance().getRandomPrivatePocket();
return generateV2PocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.PERSONAL), pocketTemplate, virtualLocation, true);
}
// TODO: size of public pockets should increase with depth
public static Pocket generatePublicPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPublicPocketTemplate();
return generatePocketFromTemplate(WorldUtil.getWorld(ModDimensions.PUBLIC), pocketTemplate, virtualLocation, linkTo, linkProperties);
return generatePocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.PUBLIC), pocketTemplate, virtualLocation, linkTo, linkProperties);
}
public static Pocket generatePublicPocketV2(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
PocketTemplateV2 pocketTemplate = SchematicV2Handler.getInstance().getRandomPublicPocket();
return generateV2PocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.PUBLIC), pocketTemplate, virtualLocation, linkTo, linkProperties);
}
/**
@ -58,11 +92,11 @@ public final class PocketGenerator {
*/
public static Pocket generateDungeonPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
int depth = virtualLocation.getDepth();
float netherProbability = WorldUtil.getWorld(virtualLocation.getWorld()).getDimension().isUltrawarm() ? 1 : (float) depth / 200; // TODO: improve nether probability
float netherProbability = DimensionalDoorsInitializer.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);
return generatePocketFromTemplate(WorldUtil.getWorld(ModDimensions.DUNGEON), pocketTemplate, virtualLocation, linkTo, linkProperties);
return generatePocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.DUNGEON), pocketTemplate, virtualLocation, linkTo, linkProperties);
}
}

View file

@ -1,25 +1,18 @@
package org.dimdev.dimdoors.pockets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimcore.schematic.Schematic;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.entity.MonolithEntity;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.rift.targets.PocketEntranceMarker;
import org.dimdev.dimdoors.rift.targets.PocketExitMarker;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.util.Location;
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.PocketRegistry;
@ -28,12 +21,8 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
/**
@ -78,9 +67,9 @@ public class PocketTemplate {
public float getWeight(int depth) {
if (depth == -1) {
return baseWeight;
return this.baseWeight;
} else {
return baseWeight; // TODO: make this actually dependend on the depth
return this.baseWeight; // TODO: make this actually dependend on the depth
}
}
@ -101,32 +90,32 @@ public class PocketTemplate {
switch (tileEntityNBT.getString("placeholder")) {
case "deeper_depth_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.deeperDungeonDestination);
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.DEEPER_DUNGEON_DESTINATION);
newNBT = rift.toTag(newNBT);
break;
case "less_deep_depth_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.shallowerDungeonDestination);
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.SHALLOWER_DUNGEON_DESTINATION);
newNBT = rift.toTag(newNBT);
break;
case "overworld_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.overworldDestination);
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.OVERWORLD_DESTINATION);
newNBT = rift.toTag(newNBT);
break;
case "entrance_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.twoWayPocketEntrance);
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.TWO_WAY_POCKET_ENTRANCE);
newNBT = rift.toTag(newNBT);
break;
case "gateway_portal":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.overworldLinkProperties);
rift.setDestination(DefaultDungeonDestinations.gatewayDestination);
rift.setProperties(DefaultDungeonDestinations.OVERWORLD_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.GATEWAY_DESTINATION);
newNBT = rift.toTag(newNBT);
break;
default:
@ -139,73 +128,50 @@ public class PocketTemplate {
}
}
schematic.tileEntities = tileEntities;
List<CompoundTag> entities = new ArrayList<>();
for (CompoundTag entitiesNBT : schematic.entities) {
if (entitiesNBT.contains("placeholder")) {
double x = entitiesNBT.getDouble("x");
double y = entitiesNBT.getDouble("y");
double z = entitiesNBT.getDouble("z");
float yaw = entitiesNBT.getFloat("yaw");
float pitch = entitiesNBT.getFloat("pitch");
CompoundTag newNBT;
if ("monolith".equals(entitiesNBT.getString("placeholder"))) {
MonolithEntity monolith = ModEntityTypes.MONOLITH.create(null);
monolith.setPos(x, y, z);
monolith.yaw = yaw;
monolith.pitch = pitch;
newNBT = monolith.toTag(new CompoundTag());
} else {
throw new RuntimeException("Unknown entity placeholder: " + entitiesNBT.getString("placeholder"));
}
// TODO: allow overriding some placeholder properties by copying other properties (not placeholder and x/y/z) to the new nbt
entities.add(newNBT);
} else {
entities.add(entitiesNBT);
}
TemplateUtils.setupEntityPlaceholders(entities, entitiesNBT);
}
schematic.entities = entities;
isReplacingPlaceholders = false;
}
public void place(Pocket pocket, boolean setup) {
pocket.setSize(size * 16, size * 16, size * 16);
int gridSize = PocketRegistry.instance(pocket.world).getGridSize();
ServerWorld world = WorldUtil.getWorld(pocket.world);
pocket.setSize(this.size * 16, this.size * 16, this.size * 16);
int gridSize = PocketRegistry.getInstance(pocket.world).getGridSize();
ServerWorld world = DimensionalDoorsInitializer.getWorld(pocket.world);
int xBase = pocket.box.minX;
int yBase = pocket.box.minY;
int zBase = pocket.box.minZ;
//Converting the schematic from bytearray if needed
if (schematic == null) {
if (this.schematic == null) {
LOGGER.debug("Schematic is null, trying to reload from byteArray.");
schematic = SchematicHandler.INSTANCE.loadSchematicFromByteArray(schematicBytecode);
replacePlaceholders(schematic);
this.schematic = SchematicHandler.INSTANCE.loadSchematicFromByteArray(this.schematicBytecode);
replacePlaceholders(this.schematic);
}
//Place the schematic
LOGGER.info("Placing new pocket using schematic " + id + " at x = " + xBase + ", z = " + zBase);
schematic.place(world, xBase, yBase, zBase);
LOGGER.info("Placing new pocket using schematic " + this.id + " at x = " + xBase + ", z = " + zBase);
this.schematic.place(world, xBase, yBase, zBase);
SchematicHandler.INSTANCE.incrementUsage(this);
if (!setup && !SchematicHandler.INSTANCE.isUsedOftenEnough(this)) {
//remove schematic from "cache"
schematic = null;
this.schematic = null;
}
}
public void setup(Pocket pocket, VirtualTarget linkTo, LinkProperties linkProperties) {
int gridSize = PocketRegistry.instance(pocket.world).getGridSize();
ServerWorld world = WorldUtil.getWorld(pocket.world);
int gridSize = PocketRegistry.getInstance(pocket.world).getGridSize();
ServerWorld world = DimensionalDoorsInitializer.getWorld(pocket.world);
int xBase = pocket.box.minX;
int yBase = pocket.box.minY;
int zBase = pocket.box.minZ;
// Fill chests and make rift list
List<RiftBlockEntity> rifts = new ArrayList<>();
for (CompoundTag tileEntityNBT : schematic.tileEntities) {
for (CompoundTag tileEntityNBT : this.schematic.tileEntities) {
BlockPos pos = new BlockPos(
xBase + tileEntityNBT.getInt("x"),
yBase + tileEntityNBT.getInt("y"),
@ -226,16 +192,7 @@ public class PocketTemplate {
Inventory inventory = (Inventory) tile;
if (inventory.isEmpty()) {
if (tile instanceof ChestBlockEntity || tile instanceof DispenserBlockEntity) {
LootTable table;
if (tile instanceof ChestBlockEntity) {
LOGGER.debug("Now populating chest.");
table = world.getServer().getLootManager().getTable(new Identifier("dimdoors:dungeon_chest"));
} else { //(tile instanceof TileEntityDispenser)
LOGGER.debug("Now populating dispenser.");
table = world.getServer().getLootManager().getTable(new Identifier("dimdoors:dispenser_projectiles"));
}
LootContext ctx = new LootContext.Builder(world).random(world.random).build(LootContextTypes.CHEST);
table.supplyInventory(inventory, ctx);
TemplateUtils.setupLootTable(world, tile, inventory, LOGGER);
LOGGER.debug("Inventory should be populated now. Chest is: " + (inventory.isEmpty() ? "empty." : "filled."));
if (inventory.isEmpty()) {
LOGGER.error(", however Inventory is: empty!");
@ -244,89 +201,45 @@ public class PocketTemplate {
}
}
}
// Find an entrance
HashMap<RiftBlockEntity, Float> entranceWeights = new HashMap<>();
for (RiftBlockEntity rift : rifts) { // Find an entrance
if (rift.getDestination() instanceof PocketEntranceMarker) {
entranceWeights.put(rift, ((PocketEntranceMarker) rift.getDestination()).getWeight());
}
}
if (entranceWeights.size() == 0) {
LOGGER.warn("Pocket had no possible entrance in schematic!");
return;
}
RiftBlockEntity selectedEntrance = MathUtil.weightedRandom(entranceWeights);
// Replace entrances with appropriate destinations
for (RiftBlockEntity rift : rifts) {
VirtualTarget dest = rift.getDestination();
if (dest instanceof PocketEntranceMarker) {
if (rift == selectedEntrance) {
PocketRegistry.instance(world.getRegistryKey()).markDirty();
rift.setDestination(((PocketEntranceMarker) dest).getIfDestination());
rift.register();
RiftRegistry.instance().addPocketEntrance(pocket, new Location((ServerWorld) rift.getWorld(), rift.getPos()));
} else {
rift.setDestination(((PocketEntranceMarker) dest).getOtherwiseDestination());
}
}
}
// Link pocket exits back
for (RiftBlockEntity rift : rifts) {
VirtualTarget dest = rift.getDestination();
if (dest instanceof PocketExitMarker) {
if (linkProperties != null) rift.setProperties(linkProperties);
rift.setDestination(rift.getProperties() == null || !rift.getProperties().oneWay ? linkTo : null);
}
}
// register the rifts
for (RiftBlockEntity rift : rifts) {
rift.register();
rift.markDirty();
}
TemplateUtils.registerRifts(rifts, linkTo, linkProperties, pocket);
if (!SchematicHandler.INSTANCE.isUsedOftenEnough(this)) {
//remove schematic from "cache"
schematic = null;
this.schematic = null;
}
}
public String getGroup() {
return group;
return this.group;
}
public String getId() {
return id;
return this.id;
}
public String getType() {
return type;
return this.type;
}
public String getName() {
return name;
return this.name;
}
public String getAuthor() {
return author;
return this.author;
}
public Schematic getSchematic() {
return schematic;
return this.schematic;
}
public int getSize() {
return size;
return this.size;
}
public int getBaseWeight() {
return baseWeight;
return this.baseWeight;
}
public void setSchematic(Schematic schematic) {

View file

@ -0,0 +1,161 @@
package org.dimdev.dimdoors.pockets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.util.schematic.v2.Schematic;
import org.dimdev.dimdoors.util.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.world.pocket.Pocket;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
public class PocketTemplateV2 {
private static final Logger LOGGER = LogManager.getLogger();
private static boolean replacingPlaceholders = false;
private final Schematic schematic;
private final String group;
private final int size;
private final String id;
public PocketTemplateV2(Schematic schematic, String group, int size, String id, float weight) {
this.schematic = schematic;
this.group = group;
this.size = size;
this.id = id;
}
public static void replacePlaceholders(Schematic schematic) {
// Replace placeholders (some schematics will contain them)
replacingPlaceholders = true;
List<CompoundTag> blockEntities = new ArrayList<>();
for (CompoundTag blockEntityTag : schematic.getBlockEntities()) {
if (blockEntityTag.contains("placeholder")) {
int x = blockEntityTag.getInt("x");
int y = blockEntityTag.getInt("y");
int z = blockEntityTag.getInt("z");
CompoundTag newTag = new CompoundTag();
EntranceRiftBlockEntity rift = Objects.requireNonNull(ModBlockEntityTypes.ENTRANCE_RIFT.instantiate());
switch (blockEntityTag.getString("placeholder")) {
case "deeper_depth_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.DEEPER_DUNGEON_DESTINATION);
newTag = rift.toTag(newTag);
break;
case "less_deep_depth_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.SHALLOWER_DUNGEON_DESTINATION);
newTag = rift.toTag(newTag);
break;
case "overworld_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.OVERWORLD_DESTINATION);
newTag = rift.toTag(newTag);
break;
case "entrance_door":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.TWO_WAY_POCKET_ENTRANCE);
newTag = rift.toTag(newTag);
break;
case "gateway_portal":
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.OVERWORLD_LINK_PROPERTIES);
rift.setDestination(DefaultDungeonDestinations.GATEWAY_DESTINATION);
newTag = rift.toTag(newTag);
break;
default:
throw new RuntimeException("Unknown block entity placeholder: " + blockEntityTag.getString("placeholder"));
}
blockEntities.add(newTag);
} else {
blockEntities.add(blockEntityTag);
}
}
schematic.setBlockEntities(blockEntities);
List<CompoundTag> entities = new ArrayList<>();
for (CompoundTag entityTag : schematic.getEntities()) {
TemplateUtils.setupEntityPlaceholders(entities, entityTag);
}
schematic.setEntities(entities);
replacingPlaceholders = false;
}
public void setup(Pocket pocket, VirtualTarget linkTo, LinkProperties linkProperties) {
ServerWorld world = DimensionalDoorsInitializer.getWorld(pocket.world);
List<RiftBlockEntity> rifts = new ArrayList<>();
for (CompoundTag blockEntityTag : this.schematic.getBlockEntities()) {
BlockPos pos = new BlockPos(
pocket.box.minX + blockEntityTag.getInt("x"),
pocket.box.minY + blockEntityTag.getInt("y"),
pocket.box.minZ + blockEntityTag.getInt("z")
);
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof RiftBlockEntity) {
LOGGER.debug("Rift found in schematic at " + pos);
RiftBlockEntity rift = (RiftBlockEntity) tile;
rift.getDestination().setLocation(new Location((ServerWorld) Objects.requireNonNull(rift.getWorld()), rift.getPos()));
rifts.add(rift);
} else if (tile instanceof Inventory) {
Inventory inventory = (Inventory) tile;
if (inventory.isEmpty()) {
if (tile instanceof ChestBlockEntity || tile instanceof DispenserBlockEntity) {
TemplateUtils.setupLootTable(world, tile, inventory, LOGGER);
if (inventory.isEmpty()) {
LOGGER.error(", however Inventory is: empty!");
}
}
}
}
}
TemplateUtils.registerRifts(rifts, linkTo, linkProperties, pocket);
}
public void place(Pocket pocket) {
pocket.setSize(this.size * 16, this.size * 16, this.size * 16);
ServerWorld world = DimensionalDoorsInitializer.getWorld(pocket.world);
BlockPos origin = new BlockPos(pocket.box.minX, pocket.box.minY, pocket.box.minZ);
LOGGER.info("Placing new pocket using schematic " + this.id + " at x = " + origin.getX() + ", z = " + origin.getZ());
SchematicPlacer.place(this.schematic, world, origin);
}
public static boolean isReplacingPlaceholders() {
return replacingPlaceholders;
}
public String getGroup() {
return this.group;
}
public Schematic getSchematic() {
return this.schematic;
}
public String getId() {
return this.id;
}
}

View file

@ -0,0 +1,104 @@
package org.dimdev.dimdoors.pockets;
import java.util.List;
import java.util.Objects;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public final class PocketType {
public static final Codec<PocketType> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("group").forGetter(PocketType::getGroup),
PocketEntry.CODEC.listOf().fieldOf("pockets").forGetter(PocketType::getEntries)
).apply(instance, PocketType::new));
private final String group;
private final List<PocketEntry> entries;
public PocketType(String group, List<PocketEntry> entries) {
this.group = group;
this.entries = entries;
}
public String getGroup() {
return this.group;
}
public List<PocketEntry> getEntries() {
return this.entries;
}
@Override
public String toString() {
return "PocketType{" +
"group='" + this.group + '\'' +
", entries=" + this.entries +
'}';
}
@Override
public boolean equals(Object o) {
if (super.equals(o)) return true;
if (o == null || this.getClass() != o.getClass()) return false;
PocketType that = (PocketType) o;
return Objects.equals(this.group, that.group) &&
Objects.equals(this.entries, that.entries);
}
@Override
public int hashCode() {
return Objects.hash(this.group, this.entries);
}
public static final class PocketEntry {
public static final Codec<PocketEntry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("size").forGetter(PocketEntry::getSize),
Codec.STRING.fieldOf("id").forGetter(PocketEntry::getName),
Codec.INT.optionalFieldOf("weight", 5).forGetter(PocketEntry::getWeight)
).apply(instance, PocketEntry::new));
private final int size;
private final String name;
private final int weight;
PocketEntry(int size, String name, int weight) {
this.size = size;
this.name = name;
this.weight = weight;
}
public int getSize() {
return this.size;
}
public String getName() {
return this.name;
}
public int getWeight() {
return this.weight;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
PocketEntry that = (PocketEntry) o;
return this.size == that.size &&
Float.compare(that.weight, this.weight) == 0 &&
this.name.equals(that.name);
}
@Override
public int hashCode() {
return Objects.hash(this.size, this.name, this.weight);
}
@Override
public String toString() {
return "PocketEntry{" +
"size=" + this.size +
", name='" + this.name + '\'' +
", weight=" + this.weight +
'}';
}
}
}

View file

@ -26,7 +26,7 @@ import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimcore.schematic.Schematic;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.math.MathUtil;
@ -46,6 +46,9 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
private static final String SAVED_POCKETS_GROUP_NAME = "saved_pockets";
public static final SchematicHandler INSTANCE = new SchematicHandler();
private SchematicHandler() {
}
private static String getFolder() {
return "config"; // TODO
}
@ -453,7 +456,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
PocketTemplate template2 = this.usageList.get(index).getKey();
if (index >= this.usageList.size() || template != template2) {
entry.setValue(this.usageList.size());
this.usageList.add(new SimpleEntry(template, 1));
this.usageList.add(new SimpleEntry<>(template, 1));
}
}
}

View file

@ -0,0 +1,108 @@
package org.dimdev.dimdoors.pockets;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.util.schematic.v2.Schematic;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.mojang.serialization.JsonOps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
public class SchematicV2Handler {
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = new GsonBuilder().setLenient().setPrettyPrinting().create();
private static final SchematicV2Handler INSTANCE = new SchematicV2Handler();
private final List<PocketTemplateV2> templates = Lists.newArrayList();
private final Multimap<String, PocketTemplateV2> templateMap = HashMultimap.create();
private final List<PocketType> pocketTypes = Lists.newArrayList();
private static final Random RANDOM = new Random(new Random().nextLong());
private boolean loaded = false;
private SchematicV2Handler() {
}
public void load() {
if (this.loaded){
throw new UnsupportedOperationException("Attempted to load schematics twice!");
}
this.loaded = true;
long startTime = System.currentTimeMillis();
Set<String> names = ImmutableSet.of("default_private", "default_public");
for (String name : names) {
try (BufferedReader reader = Files.newBufferedReader(Paths.get(SchematicV2Handler.class.getResource(String.format("/data/dimdoors/pockets/json/v2/%s.json", name)).toURI()))) {
List<String> result = new ArrayList<>();
while(true) {
String line = reader.readLine();
if (line == null) {
break;
}
result.add(line);
}
JsonObject json = GSON.fromJson(String.join("", result), JsonObject.class);
PocketType type = PocketType.CODEC.decode(JsonOps.INSTANCE, json).getOrThrow(false, System.err::println).getFirst();
this.pocketTypes.add(type);
this.loadResourceSchematics(type);
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
LOGGER.info("Loaded schematics in {} seconds", System.currentTimeMillis() - startTime);
}
private void loadResourceSchematics(PocketType type) throws URISyntaxException, IOException {
String group = type.getGroup();
Path basePath = Paths.get(SchematicV2Handler.class.getResource(String.format("/data/dimdoors/pockets/schematic/v2/%s/", group)).toURI());
for (PocketType.PocketEntry entry : type.getEntries()) {
Path schemPath = basePath.resolve(entry.getName() + ".schem");
CompoundTag schemTag = NbtIo.readCompressed(Files.newInputStream(schemPath));
Schematic schematic = Schematic.fromTag(schemTag);
for (int i = 0; i < entry.getWeight(); i++) {
this.templateMap.put(group, new PocketTemplateV2(schematic, group, entry.getSize(), entry.getName(), entry.getWeight()));
}
}
}
public PocketTemplateV2 getRandomPublicPocket() {
Collection<PocketTemplateV2> publicPockets = this.templateMap.get("public");
int index = RANDOM.nextInt(publicPockets.size());
return Lists.newArrayList(publicPockets).get(index);
}
public PocketTemplateV2 getRandomPrivatePocket() {
Collection<PocketTemplateV2> publicPockets = this.templateMap.get("private");
int index = RANDOM.nextInt(publicPockets.size());
return Lists.newArrayList(publicPockets).get(index);
}
public static SchematicV2Handler getInstance() {
return INSTANCE;
}
public List<PocketTemplateV2> getTemplates() {
return this.templates;
}
public List<PocketType> getPocketTypes() {
return this.pocketTypes;
}
}

View file

@ -0,0 +1,114 @@
package org.dimdev.dimdoors.pockets;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.entity.MonolithEntity;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.rift.targets.PocketEntranceMarker;
import org.dimdev.dimdoors.rift.targets.PocketExitMarker;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.util.math.MathUtil;
import org.dimdev.dimdoors.world.pocket.Pocket;
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
public class TemplateUtils {
static void setupEntityPlaceholders(List<CompoundTag> entities, CompoundTag entityTag) {
if (entityTag.contains("placeholder")) {
double x = entityTag.getDouble("x");
double y = entityTag.getDouble("y");
double z = entityTag.getDouble("z");
float yaw = entityTag.getFloat("yaw");
float pitch = entityTag.getFloat("pitch");
CompoundTag newTag;
if ("monolith".equals(entityTag.getString("placeholder"))) {
MonolithEntity monolith = Objects.requireNonNull(ModEntityTypes.MONOLITH.create(null));
monolith.setPos(x, y, z);
monolith.yaw = yaw;
monolith.pitch = pitch;
newTag = monolith.toTag(new CompoundTag());
} else {
throw new RuntimeException("Unknown entity placeholder: " + entityTag.getString("placeholder"));
}
entities.add(newTag);
} else {
entities.add(entityTag);
}
}
static void setupLootTable(ServerWorld world, BlockEntity tile, Inventory inventory, Logger logger) {
LootTable table;
if (tile instanceof ChestBlockEntity) {
logger.debug("Now populating chest.");
table = world.getServer().getLootManager().getTable(new Identifier("dimdoors:dungeon_chest"));
} else {
logger.debug("Now populating dispenser.");
table = world.getServer().getLootManager().getTable(new Identifier("dimdoors:dispenser_projectiles"));
}
LootContext ctx = new LootContext.Builder(world).random(world.random).build(LootContextTypes.CHEST);
table.supplyInventory(inventory, ctx);
}
static void registerRifts(List<? extends RiftBlockEntity> rifts, VirtualTarget linkTo, LinkProperties linkProperties, Pocket pocket) {
ServerWorld world = DimensionalDoorsInitializer.getWorld(pocket.world);
HashMap<RiftBlockEntity, Float> entranceWeights = new HashMap<>();
for (RiftBlockEntity rift : rifts) { // Find an entrance
if (rift.getDestination() instanceof PocketEntranceMarker) {
entranceWeights.put(rift, ((PocketEntranceMarker) rift.getDestination()).getWeight());
}
}
if (entranceWeights.size() == 0) {
return;
}
RiftBlockEntity selectedEntrance = MathUtil.weightedRandom(entranceWeights);
// Replace entrances with appropriate destinations
for (RiftBlockEntity rift : rifts) {
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()));
} else {
rift.setDestination(((PocketEntranceMarker) dest).getOtherwiseDestination());
}
}
}
for (RiftBlockEntity rift : rifts) {
VirtualTarget dest = rift.getDestination();
if (dest instanceof PocketExitMarker) {
if (linkProperties != null) rift.setProperties(linkProperties);
rift.setDestination(rift.getProperties() == null || !rift.getProperties().oneWay ? linkTo : null);
}
}
for (RiftBlockEntity rift : rifts) {
rift.register();
rift.markDirty();
}
}
}

View file

@ -8,7 +8,6 @@ import org.dimdev.dimdoors.util.Codecs;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public class LinkProperties {
public static Codec<LinkProperties> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(

View file

@ -10,8 +10,8 @@ import net.minecraft.util.dynamic.DynamicSerializableUuid;
public class PlayerRiftPointer extends RegistryVertex {
public static final Codec<PlayerRiftPointer> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
DynamicSerializableUuid.field_25122.fieldOf("id").forGetter(a -> a.id),
DynamicSerializableUuid.field_25122.fieldOf("player").forGetter(a -> a.player)
DynamicSerializableUuid.CODEC.fieldOf("id").forGetter(a -> a.id),
DynamicSerializableUuid.CODEC.fieldOf("player").forGetter(a -> a.player)
).apply(instance, (id, player) -> {
PlayerRiftPointer pointer = new PlayerRiftPointer(player);
pointer.id = id;

View file

@ -10,7 +10,7 @@ import net.minecraft.world.World;
public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass?
public static final Codec<PocketEntrancePointer> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
DynamicSerializableUuid.field_25122.fieldOf("id").forGetter(a -> a.id),
DynamicSerializableUuid.CODEC.fieldOf("id").forGetter(a -> a.id),
World.CODEC.fieldOf("pocketDim").forGetter(a -> a.pocketDim),
Codec.INT.fieldOf("pocketId").forGetter(a -> a.pocketId)
).apply(instance, (id, pocketDim, pocketId) -> {

View file

@ -40,9 +40,9 @@ public abstract class RegistryVertex {
}
public interface RegistryVertexType<T extends RegistryVertex> {
public RegistryVertexType<PlayerRiftPointer> PLAYER = register("player", PlayerRiftPointer.CODEC);
public RegistryVertexType<Rift> RIFT = register("rift", Rift.CODEC);
public RegistryVertexType<PocketEntrancePointer> ENTRANCE = register("entrance", PocketEntrancePointer.CODEC);
RegistryVertexType<PlayerRiftPointer> PLAYER = register("player", PlayerRiftPointer.CODEC);
RegistryVertexType<Rift> RIFT = register("rift", Rift.CODEC);
RegistryVertexType<PocketEntrancePointer> ENTRANCE = register("entrance", PocketEntrancePointer.CODEC);
RegistryVertexType<RiftPlaceholder> RIFT_PLACEHOLDER = register("rift_placeholder", RiftPlaceholder.CODEC);
Codec<T> codec();

View file

@ -1,5 +1,7 @@
package org.dimdev.dimdoors.rift.registry;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
@ -12,15 +14,11 @@ import net.minecraft.util.dynamic.DynamicSerializableUuid;
public class Rift extends RegistryVertex {
public static final Codec<Rift> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
DynamicSerializableUuid.field_25122.fieldOf("id").forGetter(a -> a.id),
DynamicSerializableUuid.CODEC.fieldOf("id").forGetter(a -> a.id),
Location.CODEC.fieldOf("location").forGetter(a -> a.location),
Codec.BOOL.fieldOf("isDetached").forGetter(a -> a.isDetached),
LinkProperties.CODEC.fieldOf("properties").forGetter(a -> a.properties)
).apply(instance, (id, location, isDetached, properties) -> {
Rift pointer = new Rift(location, isDetached, properties);
pointer.id = id;
return pointer;
});
).apply(instance, Rift::new);
});
private static final Logger LOGGER = LogManager.getLogger();
@ -38,13 +36,20 @@ public class Rift extends RegistryVertex {
this.properties = properties;
}
public Rift(UUID id, Location location, boolean isDetached, LinkProperties properties) {
this.location = location;
this.isDetached = isDetached;
this.properties = properties;
this.id = id;
}
public Rift() {
}
@Override
public void sourceGone(RegistryVertex source) {
super.sourceGone(source);
RiftBlockEntity riftTileEntity = (RiftBlockEntity) location.getBlockEntity();
RiftBlockEntity riftTileEntity = (RiftBlockEntity) this.location.getBlockEntity();
if (source instanceof Rift) {
riftTileEntity.handleSourceGone(((Rift) source).location);
}
@ -53,7 +58,7 @@ public class Rift extends RegistryVertex {
@Override
public void targetGone(RegistryVertex target) {
super.targetGone(target);
RiftBlockEntity riftTileEntity = (RiftBlockEntity) location.getBlockEntity();
RiftBlockEntity riftTileEntity = (RiftBlockEntity) this.location.getBlockEntity();
if (target instanceof Rift) {
riftTileEntity.handleTargetGone(((Rift) target).location);
}
@ -62,12 +67,12 @@ public class Rift extends RegistryVertex {
public void targetChanged(RegistryVertex target) {
LOGGER.debug("Rift " + this + " notified of target " + target + " having changed. Updating color.");
((RiftBlockEntity) location.getBlockEntity()).updateColor();
((RiftBlockEntity) this.location.getBlockEntity()).updateColor();
}
public void markDirty() {
((RiftBlockEntity) location.getBlockEntity()).updateColor();
for (Location location : RiftRegistry.instance().getSources(location)) {
((RiftBlockEntity) this.location.getBlockEntity()).updateColor();
for (Location location : RiftRegistry.instance().getSources(this.location)) {
RiftRegistry.instance().getRift(location).targetChanged(this);
}
}

View file

@ -9,7 +9,7 @@ import net.minecraft.util.dynamic.DynamicSerializableUuid;
public class RiftPlaceholder extends Rift { // TODO: don't extend rift
private static final Logger LOGGER = LogManager.getLogger();
public static Codec<RiftPlaceholder> CODEC = DynamicSerializableUuid.field_25122.xmap(a -> {
public static Codec<RiftPlaceholder> CODEC = DynamicSerializableUuid.CODEC.xmap(a -> {
RiftPlaceholder placeholder = new RiftPlaceholder();
placeholder.id = a;
return placeholder;

View file

@ -68,7 +68,7 @@ public class RiftRegistry extends PersistentState {
PocketEntrancePointer pocket = NbtUtil.deserialize(pocketNBT, PocketEntrancePointer.CODEC);
graph.addVertex(pocket);
uuidMap.put(pocket.id, pocket);
pocketEntranceMap.put(PocketRegistry.instance(pocket.world).getPocket(pocket.pocketId), pocket);
pocketEntranceMap.put(PocketRegistry.getInstance(pocket.world).getPocket(pocket.pocketId), pocket);
}
// Read the connections between links that have a source or destination in this dimension

View file

@ -35,7 +35,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
chat(entity, new TranslatableText("rifts.destinations.escape.not_in_pocket_dim"));
return false;
}
if (ModDimensions.isLimboDimension(entity.world) && !canEscapeLimbo) {
if (ModDimensions.isLimboDimension(entity.world) && !this.canEscapeLimbo) {
chat(entity, new TranslatableText("rifts.destinations.escape.cannot_escape_limbo"));
return false;
}
@ -43,7 +43,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
UUID uuid = entity.getUuid();
if (uuid != null) {
Location destLoc = RiftRegistry.instance().getOverworldRift(uuid);
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || canEscapeLimbo) {
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), 0);
} else {
@ -54,8 +54,8 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
}
if (!entity.getEntityWorld().isClient) {
if (ModDimensions.LIMBO_DIMENSION != null) {
entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
entity.setPos(location.getX(), location.getY(), location.getZ());
Entity newEntity = entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
newEntity.setPos(this.location.getX(), this.location.getY(), this.location.getZ());
}
}
}

View file

@ -33,7 +33,7 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg
if (uuid != null) {
destLoc = RiftRegistry.instance().getPrivatePocketExit(uuid);
Pocket pocket = PrivatePocketData.instance().getPrivatePocket(uuid);
if (ModDimensions.isDimDoorsPocketDimension(location.getWorld()) && pocket != null && PocketRegistry.instance(pocket.world).getPocketAt(location.pos).equals(pocket)) {
if (ModDimensions.isDimDoorsPocketDimension(location.getWorld()) && pocket != null && PocketRegistry.getInstance(pocket.world).getPocketAt(location.pos).equals(pocket)) {
RiftRegistry.instance().setLastPrivatePocketEntrance(uuid, location); // Remember which exit was used for next time the pocket is entered
}
if (destLoc == null || !(destLoc.getBlockEntity() instanceof RiftBlockEntity)) {
@ -56,7 +56,7 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg
@Override
public void register() {
super.register();
PocketRegistry privatePocketRegistry = PocketRegistry.instance(location.world);
PocketRegistry privatePocketRegistry = PocketRegistry.getInstance(location.world);
Pocket pocket = privatePocketRegistry.getPocketAt(location.pos);
RiftRegistry.instance().addPocketEntrance(pocket, location);
}

View file

@ -39,7 +39,7 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
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.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
pocket = PocketGenerator.generatePrivatePocketV2(new VirtualLocation(virtualLocation.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
this.processEntity(pocket, RiftRegistry.instance().getPocketEntrance(pocket).getBlockEntity(), entity, uuid, yawOffset);
@ -50,7 +50,7 @@ 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.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
pocket = PocketGenerator.generatePrivatePocketV2(new VirtualLocation(virtualLocation.getWorld(), virtualLocation.getX(), virtualLocation.getZ(), -1));
PrivatePocketData.instance().setPrivatePocketID(uuid, pocket);
destLoc = RiftRegistry.instance().getPocketEntrance(pocket);

View file

@ -41,7 +41,7 @@ public class PublicPocketTarget extends RestoringTarget {
VirtualLocation newVirtualLocation;
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);
Pocket pocket = PocketGenerator.generatePublicPocketV2(newVirtualLocation, new GlobalReference(this.location), null);
return RiftRegistry.instance().getPocketEntrance(pocket);
}

View file

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
@ -13,7 +14,6 @@ import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.registry.Rift;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.util.Location;
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;
@ -25,7 +25,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTarget subclass
public static final Codec<RandomTarget> CODEC = RecordCodecBuilder.create(instance -> {
@ -147,7 +146,7 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
if (virtualLocation.getDepth() <= 0) {
// This will lead to the overworld
ServerWorld world = WorldUtil.getWorld(virtualLocation.getWorld());
ServerWorld world = DimensionalDoorsInitializer.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)

View file

@ -7,9 +7,9 @@ import net.minecraft.util.math.Vec3i;
public class RelativeReference extends RiftReference {
private Vec3i offset;
private final Vec3i offset;
public static Codec<RelativeReference> CODEC = Vec3i.field_25123.xmap(RelativeReference::new, RelativeReference::getOffset).fieldOf("offset").codec();
public static Codec<RelativeReference> CODEC = Vec3i.CODEC.xmap(RelativeReference::new, RelativeReference::getOffset).fieldOf("offset").codec();
public RelativeReference(Vec3i offset) {
this.offset = offset;
@ -17,11 +17,11 @@ public class RelativeReference extends RiftReference {
@Override
public Location getReferencedLocation() {
return new Location(location.world, location.pos.add(offset));
return new Location(this.location.world, this.location.pos.add(this.offset));
}
public Vec3i getOffset() {
return offset;
return this.offset;
}
@Override

View file

@ -41,13 +41,13 @@ public abstract class VirtualTarget implements Target {
}
public RGBA getColor() {
return getType().getColor();
return this.getType().getColor();
}
public boolean equals(Object o) {
return o instanceof VirtualTarget &&
((VirtualTarget) o).canEqual(this) &&
(location == null ? ((VirtualTarget) o).location == null : ((Object) location).equals(((VirtualTarget) o).location));
(this.location == null ? ((VirtualTarget) o).location == null : ((Object) this.location).equals(((VirtualTarget) o).location));
}
protected boolean canEqual(Object other) {
@ -55,7 +55,7 @@ public abstract class VirtualTarget implements Target {
}
public int hashCode() {
return 59 + (location == null ? 43 : location.hashCode());
return 59 + (this.location == null ? 43 : this.location.hashCode());
}
public void setLocation(Location location) {
@ -67,18 +67,18 @@ public abstract class VirtualTarget implements Target {
}
public interface VirtualTargetType<T extends VirtualTarget> {
public VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("available_link", RandomTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<EscapeTarget> ESCAPE = register("escape", EscapeTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<GlobalReference> GLOBAL = register("global", GlobalReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<LimboTarget> LIMBO = register("limbo", LimboTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<LocalReference> LOCAL = register("local", LocalReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PublicPocketTarget> PUBLIC_POCKET = register("public_pocket", PublicPocketTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PocketEntranceMarker> POCKET_ENTRANCE = register("pocket_entrance", PocketEntranceMarker.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("pocket_exit", PocketExitMarker.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PrivatePocketTarget> PRIVATE = register("private", PrivatePocketTarget.CODEC, PrivatePocketExitTarget.COLOR);
public VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("private_pocket_exit", PrivatePocketExitTarget.CODEC, PrivatePocketExitTarget.COLOR);
public VirtualTargetType<RelativeReference> RELATIVE = register("relative", RelativeReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<NoneTarget> NONE = register("none", NoneTarget.CODEC, COLOR);
VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("available_link", RandomTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<EscapeTarget> ESCAPE = register("escape", EscapeTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<GlobalReference> GLOBAL = register("global", GlobalReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<LimboTarget> LIMBO = register("limbo", LimboTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<LocalReference> LOCAL = register("local", LocalReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PublicPocketTarget> PUBLIC_POCKET = register("public_pocket", PublicPocketTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PocketEntranceMarker> POCKET_ENTRANCE = register("pocket_entrance", PocketEntranceMarker.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("pocket_exit", PocketExitMarker.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PrivatePocketTarget> PRIVATE = register("private", PrivatePocketTarget.CODEC, PrivatePocketExitTarget.COLOR);
VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("private_pocket_exit", PrivatePocketExitTarget.CODEC, PrivatePocketExitTarget.COLOR);
VirtualTargetType<RelativeReference> RELATIVE = register("relative", RelativeReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<NoneTarget> NONE = register("none", NoneTarget.CODEC, COLOR);
Codec<T> codec();

View file

@ -0,0 +1,11 @@
package org.dimdev.dimdoors.util;
import net.minecraft.world.TeleportTarget;
public interface EntityExtensions {
boolean dimdoors_isReadyToTeleport();
void dimdoors_setReadyToTeleport(boolean value);
void dimdoors_setTeleportTarget(TeleportTarget target);
}

View file

@ -9,8 +9,19 @@ import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
public final class EntityUtils {
public static void prepareTeleportation(Entity e, Vec3d pos, float yawOffset) {
if (e instanceof EntityExtensions) {
((EntityExtensions) e).dimdoors_setReadyToTeleport(true);
((EntityExtensions) e).dimdoors_setTeleportTarget(new TeleportTarget(pos, Vec3d.ZERO, e.getYaw(1.0F) + yawOffset, e.getPitch(1.0F)));
} else {
throw new AssertionError("Mixin not applied");
}
}
public static Entity getOwner(Entity entity) {
Entity topmostEntity = null;

View file

@ -10,26 +10,26 @@ public class InstanceMap { // Type safe map between classes and instances
private final Map<Class<?>, Object> uncheckedMap = new HashMap<>();
public <T> void put(Class<T> key, T value) {
uncheckedMap.put(key, value);
this.uncheckedMap.put(key, value);
}
public <T> T get(Class<T> key) {
return key.cast(uncheckedMap.get(key));
return key.cast(this.uncheckedMap.get(key));
}
public <T> T remove(Class<T> key) {
return key.cast(uncheckedMap.remove(key));
return key.cast(this.uncheckedMap.remove(key));
}
public void clear() {
uncheckedMap.clear();
this.uncheckedMap.clear();
}
public boolean containsKey(Class<?> key) {
return uncheckedMap.containsKey(key);
return this.uncheckedMap.containsKey(key);
}
public boolean containsValue(Object value) {
return uncheckedMap.containsValue(value);
return this.uncheckedMap.containsValue(value);
}
}

View file

@ -38,50 +38,50 @@ public class Location {
}
public int getX() {
return pos.getX();
return this.pos.getX();
}
public int getY() {
return pos.getY();
return this.pos.getY();
}
public int getZ() {
return pos.getZ();
return this.pos.getZ();
}
public BlockState getBlockState() {
return getWorld().getBlockState(pos);
return this.getWorld().getBlockState(this.pos);
}
public FluidState getFluidState() {
return getWorld().getFluidState(pos);
return this.getWorld().getFluidState(this.pos);
}
public BlockEntity getBlockEntity() {
return getWorld().getBlockEntity(pos);
return this.getWorld().getBlockEntity(this.pos);
}
public BlockPos getBlockPos() {
return pos;
return this.pos;
}
@Override
public boolean equals(Object obj) {
return obj instanceof Location &&
((Location) obj).world.equals(world) &&
((Location) obj).pos.equals(pos);
((Location) obj).world.equals(this.world) &&
((Location) obj).pos.equals(this.pos);
}
@Override
public int hashCode() {
return world.hashCode() * 31 + pos.hashCode();
return this.world.hashCode() * 31 + this.pos.hashCode();
}
public RegistryKey<World> getWorldId() {
return world;
return this.world;
}
public ServerWorld getWorld() {
return DimensionalDoorsInitializer.getServer().getWorld(world);
return DimensionalDoorsInitializer.getServer().getWorld(this.world);
}
}

View file

@ -1,5 +1,7 @@
package org.dimdev.dimdoors.util;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@ -7,31 +9,37 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public final class TeleportUtil {
public static void teleport(Entity entity, World world, BlockPos pos, int yawOffset) {
if (world.isClient) {
throw new UnsupportedOperationException("Only supported on ServerWorld");
}
teleport(entity, world, Vec3d.ofBottomCenter(pos), yawOffset);
}
public static void teleport(Entity entity, World world, Vec3d pos, float yawOffset) {
if (entity.world.getRegistryKey().equals(world.getRegistryKey())) {
if (world.isClient) {
throw new UnsupportedOperationException("Only supported on ServerWorld");
}
if (entity instanceof ServerPlayerEntity) {
((ServerPlayerEntity) entity).teleport((ServerWorld) world, pos.x, pos.y, pos.z, entity.getYaw(1.0F) + yawOffset, entity.getPitch(1.0F));
}
else if (entity.world.getRegistryKey().equals(world.getRegistryKey())) {
entity.setPos(pos.x, pos.y, pos.z);
entity.setYaw(entity.yaw + yawOffset);
} else {
if (world instanceof ServerWorld) {
entity.moveToWorld((ServerWorld) world);
entity.setPos(pos.x, pos.y, pos.z);
entity.setYaw(entity.yaw + yawOffset);
entity.setOnFireFor(0);// Workaround for https://bugs.mojang.com/browse/MC-100097
}
EntityUtils.prepareTeleportation(entity, pos, yawOffset);
entity.moveToWorld((ServerWorld) world);
}
}
public static void teleport(ServerPlayerEntity player, Location location) {
teleport(player, WorldUtil.getWorld(location.world), location.pos, 0);
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0);
}
public static void teleport(ServerPlayerEntity player, RotatedLocation location) {
teleport(player, WorldUtil.getWorld(location.world), location.pos, (int) location.yaw);
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
}
}

View file

@ -1,13 +0,0 @@
package org.dimdev.dimdoors.util;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
public class WorldUtil {
public static ServerWorld getWorld(RegistryKey<World> key) {
return DimensionalDoorsInitializer.getWorld(key);
}
}

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic;
package org.dimdev.dimdoors.util.schematic;
import java.util.ArrayList;
import java.util.HashMap;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic;
package org.dimdev.dimdoors.util.schematic;
import java.util.HashMap;
import java.util.Map;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic;
package org.dimdev.dimdoors.util.schematic;
import java.lang.reflect.Method;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic;
package org.dimdev.dimdoors.util.schematic;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.util.Map;
import java.util.Objects;
@ -34,7 +34,7 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
public RelativeBlockSample(Schematic schematic) {
this.schematic = schematic;
this.blockData = SchematicPlacer.getBlockData(schematic, schematic.getWidth(), schematic.getHeight(), schematic.getLength());
this.blockData = SchematicPlacer.getBlockData(schematic);
this.blockPalette = ImmutableBiMap.copyOf(schematic.getBlockPalette());
this.blockContainer = Maps.newHashMap();
this.blockEntityContainer = Maps.newHashMap();

View file

@ -1,10 +1,14 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
@ -13,12 +17,12 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.SharedConstants;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.StructureWorldAccess;
@SuppressWarnings("CodeBlock2Expr")
public class Schematic {
private static final Consumer<String> PRINT_TO_STDERR = System.err::println;
public static final Codec<Schematic> CODEC = RecordCodecBuilder.create((instance) -> {
@ -29,7 +33,7 @@ public class Schematic {
Codec.SHORT.fieldOf("Width").forGetter(Schematic::getWidth),
Codec.SHORT.fieldOf("Height").forGetter(Schematic::getHeight),
Codec.SHORT.fieldOf("Length").forGetter(Schematic::getLength),
Vec3i.field_25123.fieldOf("Offset").forGetter(Schematic::getOffset),
Vec3i.CODEC.fieldOf("Offset").forGetter(Schematic::getOffset),
Codec.INT.fieldOf("PaletteMax").forGetter(Schematic::getPaletteMax),
SchematicBlockPalette.CODEC.fieldOf("Palette").forGetter(Schematic::getBlockPalette),
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
@ -46,10 +50,10 @@ public class Schematic {
private final short length;
private final Vec3i offset;
private final int paletteMax;
private final Map<BlockState, Integer> blockPalette;
private final BiMap<BlockState, Integer> blockPalette;
private final ByteBuffer blockData;
private final List<CompoundTag> blockEntities;
private final List<CompoundTag> entities;
private List<CompoundTag> blockEntities;
private List<CompoundTag> entities;
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities) {
this.version = version;
@ -60,7 +64,7 @@ public class Schematic {
this.length = length;
this.offset = offset;
this.paletteMax = paletteMax;
this.blockPalette = blockPalette;
this.blockPalette = HashBiMap.create(blockPalette);
this.blockData = blockData;
this.blockEntities = blockEntities;
this.entities = entities;
@ -110,10 +114,26 @@ public class Schematic {
return this.blockEntities;
}
public void setBlockEntities(List<CompoundTag> blockEntities) {
this.blockEntities = blockEntities.stream().map(SchematicPlacer::fixEntityId).collect(Collectors.toList());
}
public void setEntities(Collection<? extends Entity> entities) {
this.setEntities(entities.stream().map((e) -> {
CompoundTag tag = new CompoundTag();
e.saveSelfToTag(tag);
return tag;
}).collect(Collectors.toList()));
}
public List<CompoundTag> getEntities() {
return this.entities;
}
public void setEntities(List<CompoundTag> entities) {
this.entities = entities;
}
public static RelativeBlockSample getBlockSample(Schematic schem) {
return new RelativeBlockSample(schem);
}

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.util.Iterator;
import java.util.Objects;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.util.List;

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.util.List;
import java.util.Objects;
@ -31,15 +31,14 @@ public final class SchematicPlacer {
LOGGER.warn("Schematic \"" + schematic.getMetadata().getName() + "\" depends on mod \"" + id + "\", which is missing!");
}
}
int originX = origin.getX();
int originY = origin.getY();
int originZ = origin.getZ();
RelativeBlockSample blockSample = Schematic.getBlockSample(schematic, world);
blockSample.place(origin);
SchematicPlacer.placeEntities(originX, originY, originZ, schematic, world);
}
static int[][][] getBlockData(Schematic schematic, int width, int height, int length) {
public static int[][][] getBlockData(Schematic schematic) {
int width = schematic.getWidth();
int height = schematic.getHeight();
int length = schematic.getLength();
byte[] blockDataIntArray = schematic.getBlockData().array();
int[][][] blockData = new int[width][height][length];
for (int x = 0; x < width; x++) {
@ -55,12 +54,6 @@ public final class SchematicPlacer {
private static void placeEntities(int originX, int originY, int originZ, Schematic schematic, StructureWorldAccess world) {
List<CompoundTag> entityTags = schematic.getEntities();
for (CompoundTag tag : entityTags) {
// Ensures compatibility with worldedit schematics
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!");
}
ListTag listTag = Objects.requireNonNull(tag.getList("Pos", 6), "Entity in schematic \"" + schematic.getMetadata().getName() + "\" did not have a Pos tag!");
SchematicPlacer.processPos(listTag, originX, originY, originZ, tag);
@ -74,13 +67,18 @@ public final class SchematicPlacer {
}
}
private static boolean fixId(CompoundTag tag) {
public static CompoundTag fixEntityId(CompoundTag tag) {
if (!tag.contains("Id") && tag.contains("id")) {
tag.putString("Id", tag.getString("id"));
} else if (tag.contains("Id") && !tag.contains("id")) {
tag.putString("id", tag.getString("Id"));
}
return !tag.contains("Id") || !tag.contains("id");
if (!tag.contains("Id") || !tag.contains("id")) {
System.err.println("An unexpected error occurred parsing this entity");
System.err.println(tag.toString());
throw new IllegalStateException("Entity did not have an 'Id' tag, nor an 'id' tag!");
}
return tag;
}
private static void processPos(ListTag listTag, int originX, int originY, int originZ, CompoundTag tag) {

View file

@ -1,4 +1,4 @@
package org.dimdev.dimcore.schematic.v2;
package org.dimdev.dimdoors.util.schematic.v2;
import java.io.IOException;
import java.nio.ByteBuffer;

View file

@ -56,7 +56,7 @@ public final class ModBiomes {
}
static {
Biome.Builder voidBiomeBuilder = new Biome.Builder().category(Biome.Category.NONE).depth(0).downfall(0).generationSettings(new GenerationSettings.Builder().surfaceBuilder(SurfaceBuilder.DEFAULT.method_30478(new TernarySurfaceConfig(Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), Blocks.VOID_AIR.getDefaultState()))).build()).precipitation(Biome.Precipitation.NONE).scale(0).spawnSettings(new SpawnSettings.Builder().build()).temperature(0.8f).temperatureModifier(Biome.TemperatureModifier.NONE);
Biome.Builder voidBiomeBuilder = new Biome.Builder().category(Biome.Category.NONE).depth(0).downfall(0).generationSettings(new GenerationSettings.Builder().surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), Blocks.VOID_AIR.getDefaultState()))).build()).precipitation(Biome.Precipitation.NONE).scale(0).spawnSettings(new SpawnSettings.Builder().build()).temperature(0.8f).temperatureModifier(Biome.TemperatureModifier.NONE);
PERSONAL_WHITE_VOID_KEY = RegistryKey.of(Registry.BIOME_KEY, new Identifier("dimdoors:white_void"));
PUBLIC_BLACK_VOID_KEY = RegistryKey.of(Registry.BIOME_KEY, new Identifier("dimdoors:black_void"));
DUNGEON_DANGEROUS_BLACK_VOID_KEY = RegistryKey.of(Registry.BIOME_KEY, new Identifier("dimdoors:dangerous_black_void"));
@ -81,7 +81,7 @@ public final class ModBiomes {
.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())))
.surfaceBuilder(SurfaceBuilder.NETHER.withConfig(new TernarySurfaceConfig(ModBlocks.UNRAVELLED_FABRIC.getDefaultState(), ModBlocks.UNRAVELLED_FABRIC.getDefaultState(), ModBlocks.ETERNAL_FLUID.getDefaultState())))
.build())
.precipitation(Biome.Precipitation.NONE)
.scale(2F)

View file

@ -6,7 +6,6 @@ import java.util.OptionalLong;
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;
@ -18,8 +17,6 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.FixedBiomeSource;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.GenerationShapeConfig;
@ -43,11 +40,6 @@ public final class ModDimensions {
public static final ChunkGeneratorSettings LIMBO_CHUNK_GENERATOR_SETTINGS;
// TODO: move pocket dimension generation settings to code
public static final BiomeSource PERSONAL_BIOME_SOURCE = new FixedBiomeSource(() -> ModBiomes.PERSONAL_WHITE_VOID_BIOME);
public static final BiomeSource PUBLIC_BIOME_SOURCE = new FixedBiomeSource(() -> ModBiomes.PUBLIC_BLACK_VOID_BIOME);
public static final BiomeSource DUNGEON_BIOME_SOURCE = new FixedBiomeSource(() -> ModBiomes.DUNGEON_DANGEROUS_BLACK_VOID_BIOME);
public static ServerWorld LIMBO_DIMENSION;
public static ServerWorld PERSONAL_POCKET_DIMENSION;
public static ServerWorld PUBLIC_POCKET_DIMENSION;
@ -62,11 +54,11 @@ public final class ModDimensions {
}
public static boolean isLimbo(StructureWorldAccess world) {
return world.getDimension() == LIMBO_TYPE || world == LIMBO_DIMENSION;
return world != null && (world.getDimension() == LIMBO_TYPE || world == LIMBO_DIMENSION);
}
public static boolean isLimboDimension(World world) {
return world.getRegistryKey() == LIMBO || world.getDimension() == LIMBO_TYPE || world == LIMBO_DIMENSION;
return world != null && (world.getRegistryKey() == LIMBO || world.getDimension() == LIMBO_TYPE || world == LIMBO_DIMENSION);
}
public static void init() {
@ -80,7 +72,6 @@ public final class ModDimensions {
});
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("dimdoors", "blank"), BlankChunkGenerator.CODEC);
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("dimdoors", "limbo_chunk_generator"), LimboChunkGenerator.CODEC);
Registry.register(Registry.BIOME_SOURCE, new Identifier("dimdoors", "limbo_biome_source"), LimboBiomeSource.CODEC);
}
static {

View file

@ -6,8 +6,8 @@ import java.io.InputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimcore.schematic.v2.Schematic;
import org.dimdev.dimcore.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.util.schematic.v2.Schematic;
import org.dimdev.dimdoors.util.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.feature.gateway.Gateway;
import com.google.common.collect.BiMap;

View file

@ -1,40 +0,0 @@
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 net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
public class LimboBiomeSource extends BiomeSource {
public static final LimboBiomeSource INSTANCE = new LimboBiomeSource();
public static final Codec<LimboBiomeSource> CODEC = Codec.unit(INSTANCE);
private LimboBiomeSource() {
super(ImmutableList.of(ModBiomes.LIMBO_BIOME));
}
@Override
public Codec<? extends BiomeSource> getCodec() {
return CODEC;
}
@Override
public BiomeSource withSeed(long seed) {
return this;
}
@Override
public Set<Biome> getBiomesInArea(int x, int y, int z, int radius) {
return ImmutableSet.of(ModBiomes.LIMBO_BIOME);
}
@Override
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
return ModBiomes.LIMBO_BIOME;
}
}

View file

@ -11,6 +11,7 @@ import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.mixin.ChunkGeneratorAccessor;
import org.dimdev.dimdoors.world.ModBiomes;
import org.dimdev.dimdoors.world.ModDimensions;
import org.jetbrains.annotations.Nullable;
import com.mojang.serialization.Codec;
@ -39,6 +40,7 @@ import net.minecraft.world.SpawnHelper;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.FixedBiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
@ -55,7 +57,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class LimboChunkGenerator extends ChunkGenerator {
public static final LimboChunkGenerator INSTANCE = new LimboChunkGenerator(LimboBiomeSource.INSTANCE, LimboBiomeSource.INSTANCE);
public static final LimboChunkGenerator INSTANCE = new LimboChunkGenerator(new FixedBiomeSource(() -> ModBiomes.LIMBO_BIOME), new FixedBiomeSource(() -> ModBiomes.LIMBO_BIOME));
public static final Codec<LimboChunkGenerator> CODEC = Codec.unit(INSTANCE);
private static final float[] NOISE_WEIGHT_TABLE = Util.make(new float[13824], (array) -> {
for (int i = 0; i < 24; ++i) {

View file

@ -22,7 +22,60 @@ import net.minecraft.block.BlockWithEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import static net.minecraft.block.Blocks.*;
import static net.minecraft.block.Blocks.ACACIA_LOG;
import static net.minecraft.block.Blocks.ACACIA_PLANKS;
import static net.minecraft.block.Blocks.ACACIA_WOOD;
import static net.minecraft.block.Blocks.AIR;
import static net.minecraft.block.Blocks.ANDESITE;
import static net.minecraft.block.Blocks.BIRCH_LOG;
import static net.minecraft.block.Blocks.BIRCH_PLANKS;
import static net.minecraft.block.Blocks.BIRCH_WOOD;
import static net.minecraft.block.Blocks.BLACKSTONE;
import static net.minecraft.block.Blocks.COAL_BLOCK;
import static net.minecraft.block.Blocks.COAL_ORE;
import static net.minecraft.block.Blocks.COBBLESTONE;
import static net.minecraft.block.Blocks.CRACKED_STONE_BRICKS;
import static net.minecraft.block.Blocks.DARK_OAK_LOG;
import static net.minecraft.block.Blocks.DARK_OAK_PLANKS;
import static net.minecraft.block.Blocks.DARK_OAK_WOOD;
import static net.minecraft.block.Blocks.DIORITE;
import static net.minecraft.block.Blocks.DIRT;
import static net.minecraft.block.Blocks.EMERALD_BLOCK;
import static net.minecraft.block.Blocks.EMERALD_ORE;
import static net.minecraft.block.Blocks.END_STONE;
import static net.minecraft.block.Blocks.END_STONE_BRICKS;
import static net.minecraft.block.Blocks.FARMLAND;
import static net.minecraft.block.Blocks.GLASS;
import static net.minecraft.block.Blocks.GOLD_BLOCK;
import static net.minecraft.block.Blocks.GOLD_ORE;
import static net.minecraft.block.Blocks.GRANITE;
import static net.minecraft.block.Blocks.GRASS_BLOCK;
import static net.minecraft.block.Blocks.GRASS_PATH;
import static net.minecraft.block.Blocks.GRAVEL;
import static net.minecraft.block.Blocks.IRON_BLOCK;
import static net.minecraft.block.Blocks.IRON_ORE;
import static net.minecraft.block.Blocks.JUNGLE_LOG;
import static net.minecraft.block.Blocks.JUNGLE_PLANKS;
import static net.minecraft.block.Blocks.JUNGLE_WOOD;
import static net.minecraft.block.Blocks.LAPIS_BLOCK;
import static net.minecraft.block.Blocks.LAPIS_ORE;
import static net.minecraft.block.Blocks.OAK_LOG;
import static net.minecraft.block.Blocks.OAK_PLANKS;
import static net.minecraft.block.Blocks.OAK_WOOD;
import static net.minecraft.block.Blocks.PODZOL;
import static net.minecraft.block.Blocks.POLISHED_ANDESITE;
import static net.minecraft.block.Blocks.POLISHED_BLACKSTONE;
import static net.minecraft.block.Blocks.POLISHED_DIORITE;
import static net.minecraft.block.Blocks.POLISHED_GRANITE;
import static net.minecraft.block.Blocks.REDSTONE_BLOCK;
import static net.minecraft.block.Blocks.REDSTONE_ORE;
import static net.minecraft.block.Blocks.SAND;
import static net.minecraft.block.Blocks.SANDSTONE;
import static net.minecraft.block.Blocks.SPRUCE_LOG;
import static net.minecraft.block.Blocks.SPRUCE_PLANKS;
import static net.minecraft.block.Blocks.SPRUCE_WOOD;
import static net.minecraft.block.Blocks.STONE;
import static net.minecraft.block.Blocks.STONE_BRICKS;
/**
* Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo

View file

@ -3,9 +3,9 @@ package org.dimdev.dimdoors.world.pocket;
import java.util.HashMap;
import java.util.Map;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
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;
@ -61,8 +61,8 @@ public class PocketRegistry extends PersistentState {
return tag;
}
public static PocketRegistry instance(RegistryKey<World> key) {
ServerWorld world = WorldUtil.getWorld(key);
public static PocketRegistry getInstance(RegistryKey<World> key) {
ServerWorld world = DimensionalDoorsInitializer.getWorld(key);
if (!(ModDimensions.isDimDoorsPocketDimension(world))) {
throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!");

View file

@ -2,8 +2,8 @@ package org.dimdev.dimdoors.world.pocket;
import java.util.UUID;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
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;
@ -35,7 +35,7 @@ public class PrivatePocketData extends PersistentState {
}
}
public static final Codec<BiMap<UUID, PocketInfo>> CODEC = Codec.unboundedMap(DynamicSerializableUuid.field_25122, PocketInfo.CODEC).xmap(HashBiMap::create, a -> a);
public static final Codec<BiMap<UUID, PocketInfo>> CODEC = Codec.unboundedMap(DynamicSerializableUuid.CODEC, PocketInfo.CODEC).xmap(HashBiMap::create, a -> a);
private static final String DATA_NAME = "dimdoors_private_pockets";
@ -50,32 +50,32 @@ public class PrivatePocketData extends PersistentState {
}
public static PrivatePocketData instance() {
return WorldUtil.getWorld(OVERWORLD).getPersistentStateManager().getOrCreate(PrivatePocketData::new, DATA_NAME);
return DimensionalDoorsInitializer.getWorld(OVERWORLD).getPersistentStateManager().getOrCreate(PrivatePocketData::new, DATA_NAME);
}
@Override
public void fromTag(CompoundTag nbt) {
privatePocketMap = NbtUtil.deserialize(nbt.get("privatePocketMap"), CODEC);
this.privatePocketMap = NbtUtil.deserialize(nbt.get("privatePocketMap"), CODEC);
}
@Override
public CompoundTag toTag(CompoundTag nbt) {
nbt.put("privatePocketMap", NbtUtil.serialize(privatePocketMap, CODEC));
nbt.put("privatePocketMap", NbtUtil.serialize(this.privatePocketMap, CODEC));
return nbt;
}
public Pocket getPrivatePocket(UUID playerUUID) {
PocketInfo pocket = privatePocketMap.get(playerUUID);
PocketInfo pocket = this.privatePocketMap.get(playerUUID);
if (pocket == null) return null;
return PocketRegistry.instance(pocket.world).getPocket(pocket.id);
return PocketRegistry.getInstance(pocket.world).getPocket(pocket.id);
}
public void setPrivatePocketID(UUID playerUUID, Pocket pocket) {
privatePocketMap.put(playerUUID, new PocketInfo(pocket.world, pocket.id));
markDirty();
this.privatePocketMap.put(playerUUID, new PocketInfo(pocket.world, pocket.id));
this.markDirty();
}
public UUID getPrivatePocketOwner(Pocket pocket) {
return privatePocketMap.inverse().get(new PocketInfo(pocket.world, pocket.id));
return this.privatePocketMap.inverse().get(new PocketInfo(pocket.world, pocket.id));
}
}

View file

@ -59,7 +59,7 @@ public class VirtualLocation {
VirtualLocation virtualLocation = null;
if (ModDimensions.isDimDoorsPocketDimension(location.world)) {
Pocket pocket = PocketRegistry.instance(location.world).getPocketAt(location.pos);
Pocket pocket = PocketRegistry.getInstance(location.world).getPocketAt(location.pos);
if (pocket != null) {
virtualLocation = pocket.virtualLocation; // TODO: pockets-relative coordinates
} else {

View file

@ -0,0 +1,45 @@
{
"group": "private",
"pockets": [
{
"id": "private_pocket_0",
"size": 0,
"weight": 20
},
{
"id": "private_pocket_1",
"size": 1,
"weight": 17
},
{
"id": "private_pocket_2",
"size": 2,
"weight": 14
},
{
"id": "private_pocket_3",
"size": 3,
"weight": 11
},
{
"id": "private_pocket_4",
"size": 4,
"weight": 8
},
{
"id": "private_pocket_5",
"size": 5,
"weight": 5
},
{
"id": "private_pocket_6",
"size": 6,
"weight": 3
},
{
"id": "private_pocket_7",
"size": 7,
"weight": 1
}
]
}

View file

@ -0,0 +1,45 @@
{
"group": "public",
"pockets": [
{
"id": "public_pocket_0",
"size": 0,
"weight": 20
},
{
"id": "public_pocket_1",
"size": 1,
"weight": 17
},
{
"id": "public_pocket_2",
"size": 2,
"weight": 14
},
{
"id": "public_pocket_3",
"size": 3,
"weight": 11
},
{
"id": "public_pocket_4",
"size": 4,
"weight": 8
},
{
"id": "public_pocket_5",
"size": 5,
"weight": 5
},
{
"id": "public_pocket_6",
"size": 6,
"weight": 3
},
{
"id": "public_pocket_7",
"size": 7,
"weight": 1
}
]
}

View file

@ -9,8 +9,10 @@
"DefaultBiomeFeaturesMixin",
"DimensionTypeAccessor",
"DirectionAccessor",
"EntityMixin",
"ListTagAccessor",
"PlayerEntityMixin"
"PlayerEntityMixin",
"RedstoneWireBlockAccessor"
],
"client": [
"client.GlStateManagerAccessor",