diff --git a/README.md b/README.md index 0a8756a5..16eb4a08 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,6 @@ There are many ways to contribute to the project. We encourage you to join our D ### Submitting dungeons Use the `/pocket blank blank_pocket_` to create a blank, closed pocket, or `/pocket blank void_pocket_` to create a pocket containing only a frame marking the pocket bounds, where `` is the size of the pocket (the number of chunks on each side - 1). **Do not build outside the pocket bounds, or it will be clipped when saved. If you want to make your pocket larger after having started to build, you will have to make a new pocket and copy what you built using WorldEdit.** Use the `/saveschem ` command to save your pocket, and click "Create a new file" on [this](https://github.com/DimensionalDevelopment/DimDoors-Dungeon-Repo) page to submit your pocket. For any questions, please join our Discord server. -### Coding -This project uses [Lombok](https://projectlombok.org/) to automatically generate getters and setters. You should install the Lombok plugin for [IntelliJ](https://plugins.jetbrains.com/plugin/6317-lombok-plugin) or [Eclipse](https://projectlombok.org/setup/eclipse) to be able to correctly test the project. We reccommend that you join the Discord server if you're planning on making more major changes to the code or have any questions or problems. - ### Translating [This page](https://github.com/DimensionalDevelopment/DimDoors/tree/1.12-WIP/src/main/resources/assets/dimdoors/lang) contains all the currently translated languages. To contribute a translation, start by copying the [en_US.lang file](https://github.com/DimensionalDevelopment/DimDoors/blob/1.12-WIP/src/main/resources/assets/dimdoors/lang/en_US.lang) to a text editor, and saving it as the [correct locale code](https://minecraft.gamepedia.com/Language#Available_languages). Translate **only what is to the right of the = sign**, and then click "Create a new file" on [this page](https://github.com/DimensionalDevelopment/DimDoors/tree/1.12-WIP/src/main/resources/assets/dimdoors/lang) to submit your translation. diff --git a/build.gradle b/build.gradle index cf3852fd..e45e0844 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'net.fabricmc:fabric-loom:0.2.6-SNAPSHOT' + classpath 'net.fabricmc:fabric-loom:0.2.7-SNAPSHOT' } } @@ -28,7 +28,6 @@ dependencies { modCompile 'com.flowpowered:flow-math:1.0.3' modCompile 'org.jgrapht:jgrapht-core:1.1.0' modCompile 'com.github.DimensionalDevelopment:poly2tri.java:master-SNAPSHOT' - modCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.10' } version "4.0" diff --git a/gradle.properties b/gradle.properties index a7a8e86b..1a6aab5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -minecraft_version=1.15-pre3 -yarn_version=1.15-pre3+build.2 -loader_version=0.7.1+build.173 -fabric_version=0.4.18+build.271-1.15 \ No newline at end of file +minecraft_version=20w11a +yarn_version=20w11a+build.6 +loader_version=0.7.8+build.187 +fabric_version=0.5.3+build.308-1.16 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 30b572c7..8ef06692 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip diff --git a/src/main/java/org/dimdev/annotatednbt/AnnotatedNbt.java b/src/main/java/org/dimdev/annotatednbt/AnnotatedNbt.java index 4b206e8e..6c3b9278 100644 --- a/src/main/java/org/dimdev/annotatednbt/AnnotatedNbt.java +++ b/src/main/java/org/dimdev/annotatednbt/AnnotatedNbt.java @@ -1,11 +1,9 @@ package org.dimdev.annotatednbt; import net.minecraft.nbt.CompoundTag; +import org.dimdev.dimdoors.rift.registry.PlayerRiftPointer; import org.dimdev.util.RotatedLocation; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - public final class AnnotatedNbt { public static T deserialize(Class rotatedLocationClass, CompoundTag tag) { return null; // TODO @@ -22,4 +20,12 @@ public final class AnnotatedNbt { public static void save(Object object, CompoundTag tag) { // TODO } + + public static void fromTag(Object playerRiftPointer, CompoundTag nbt) { + + } + + public static CompoundTag toTag(Object playerRiftPointer, CompoundTag nbt) { + return null; + } } diff --git a/src/main/java/org/dimdev/dimdoors/DimDoors.java b/src/main/java/org/dimdev/dimdoors/DimDoors.java index 825ba455..abe0dbab 100644 --- a/src/main/java/org/dimdev/dimdoors/DimDoors.java +++ b/src/main/java/org/dimdev/dimdoors/DimDoors.java @@ -2,27 +2,22 @@ package org.dimdev.dimdoors; import net.fabricmc.api.ModInitializer; import net.minecraft.entity.Entity; +import net.minecraft.text.TranslatableText; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.item.ModItems; import org.dimdev.dimdoors.rift.targets.*; import org.dimdev.dimdoors.world.ModDimensions; -import java.io.File; - public class DimDoors implements ModInitializer { - public static void sendTranslatedMessage(Entity entity, String s, Object... args) { - // TODO - } - public static String getConfigurationFolder() { - return null; // TODO + return "config"; // TODO } @Override public void onInitialize() { ModBlocks.init(); ModItems.init(); - ModDimensions.registerDimensions(); + ModDimensions.init(); VirtualTarget.registry.put("available_link", RandomTarget.class); VirtualTarget.registry.put("escape", EscapeTarget.class); diff --git a/src/main/java/org/dimdev/dimdoors/EventHandler.java b/src/main/java/org/dimdev/dimdoors/EventHandler.java index f1ebdbad..68b05192 100644 --- a/src/main/java/org/dimdev/dimdoors/EventHandler.java +++ b/src/main/java/org/dimdev/dimdoors/EventHandler.java @@ -1,29 +1,19 @@ package org.dimdev.dimdoors; -import net.minecraft.entity.Entity; -import net.minecraft.util.DamageSource; -import net.minecraftforge.event.entity.living.LivingHurtEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent; -import org.dimdev.dimdoors.rift.registry.RiftRegistry; -import org.dimdev.dimdoors.world.ModDimensions; - public final class EventHandler { - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public static void onLivingHurt(LivingHurtEvent event) { - Entity entity = event.getEntity(); - if (entity.dimension == ModDimensions.LIMBO.getId() && event.getSource() == DamageSource.FALL) { - event.setCanceled(true);// no fall damage in limbo - } - } - - @SubscribeEvent(priority = EventPriority.LOWEST) - public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) { - // TODO: Make this work with other mods (such as Dimensional Industry) - if (!ModDimensions.isDimDoorsPocketDimension(event.fromDim) && ModDimensions.isDimDoorsPocketDimension(event.toDim)) { - RiftRegistry.instance().setOverworldRift(event.player.getUniqueID(), null); - } - } +// @SubscribeEvent(priority = EventPriority.HIGHEST) +// public static void onLivingHurt(LivingHurtEvent event) { +// Entity entity = event.getEntity(); +// if (entity.dimension == ModDimensions.LIMBO && event.getSource() == DamageSource.FALL) { +// event.setCanceled(true);// no fall damage in limbo +// } +// } +// +// @SubscribeEvent(priority = EventPriority.LOWEST) +// public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) { +// // TODO: Make this work with other mods (such as Dimensional Industry) +// if (!ModDimensions.isDimDoorsPocketDimension(event.fromDim) && ModDimensions.isDimDoorsPocketDimension(event.toDim)) { +// RiftRegistry.instance().setOverworldRift(event.player.getUniqueID(), null); +// } +// } } diff --git a/src/main/java/org/dimdev/dimdoors/ModConfig.java b/src/main/java/org/dimdev/dimdoors/ModConfig.java index 2fc52c87..502c872d 100644 --- a/src/main/java/org/dimdev/dimdoors/ModConfig.java +++ b/src/main/java/org/dimdev/dimdoors/ModConfig.java @@ -1,5 +1,8 @@ package org.dimdev.dimdoors; +import java.util.LinkedHashSet; +import java.util.Set; + public final class ModConfig { public static final General GENERAL = new General(); public static final Pockets POCKETS = new Pockets(); @@ -33,8 +36,8 @@ public final class ModConfig { public static class World { public double clusterGenChance = 0.0002; public double gatewayGenChance = 0.0015; - public int[] clusterDimBlacklist = {}; - public int[] gatewayDimBlacklist = {}; + public Set clusterDimBlacklist = new LinkedHashSet<>(); + public Set gatewayDimBlacklist = new LinkedHashSet<>(); } public static class Dungeons { diff --git a/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java b/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java index e60fb6e0..1291089b 100644 --- a/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java @@ -15,12 +15,9 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity; -import javax.annotation.Nullable; - public class DimensionalDoorBlock extends DoorBlock implements RiftProvider { public DimensionalDoorBlock(Settings settings) { super(settings); @@ -54,19 +51,16 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider { @@ -31,7 +30,7 @@ public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvi } } - @Nullable + @Override public BlockEntity createBlockEntity(BlockView blockView) { return new EntranceRiftBlockEntity(); diff --git a/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java b/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java index b4addfb3..2b2dc9f8 100644 --- a/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java @@ -19,7 +19,7 @@ public class FabricBlock extends Block { } @Override - @SuppressWarnings("deprecated") + @SuppressWarnings({"deprecation"}) public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ItemStack heldStack = hand == Hand.MAIN_HAND ? player.getMainHandStack() : player.getOffHandStack(); Block heldBlock = Block.getBlockFromItem(heldStack.getItem()); diff --git a/src/main/java/org/dimdev/dimdoors/block/ModBlocks.java b/src/main/java/org/dimdev/dimdoors/block/ModBlocks.java index a73487b3..29c24012 100644 --- a/src/main/java/org/dimdev/dimdoors/block/ModBlocks.java +++ b/src/main/java/org/dimdev/dimdoors/block/ModBlocks.java @@ -62,6 +62,10 @@ public final class ModBlocks { return Registry.register(Registry.BLOCK, string, block); } + public static void init() { + // just loads the class + } + private static class DoorBlock extends net.minecraft.block.DoorBlock { // TODO: use access transformer instead protected DoorBlock(Settings settings) { super(settings); diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java index 20f95d26..99ce5bc5 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java @@ -1,6 +1,5 @@ package org.dimdev.dimdoors.block.entity; -import lombok.Setter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.entity.Entity; @@ -8,13 +7,14 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnType; import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Tickable; +import org.dimdev.annotatednbt.AnnotatedNbt; import org.dimdev.annotatednbt.Saved; import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.util.Location; import org.dimdev.util.TeleportUtil; -import org.dimdev.annotatednbt.AnnotatedNbt; import java.util.Random; @@ -27,7 +27,7 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable @Saved public int spawnedEndermanId = 0; @Saved public float size = 0; - @Setter private boolean unregisterDisabled = false; + private boolean unregisterDisabled = false; @Environment(EnvType.CLIENT) public double renderAngle; @@ -99,7 +99,9 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable @Override public boolean receiveEntity(Entity entity, float relativeYaw, float relativePitch) { - TeleportUtil.teleport(entity, new Location(world, pos), entity.yaw, entity.pitch); + TeleportUtil.teleport(entity, new Location((ServerWorld) world, pos), entity.yaw, entity.pitch); return true; } + + public void setUnregisterDisabled(boolean unregisterDisabled) {this.unregisterDisabled = unregisterDisabled; } } diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java index 0a3cd56c..58bfedd1 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java @@ -43,7 +43,7 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity { @Override public boolean receiveEntity(Entity entity, float relativeYaw, float relativePitch) { - Vec3d targetPos = new Vec3d(pos).add(0.5, 0, 0.5).add(new Vec3d(getOrientation().getVector()).multiply(ModConfig.GENERAL.teleportOffset + 0.5)); + Vec3d targetPos = Vec3d.method_24953(pos).add(Vec3d.method_24954(getOrientation().getVector()).multiply(ModConfig.GENERAL.teleportOffset + 0.5)); TeleportUtil.teleport(entity, world, targetPos.x, targetPos.y, targetPos.z, entity.yaw + relativeYaw, entity.pitch + relativePitch); return true; diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java b/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java index d34b711c..82ec2d99 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java @@ -23,6 +23,6 @@ public class ModBlockEntityTypes { ); private static BlockEntityType register(String id, Supplier supplier, Block[] blocks) { - return Registry.register(Registry.BLOCK_ENTITY, id, new BlockEntityType<>(supplier, Sets.newHashSet(blocks), null)); + return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, new BlockEntityType<>(supplier, Sets.newHashSet(blocks), null)); } } diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java index c08d0488..5769df02 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java @@ -1,12 +1,11 @@ package org.dimdev.dimdoors.block.entity; -import lombok.Getter; -import lombok.ToString; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.TranslatableText; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,17 +20,15 @@ import org.dimdev.dimdoors.rift.targets.*; import org.dimdev.pocketlib.VirtualLocation; import org.dimdev.util.Location; -import javax.annotation.Nonnull; import java.util.Arrays; -@ToString public abstract class RiftBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Target, EntityTarget, AutoSerializable { private static final Logger LOGGER = LogManager.getLogger(); - /*@Saved*/ @Nonnull @Getter protected VirtualTarget destination; // How the rift acts as a source - @Saved @Getter protected LinkProperties properties; - @Saved @Getter protected boolean alwaysDelete; - @Saved @Getter protected boolean forcedColor; - @Saved @Getter protected float[] color = null; + /*@Saved*/ protected VirtualTarget destination; // How the rift acts as a source + @Saved protected LinkProperties properties; + @Saved protected boolean alwaysDelete; + @Saved protected boolean forcedColor; + @Saved protected float[] color = null; protected boolean riftStateChanged; // not saved @@ -67,7 +64,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity this.destination = destination; if (destination != null) { if (world != null && pos != null) { - destination.setLocation(new Location(world, pos)); + destination.setLocation(new Location((ServerWorld) world, pos)); } if (isRegistered()) destination.register(); } @@ -94,7 +91,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity } public boolean isRegistered() { - return !PocketTemplate.isReplacingPlaceholders() && RiftRegistry.instance().isRiftAt(new Location(world, pos)); + return !PocketTemplate.isReplacingPlaceholders() && RiftRegistry.instance().isRiftAt(new Location((ServerWorld) world, pos)); } public void register() { @@ -102,7 +99,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity return; } - Location loc = new Location(world, pos); + Location loc = new Location((ServerWorld) world, pos); RiftRegistry.instance().addRift(loc); if (destination != null) destination.register(); updateProperties(); @@ -110,19 +107,19 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity } public void updateProperties() { - if (isRegistered()) RiftRegistry.instance().setProperties(new Location(world, pos), properties); + if (isRegistered()) RiftRegistry.instance().setProperties(new Location((ServerWorld) world, pos), properties); markDirty(); } public void unregister() { if (isRegistered()) { - RiftRegistry.instance().removeRift(new Location(world, pos)); + RiftRegistry.instance().removeRift(new Location((ServerWorld) world, pos)); } } public void updateType() { if (!isRegistered()) return; - Rift rift = RiftRegistry.instance().getRift(new Location(world, pos)); + Rift rift = RiftRegistry.instance().getRift(new Location((ServerWorld) world, pos)); rift.isDetached = isDetached(); rift.markDirty(); } @@ -144,7 +141,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity if (destination == null) { return new MessageTarget("rifts.unlinked"); } else { - destination.setLocation(new Location(world, pos)); + destination.setLocation(new Location((ServerWorld) world, pos)); return destination; } } @@ -157,7 +154,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity EntityTarget target = getTarget().as(Targets.ENTITY); if (target.receiveEntity(entity, entity.yaw, entity.pitch)) { - VirtualLocation vloc = VirtualLocation.fromLocation(new Location(entity.world, entity.getBlockPos())); + VirtualLocation vloc = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getSenseCenterPos())); entity.sendMessage(new TranslatableText("You are at x = " + vloc.x + ", y = ?, z = " + vloc.z + ", w = " + vloc.depth)); return true; } @@ -176,7 +173,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity } else if (destination == null) { color = new float[]{0.7f, 0.7f, 0.7f, 1}; } else { - destination.setLocation(new Location(world, pos)); + destination.setLocation(new Location((ServerWorld) world, pos)); float[] newColor = destination.getColor(); if (color == null && newColor != null || !Arrays.equals(color, newColor)) { color = newColor; @@ -193,4 +190,24 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity alwaysDelete = rift.alwaysDelete; forcedColor = rift.forcedColor; } + + public VirtualTarget getDestination() { + return destination; + } + + public LinkProperties getProperties() { + return properties; + } + + public boolean isAlwaysDelete() { + return alwaysDelete; + } + + public boolean isForcedColor() { + return forcedColor; + } + + public float[] getColor() { + return color; + } } diff --git a/src/main/java/org/dimdev/dimdoors/commands/CommandDimTeleport.java b/src/main/java/org/dimdev/dimdoors/commands/CommandDimTeleport.java index 99efa5e6..1296f7ee 100644 --- a/src/main/java/org/dimdev/dimdoors/commands/CommandDimTeleport.java +++ b/src/main/java/org/dimdev/dimdoors/commands/CommandDimTeleport.java @@ -14,7 +14,7 @@ //import org.dimdev.util.Location; //import org.dimdev.util.TeleportUtil; // -//import javax.annotation.Nullable; +// //import java.util.Arrays; //import java.util.Collections; //import java.util.List; @@ -60,7 +60,7 @@ // } // // @Override -// public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) { +// public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) { // if (args.length == 1) { // return Arrays.stream(DimensionManager.getStaticDimensionIDs()) // .map(Object::toString) diff --git a/src/main/java/org/dimdev/dimdoors/commands/CommandPocket.java b/src/main/java/org/dimdev/dimdoors/commands/CommandPocket.java index c35f7957..0955c8df 100644 --- a/src/main/java/org/dimdev/dimdoors/commands/CommandPocket.java +++ b/src/main/java/org/dimdev/dimdoors/commands/CommandPocket.java @@ -18,7 +18,7 @@ //import org.dimdev.dimdoors.world.ModDimensions; //import org.dimdev.pocketlib.Pocket; // -//import javax.annotation.Nullable; +// //import java.util.ArrayList; //import java.util.List; //import java.util.stream.Collectors; @@ -76,7 +76,7 @@ // } // // @Override -// public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) { +// public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) { // List list = new ArrayList<>(); // switch (args.length) { // case 1: diff --git a/src/main/java/org/dimdev/dimdoors/entity/ModEntityTypes.java b/src/main/java/org/dimdev/dimdoors/entity/ModEntityTypes.java index 72c4c1d2..7a029f3d 100644 --- a/src/main/java/org/dimdev/dimdoors/entity/ModEntityTypes.java +++ b/src/main/java/org/dimdev/dimdoors/entity/ModEntityTypes.java @@ -15,6 +15,8 @@ public class ModEntityTypes { true, true, true, + 128, + 32, new EntityDimensions(3, 3, false) ); @@ -26,10 +28,12 @@ public class ModEntityTypes { true, true, true, + 128, + 32, new EntityDimensions(1, 1, false) ); - private static EntityType register(String id, EntityType.EntityFactory factory, EntityCategory category, boolean canSpawnFar, boolean saveable, boolean summonable, boolean immuneToFire, EntityDimensions dimensions) { - return Registry.register(Registry.ENTITY_TYPE, id, new EntityType<>(factory, category, canSpawnFar, saveable, summonable, immuneToFire, dimensions)); + private static EntityType register(String id, EntityType.EntityFactory factory, EntityCategory category, boolean canSpawnFar, boolean saveable, boolean summonable, boolean immuneToFire, int i, int j, EntityDimensions dimensions) { + return Registry.register(Registry.ENTITY_TYPE, id, new EntityType<>(factory, category, canSpawnFar, saveable, summonable, immuneToFire, i, j, dimensions)); } } diff --git a/src/main/java/org/dimdev/dimdoors/fluid/EternalLiquidFluid.java b/src/main/java/org/dimdev/dimdoors/fluid/EternalLiquidFluid.java index ee5ab4f2..fff9344a 100644 --- a/src/main/java/org/dimdev/dimdoors/fluid/EternalLiquidFluid.java +++ b/src/main/java/org/dimdev/dimdoors/fluid/EternalLiquidFluid.java @@ -48,7 +48,7 @@ public class EternalLiquidFluid extends BaseFluid { // TODO } @Override - protected boolean method_15777(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) { + protected boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) { return false; } diff --git a/src/main/java/org/dimdev/dimdoors/item/DimensionalDoorItem.java b/src/main/java/org/dimdev/dimdoors/item/DimensionalDoorItem.java index 479597f1..ba665041 100644 --- a/src/main/java/org/dimdev/dimdoors/item/DimensionalDoorItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/DimensionalDoorItem.java @@ -29,7 +29,6 @@ public class DimensionalDoorItem extends TallBlockItem { @Override public ActionResult place(ItemPlacementContext context) { BlockPos pos = context.getBlockPos(); - BlockPos originalPos = context.getBlockPos(); // super.onItemUse needs the actual position if (!context.getWorld().getBlockState(pos).canReplace(context)) { pos = pos.offset(context.getPlayerFacing()); diff --git a/src/main/java/org/dimdev/dimdoors/item/ModItems.java b/src/main/java/org/dimdev/dimdoors/item/ModItems.java index 2a68ce6a..4d30eac8 100644 --- a/src/main/java/org/dimdev/dimdoors/item/ModItems.java +++ b/src/main/java/org/dimdev/dimdoors/item/ModItems.java @@ -141,10 +141,10 @@ public final class ModItems { public static final Item RIFT_SIGNATURE = new RiftSignatureItem(new Item.Settings().maxCount(1).maxDamage(1).group(ModItemGroups.DIMENSIONAL_DOORS)); public static final Item STABILIZED_RIFT_SIGNATURE = new StabilizedRiftSignatureItem(new Item.Settings().maxCount(1).maxDamage(20).group(ModItemGroups.DIMENSIONAL_DOORS)); public static final Item RIFT_STABILIZER = new RiftStabilizerItem(new Item.Settings().maxCount(1).maxDamage(6).group(ModItemGroups.DIMENSIONAL_DOORS)); - public static final Item WOVEN_WORLD_THREAD_HELMET = new WorldThreadArmorItem("world_thread_helmet", 1, EquipmentSlot.HEAD); - public static final Item WOVEN_WORLD_THREAD_CHESTPLATE = new WorldThreadArmorItem("world_thread_chestplate", 1, EquipmentSlot.CHEST); - public static final Item WOVEN_WORLD_THREAD_LEGGINGS = new WorldThreadArmorItem("world_thread_leggings", 2, EquipmentSlot.LEGS); - public static final Item WOVEN_WORLD_THREAD_BOOTS = new WorldThreadArmorItem("world_thread_boots", 1, EquipmentSlot.FEET); + public static final Item WOVEN_WORLD_THREAD_HELMET = new WorldThreadArmorItem("world_thread_helmet", EquipmentSlot.HEAD, new Item.Settings()); + public static final Item WOVEN_WORLD_THREAD_CHESTPLATE = new WorldThreadArmorItem("world_thread_chestplate", EquipmentSlot.CHEST, new Item.Settings()); + public static final Item WOVEN_WORLD_THREAD_LEGGINGS = new WorldThreadArmorItem("world_thread_leggings", EquipmentSlot.LEGS, new Item.Settings()); + public static final Item WOVEN_WORLD_THREAD_BOOTS = new WorldThreadArmorItem("world_thread_boots", EquipmentSlot.FEET, new Item.Settings()); public static final Item CREEPY_RECORD = new MusicDiscItem(10, ModSoundEvents.CREEPY, new Item.Settings().group(ModItemGroups.DIMENSIONAL_DOORS)); public static final Item WHITE_VOID_RECORD = new MusicDiscItem(10, ModSoundEvents.CREEPY, new Item.Settings().group(ModItemGroups.DIMENSIONAL_DOORS)); @@ -172,6 +172,10 @@ public final class ModItems { return Registry.register(Registry.ITEM, identifier, item); } + public static void init() { + // just loads the class + } + private static class MusicDiscItem extends net.minecraft.item.MusicDiscItem { // TODO: access transformers protected MusicDiscItem(int i, SoundEvent soundEvent, Settings settings) { super(i, soundEvent, settings); diff --git a/src/main/java/org/dimdev/dimdoors/item/RiftBladeItem.java b/src/main/java/org/dimdev/dimdoors/item/RiftBladeItem.java index 0d95e66c..cd122992 100644 --- a/src/main/java/org/dimdev/dimdoors/item/RiftBladeItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/RiftBladeItem.java @@ -4,6 +4,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; import net.minecraft.item.ToolMaterials; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -47,7 +48,7 @@ public class RiftBladeItem extends SwordItem { if (RayTraceHelper.hitsLivingEntity(hit) || RayTraceHelper.hitsRift(hit, world)) { return new TypedActionResult<>(ActionResult.SUCCESS, stack); } else { - player.addChatMessage(new TranslatableText(getTranslationKey() + ".rift_miss"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".rift_miss")); DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; return new TypedActionResult<>(ActionResult.FAIL, stack); } @@ -59,14 +60,14 @@ public class RiftBladeItem extends SwordItem { double offsetDistance = Math.random() * damageMultiplier * 7 + 2; //TODO: make these offset distances configurable double offsetRotationYaw = (Math.random() - 0.5) * damageMultiplier * 360; - Vec3d playerVec = player.getPosVector(); + Vec3d playerVec = player.getPos(); Vec3d entityVec = hit.getPos(); Vec3d offsetDirection = playerVec.subtract(entityVec).normalize(); offsetDirection = offsetDirection.rotateY((float) (offsetRotationYaw * Math.PI) / 180); BlockPos tpPos = new BlockPos(entityVec.add(offsetDirection.multiply(offsetDistance))); while (world.getBlockState(tpPos).getMaterial().blocksMovement()) tpPos = tpPos.up(); // TODO: move to ddutils - TeleportUtil.teleport(player, new Location(world, tpPos), (player.yaw - (float) offsetRotationYaw) % 360, player.pitch); + TeleportUtil.teleport(player, new Location((ServerWorld) world, tpPos), (player.yaw - (float) offsetRotationYaw) % 360, player.pitch); stack.damage(1, player, a -> {}); return new TypedActionResult<>(ActionResult.SUCCESS, stack); diff --git a/src/main/java/org/dimdev/dimdoors/item/RiftConfigurationToolItem.java b/src/main/java/org/dimdev/dimdoors/item/RiftConfigurationToolItem.java index 2132e7a0..81ec234d 100644 --- a/src/main/java/org/dimdev/dimdoors/item/RiftConfigurationToolItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/RiftConfigurationToolItem.java @@ -1,18 +1,15 @@ package org.dimdev.dimdoors.item; import net.fabricmc.api.Environment; -import net.fabricmc.loader.metadata.ModMetadataV0; import net.minecraft.client.item.TooltipContext; import net.minecraft.client.resource.language.I18n; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.EggItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -21,10 +18,9 @@ import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.block.entity.RiftBlockEntity; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; -import javax.annotation.Nullable; import java.util.List; -import static net.fabricmc.api.EnvType.CLIENT; +import static net.fabricmc.api.EnvType.*; public class RiftConfigurationToolItem extends Item { @@ -41,7 +37,7 @@ public class RiftConfigurationToolItem extends Item { if (world.isClient) { if (!RayTraceHelper.hitsRift(hit, world)) { - player.addChatMessage(new TranslatableText("tools.rift_miss"), true); + player.sendMessage(new TranslatableText("tools.rift_miss")); DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; } return new TypedActionResult<>(ActionResult.FAIL, stack); @@ -60,7 +56,7 @@ public class RiftConfigurationToolItem extends Item { @Override @Environment(CLIENT) - public void appendTooltip(ItemStack itemStack, @Nullable World world, List list, TooltipContext tooltipContext) { + public void appendTooltip(ItemStack itemStack, World world, List list, TooltipContext tooltipContext) { if (I18n.hasTranslation(this.getTranslationKey() + ".info")) { list.add(new TranslatableText(this.getTranslationKey() + ".info")); } diff --git a/src/main/java/org/dimdev/dimdoors/item/RiftRemoverItem.java b/src/main/java/org/dimdev/dimdoors/item/RiftRemoverItem.java index e917e47a..5d312f30 100644 --- a/src/main/java/org/dimdev/dimdoors/item/RiftRemoverItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/RiftRemoverItem.java @@ -10,7 +10,6 @@ import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -20,7 +19,6 @@ import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; import org.dimdev.dimdoors.sound.ModSoundEvents; -import javax.annotation.Nullable; import java.util.List; public class RiftRemoverItem extends Item { @@ -31,8 +29,8 @@ public class RiftRemoverItem extends Item { } @Override - public void appendTooltip(ItemStack itemStack, @Nullable World world, List list, TooltipContext tooltipContext) { - if(I18n.hasTranslation(getTranslationKey() + ".info")) { + public void appendTooltip(ItemStack itemStack, World world, List list, TooltipContext tooltipContext) { + if (I18n.hasTranslation(getTranslationKey() + ".info")) { list.add(new TranslatableText(getTranslationKey() + ".info")); } } @@ -45,7 +43,7 @@ public class RiftRemoverItem extends Item { if (world.isClient) { if (!RayTraceHelper.hitsDetachedRift(hit, world)) { - player.addChatMessage(new TranslatableText("tools.rift_miss"), true); + player.sendMessage(new TranslatableText("tools.rift_miss")); DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; } return new TypedActionResult<>(ActionResult.FAIL, stack); @@ -55,12 +53,12 @@ public class RiftRemoverItem extends Item { DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos())); if (!rift.closing) { rift.setClosing(true); - world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1); + world.playSound(null, player.getSenseCenterPos(), ModSoundEvents.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1); stack.damage(10, player, a -> {}); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".closing"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".closing")); return new TypedActionResult<>(ActionResult.SUCCESS, stack); } else { - player.addChatMessage(new TranslatableText(getTranslationKey() + ".already_closing"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".already_closing")); } } return new TypedActionResult<>(ActionResult.FAIL, stack); diff --git a/src/main/java/org/dimdev/dimdoors/item/RiftSignatureItem.java b/src/main/java/org/dimdev/dimdoors/item/RiftSignatureItem.java index bceddae8..3578c3e4 100644 --- a/src/main/java/org/dimdev/dimdoors/item/RiftSignatureItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/RiftSignatureItem.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; @@ -17,7 +18,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; -import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.rift.targets.RiftReference; @@ -25,7 +25,6 @@ import org.dimdev.dimdoors.sound.ModSoundEvents; import org.dimdev.util.Location; import org.dimdev.util.RotatedLocation; -import javax.annotation.Nullable; import java.util.List; public class RiftSignatureItem extends Item { @@ -66,38 +65,36 @@ public class RiftSignatureItem extends Item { if (target == null) { // The link signature has not been used. Store its current target as the first location. - setSource(stack, new RotatedLocation(world, pos, player.yaw, 0)); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".stored"), true); - world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1); + setSource(stack, new RotatedLocation((ServerWorld) world, pos, player.yaw, 0)); + player.sendMessage(new TranslatableText(getTranslationKey() + ".stored")); + world.playSound(null, player.getSenseCenterPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1); } else { // Place a rift at the saved point if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) { if (!target.getBlockState().getBlock().canMobSpawnInside()) { - DimDoors.sendTranslatedMessage(player, "tools.target_became_block"); + player.sendMessage(new TranslatableText("tools.target_became_block")); clearSource(stack); // TODO: But is this fair? It's a rather hidden way of unbinding your signature! return ActionResult.FAIL; } - World sourceWorld = ((Location) target).world; - sourceWorld.setBlockState(((Location) target).getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState()); + World sourceWorld = target.world; + sourceWorld.setBlockState(target.getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState()); DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity(); - rift1.setDestination(RiftReference.tryMakeRelative(target, new Location(world, pos))); - rift1.setTeleportTargetRotation(target.yaw, 0); // setting pitch to 0 because player is always facing down to place rift + rift1.setDestination(RiftReference.tryMakeRelative(target, new Location((ServerWorld) world, pos))); rift1.register(); } // Place a rift at the target point world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState()); DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos); - rift2.setDestination(RiftReference.tryMakeRelative(new Location(world, pos), target)); - rift2.setTeleportTargetRotation(player.yaw, 0); + rift2.setDestination(RiftReference.tryMakeRelative(new Location((ServerWorld) world, pos), target)); rift2.register(); stack.damage(1, player, a -> {}); // TODO: calculate damage based on position? clearSource(stack); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".created"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".created")); // null = send sound to the player too, we have to do this because this code is not run client-side - world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_END, SoundCategory.BLOCKS, 0.6f, 1); + world.playSound(null, player.getSenseCenterPos(), ModSoundEvents.RIFT_END, SoundCategory.BLOCKS, 0.6f, 1); } return ActionResult.SUCCESS; @@ -116,8 +113,7 @@ public class RiftSignatureItem extends Item { public static RotatedLocation getSource(ItemStack itemStack) { if (itemStack.hasTag() && itemStack.getTag().contains("destination")) { - RotatedLocation transform = RotatedLocation.deserialize(itemStack.getTag().getCompound("destination")); - return transform; + return RotatedLocation.deserialize(itemStack.getTag().getCompound("destination")); } else { return null; } @@ -125,7 +121,7 @@ public class RiftSignatureItem extends Item { @Override @Environment(EnvType.CLIENT) - public void appendTooltip(ItemStack itemStack, @Nullable World world, List list, TooltipContext tooltipContext) { + public void appendTooltip(ItemStack itemStack, World world, List list, TooltipContext tooltipContext) { RotatedLocation transform = getSource(itemStack); if (transform != null) { list.add(new TranslatableText(getTranslationKey() + ".bound.info", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId())); diff --git a/src/main/java/org/dimdev/dimdoors/item/RiftStabilizerItem.java b/src/main/java/org/dimdev/dimdoors/item/RiftStabilizerItem.java index ac770122..5be1c22a 100644 --- a/src/main/java/org/dimdev/dimdoors/item/RiftStabilizerItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/RiftStabilizerItem.java @@ -20,7 +20,7 @@ import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; import org.dimdev.dimdoors.sound.ModSoundEvents; -import javax.annotation.Nullable; + import java.util.List; public class RiftStabilizerItem extends Item { @@ -40,7 +40,7 @@ public class RiftStabilizerItem extends Item { // TODO: not necessarily success, fix this and all other similar cases to make arm swing correct return new TypedActionResult<>(ActionResult.SUCCESS, stack); } else { - player.addChatMessage(new TranslatableText("tools.rift_miss"), true); + player.sendMessage(new TranslatableText("tools.rift_miss")); DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; return new TypedActionResult<>(ActionResult.FAIL, stack); } @@ -50,12 +50,12 @@ public class RiftStabilizerItem extends Item { DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos())); if (!rift.stabilized && !rift.closing) { rift.setStabilized(true); - world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1); // TODO: different sound + world.playSound(null, player.getSenseCenterPos(), ModSoundEvents.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1); // TODO: different sound stack.damage(1, player, a -> {}); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".stabilized"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".stabilized")); return new TypedActionResult<>(ActionResult.SUCCESS, stack); } else { - player.addChatMessage(new TranslatableText(getTranslationKey() + ".already_stabilized"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".already_stabilized")); } } return new TypedActionResult<>(ActionResult.FAIL, stack); @@ -63,7 +63,7 @@ public class RiftStabilizerItem extends Item { @Environment(EnvType.CLIENT) @Override - public void appendTooltip(ItemStack itemStack, @Nullable World world, List list, TooltipContext tooltipContext) { + public void appendTooltip(ItemStack itemStack, World world, List list, TooltipContext tooltipContext) { list.add(new TranslatableText(getTranslationKey() + ".info")); } } diff --git a/src/main/java/org/dimdev/dimdoors/item/StabilizedRiftSignatureItem.java b/src/main/java/org/dimdev/dimdoors/item/StabilizedRiftSignatureItem.java index 5a6663d3..3755d00d 100644 --- a/src/main/java/org/dimdev/dimdoors/item/StabilizedRiftSignatureItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/StabilizedRiftSignatureItem.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; @@ -15,7 +16,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; -import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.rift.targets.RiftReference; @@ -23,7 +23,7 @@ import org.dimdev.dimdoors.sound.ModSoundEvents; import org.dimdev.util.Location; import org.dimdev.util.RotatedLocation; -import javax.annotation.Nullable; + import java.util.List; public class StabilizedRiftSignatureItem extends Item { // TODO: common superclass with rift signature @@ -64,33 +64,31 @@ public class StabilizedRiftSignatureItem extends Item { // TODO: common supercla if (target == null) { // The link signature has not been used. Store its current target as the first location. setSource(stack, new RotatedLocation(world, pos, player.yaw, 0)); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".stored"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".stored"), true); world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1); } else { // Place a rift at the target point if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) { if (!target.getBlockState().getBlock().canReplace(world.getBlockState(((Location) target).getBlockPos()), itemPlacementContext)) { - DimDoors.sendTranslatedMessage(player, "tools.target_became_block"); + player.sendMessage(new TranslatableText("tools.target_became_block")); // Don't clear source, stabilized signatures always stay bound return ActionResult.FAIL; } World targetWorld = ((Location) target).world; targetWorld.setBlockState(((Location) target).getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState()); DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity(); - rift1.setTeleportTargetRotation(target.yaw, 0); rift1.register(); } // Place a rift at the source point world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState()); DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos); - rift2.setDestination(RiftReference.tryMakeRelative(new Location(world, pos), target)); - rift2.setTeleportTargetRotation(player.yaw, 0); + rift2.setDestination(RiftReference.tryMakeRelative(new Location((ServerWorld) world, pos), target)); rift2.register(); stack.damage(1, player, playerEntity -> {}); - player.addChatMessage(new TranslatableText(getTranslationKey() + ".created"), true); + player.sendMessage(new TranslatableText(getTranslationKey() + ".created"), true); world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_END, SoundCategory.BLOCKS, 0.6f, 1); } @@ -118,7 +116,7 @@ public class StabilizedRiftSignatureItem extends Item { // TODO: common supercla } @Override - public void appendTooltip(ItemStack itemStack, @Nullable World world, List list, TooltipContext tooltipContext) { + public void appendTooltip(ItemStack itemStack, World world, List list, TooltipContext tooltipContext) { RotatedLocation transform = getTarget(itemStack); if (transform != null) { diff --git a/src/main/java/org/dimdev/dimdoors/item/WorldThreadArmorItem.java b/src/main/java/org/dimdev/dimdoors/item/WorldThreadArmorItem.java index 8152bd22..73e86909 100644 --- a/src/main/java/org/dimdev/dimdoors/item/WorldThreadArmorItem.java +++ b/src/main/java/org/dimdev/dimdoors/item/WorldThreadArmorItem.java @@ -1,27 +1,56 @@ package org.dimdev.dimdoors.item; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.init.SoundEvents; import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorMaterial; -import net.minecraft.item.ItemStack; -import net.minecraft.sound.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.recipe.Ingredient; +import net.minecraft.sound.SoundEvent; public class WorldThreadArmorItem extends ArmorItem { - public static final ArmorMaterial WOVEN_WORLD_THREAD = EnumHelper.addArmorMaterial( - "woven_world_thread", - "dimdoors:woven_world_thread", - 20, - new int[]{2, 3, 4, 5}, - 20, - SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, - 1.0f) - .setRepairItem(new ItemStack(ModItems.WORLD_THREAD)); + public static final ArmorMaterial MATERIAL = new ArmorMaterial() { + @Override + public int getDurability(EquipmentSlot equipmentSlot) { + return 20; + } - public WorldThreadArmorItem(String name, int renderIndex, EquipmentSlot equipmentSlot) { - super(WOVEN_WORLD_THREAD, renderIndex, equipmentSlot); - setRegistryName("dimdoors", name); - setTranslationKey(name); - setCreativeTab(ModItemGroups.DIMENSIONAL_DOORS); + @Override + public int getProtectionAmount(EquipmentSlot equipmentSlot) { + return new int[]{2, 3, 4, 5}[equipmentSlot.getEntitySlotId()]; + } + + @Override + public int getEnchantability() { + return 20; + } + + @Override + public SoundEvent getEquipSound() { + return null; + } + + @Override + public Ingredient getRepairIngredient() { + return Ingredient.ofItems(ModItems.WORLD_THREAD); + } + + @Override + public String getName() { + return "woven_world_thread"; + } + + @Override + public float getToughness() { + return 1; + } + + @Override + public float getKnockbackResistance() { + return 0; + } + }; + + public WorldThreadArmorItem(String name, EquipmentSlot equipmentSlot, Item.Settings settings) { + super(MATERIAL, equipmentSlot, settings); } } diff --git a/src/main/java/org/dimdev/dimdoors/pockets/PocketGenerator.java b/src/main/java/org/dimdev/dimdoors/pockets/PocketGenerator.java index 573b1793..8c340de2 100644 --- a/src/main/java/org/dimdev/dimdoors/pockets/PocketGenerator.java +++ b/src/main/java/org/dimdev/dimdoors/pockets/PocketGenerator.java @@ -1,46 +1,53 @@ package org.dimdev.dimdoors.pockets; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.dimdev.dimdoors.ModConfig; -import org.dimdev.dimdoors.rift.targets.VirtualTarget; import org.dimdev.dimdoors.rift.registry.LinkProperties; +import org.dimdev.dimdoors.rift.targets.VirtualTarget; import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.pocketlib.Pocket; import org.dimdev.pocketlib.PocketRegistry; import org.dimdev.pocketlib.VirtualLocation; +import org.dimdev.util.WorldUtils; import java.util.Random; public final class PocketGenerator { - private static Pocket prepareAndPlacePocket(int dim, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) { + private static final Logger LOGGER = LogManager.getLogger(); + + 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(dim).newPocket(); - pocketTemplate.place(pocket, setup); - pocket.setVirtualLocation(virtualLocation); - return pocket; + Pocket pocket = PocketRegistry.instance(world).newPocket(); + pocketTemplate.place(pocket, setup); + pocket.virtualLocation = virtualLocation; + return pocket; } - public static Pocket generatePocketFromTemplate(int dim, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) { - Pocket pocket = prepareAndPlacePocket(dim, pocketTemplate, virtualLocation, setup); + 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 generatePocketFromTemplate(int dim, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) { - Pocket pocket = prepareAndPlacePocket(dim, pocketTemplate, virtualLocation, true); + 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 generatePrivatePocket(VirtualLocation virtualLocation) { PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate(); - return generatePocketFromTemplate(ModDimensions.getPrivateDim(), pocketTemplate, virtualLocation, true); + return generatePocketFromTemplate(WorldUtils.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(ModDimensions.getPublicDim(), pocketTemplate, virtualLocation, linkTo, linkProperties); + return generatePocketFromTemplate(WorldUtils.getWorld(ModDimensions.PUBLIC), pocketTemplate, virtualLocation, linkTo, linkProperties); } /** @@ -51,11 +58,11 @@ public final class PocketGenerator { */ public static Pocket generateDungeonPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) { int depth = virtualLocation.depth; - float netherProbability = virtualLocation.dimension == -1 ? 1 : (float) depth / 200; // TODO: improve nether probability + float netherProbability = virtualLocation.world.dimension.isNether() ? 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.POCKETS.maxPocketSize, false); - return generatePocketFromTemplate(ModDimensions.getDungeonDim(), pocketTemplate, virtualLocation, linkTo, linkProperties); + return generatePocketFromTemplate(WorldUtils.getWorld(ModDimensions.DUNGEON), pocketTemplate, virtualLocation, linkTo, linkProperties); } } diff --git a/src/main/java/org/dimdev/dimdoors/pockets/PocketTemplate.java b/src/main/java/org/dimdev/dimdoors/pockets/PocketTemplate.java index fa096fbf..03c3952d 100644 --- a/src/main/java/org/dimdev/dimdoors/pockets/PocketTemplate.java +++ b/src/main/java/org/dimdev/dimdoors/pockets/PocketTemplate.java @@ -1,69 +1,79 @@ package org.dimdev.dimdoors.pockets; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.ChestBlockEntity; import net.minecraft.block.entity.DispenserBlockEntity; -import net.minecraft.block.state.BlockState; -import net.minecraft.inventory.IInventory; 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.tileentity.CoordinateArgument; -import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.tileentity.TileEntityDispenser; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraft.world.storage.loot.LootContext; -import net.minecraft.world.storage.loot.LootTable; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +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.loottables.ModLootTables; +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.pocketlib.Pocket; +import org.dimdev.pocketlib.PocketRegistry; import org.dimdev.util.Location; import org.dimdev.util.math.MathUtil; import org.dimdev.util.schem.Schematic; -import org.dimdev.dimdoors.entity.MonolithEntity; -import org.dimdev.dimdoors.rift.targets.VirtualTarget; -import org.dimdev.dimdoors.block.entity.RiftBlockEntity; -import org.dimdev.dimdoors.rift.targets.PocketEntranceMarker; -import org.dimdev.dimdoors.rift.targets.PocketExitMarker; -import org.dimdev.dimdoors.rift.registry.LinkProperties; -import org.dimdev.dimdoors.rift.registry.RiftRegistry; -import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity; -import org.dimdev.pocketlib.Pocket; -import org.dimdev.pocketlib.PocketRegistry; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; /** * @author Robijnvogel */ -@AllArgsConstructor @RequiredArgsConstructor public class PocketTemplate { private static final Logger LOGGER = LogManager.getLogger(); - @Getter private final String group; - @Getter private final String id; - @Getter private final String type; - @Getter private final String name; - @Getter private final String author; - @Getter @Setter private Schematic schematic; - @Setter private byte[] schematicBytecode; - @Getter private int size; // number of chunks (16 blocks) on each side - 1 - @Getter private int baseWeight; - @Getter private static boolean isReplacingPlaceholders = false; + private final String group; + private final String id; + private final String type; + private final String name; + private final String author; + private Schematic schematic; + private byte[] schematicBytecode; + private int size; // number of chunks (16 blocks) on each side - 1 + private int baseWeight; + private static boolean isReplacingPlaceholders = false; + + public PocketTemplate(String group, String id, String type, String name, String author) { + this.group = group; + this.id = id; + this.type = type; + this.name = name; + this.author = author; + } + + public PocketTemplate(String group, String id, String type, String name, String author, Schematic schematic, byte[] schematicBytecode, int size, int baseWeight) { + this.group = group; + this.id = id; + this.type = type; + this.name = name; + this.author = author; + this.schematic = schematic; + this.schematicBytecode = schematicBytecode; + this.size = size; + this.baseWeight = baseWeight; + } + + public static boolean isReplacingPlaceholders() {return PocketTemplate.isReplacingPlaceholders;} public float getWeight(int depth) { - //noinspection IfStatementWithIdenticalBranches if (depth == -1) { return baseWeight; } else { @@ -102,7 +112,6 @@ public class PocketTemplate { rift.setPos(new BlockPos(x, y, z)); rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties); rift.setDestination(DefaultDungeonDestinations.overworldDestination); - rift.setLeaveRiftOnBreak(true); newNBT = rift.toTag(newNBT); break; case "entrance_door": @@ -131,7 +140,7 @@ public class PocketTemplate { List entities = new ArrayList<>(); for (CompoundTag entitiesNBT : schematic.entities) { - if (entitiesNBT.hasKey("placeholder")) { + if (entitiesNBT.contains("placeholder")) { double x = entitiesNBT.getDouble("x"); double y = entitiesNBT.getDouble("y"); double z = entitiesNBT.getDouble("z"); @@ -141,8 +150,10 @@ public class PocketTemplate { CompoundTag newNBT; if ("monolith".equals(entitiesNBT.getString("placeholder"))) { MonolithEntity monolith = ModEntityTypes.MONOLITH.create(null); - monolith.setPositionAndAngles(x, y, z, yaw, pitch); - newNBT = monolith.serializeNBT(); + 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")); } @@ -163,7 +174,7 @@ public class PocketTemplate { int xBase = pocket.getX() * gridSize * 16; int yBase = 0; int zBase = pocket.getZ() * gridSize * 16; - + //Converting the schematic from bytearray if needed if (schematic == null) { LOGGER.debug("Schematic is null, trying to reload from byteArray."); @@ -174,7 +185,7 @@ public class PocketTemplate { //Place the schematic LOGGER.info("Placing new pocket using schematic " + id + " at x = " + xBase + ", z = " + zBase); schematic.place(world, xBase, yBase, zBase); - + SchematicHandler.INSTANCE.incrementUsage(this); if (!setup && !SchematicHandler.INSTANCE.isUsedOftenEnough(this)) { //remove schematic from "cache" @@ -201,7 +212,7 @@ public class PocketTemplate { if (tile instanceof RiftBlockEntity) { LOGGER.debug("Rift found in schematic at " + pos); RiftBlockEntity rift = (RiftBlockEntity) tile; - rift.getDestination().setLocation(new Location(rift.getWorld(), rift.getPos())); + rift.getDestination().setLocation(new Location((ServerWorld) rift.getWorld(), rift.getPos())); rifts.add(rift); } else if (tile instanceof Inventory) { Inventory inventory = (Inventory) tile; @@ -250,7 +261,7 @@ public class PocketTemplate { PocketRegistry.instance(world).markDirty(); rift.setDestination(((PocketEntranceMarker) dest).getIfDestination()); rift.register(); - RiftRegistry.instance().addPocketEntrance(pocket, new Location(rift.getWorld(), rift.getPos())); + RiftRegistry.instance().addPocketEntrance(pocket, new Location((ServerWorld) rift.getWorld(), rift.getPos())); } else { rift.setDestination(((PocketEntranceMarker) dest).getOtherwiseDestination()); } @@ -263,9 +274,6 @@ public class PocketTemplate { if (dest instanceof PocketExitMarker) { if (linkProperties != null) rift.setProperties(linkProperties); rift.setDestination(rift.getProperties() == null || !rift.getProperties().oneWay ? linkTo : null); - if (rift instanceof EntranceRiftBlockEntity && !rift.isAlwaysDelete()) { - ((EntranceRiftBlockEntity) rift).setLeaveRiftOnBreak(true); // We modified the door's state - } } } @@ -274,10 +282,30 @@ public class PocketTemplate { rift.register(); rift.markDirty(); } - + if (!SchematicHandler.INSTANCE.isUsedOftenEnough(this)) { //remove schematic from "cache" schematic = null; } } + + public String getGroup() {return group;} + + public String getId() {return id;} + + public String getType() {return type;} + + public String getName() {return name;} + + public String getAuthor() {return author;} + + public Schematic getSchematic() {return schematic;} + + public int getSize() {return size;} + + public int getBaseWeight() {return baseWeight;} + + public void setSchematic(Schematic schematic) {this.schematic = schematic; } + + public void setSchematicBytecode(byte[] schematicBytecode) {this.schematicBytecode = schematicBytecode; } } diff --git a/src/main/java/org/dimdev/dimdoors/pockets/SchematicHandler.java b/src/main/java/org/dimdev/dimdoors/pockets/SchematicHandler.java index dce1f1fc..56ef081d 100644 --- a/src/main/java/org/dimdev/dimdoors/pockets/SchematicHandler.java +++ b/src/main/java/org/dimdev/dimdoors/pockets/SchematicHandler.java @@ -204,7 +204,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or String name = pocket.has("name") ? pocket.get("name").getAsString() : null; String author = pocket.has("author") ? pocket.get("author").getAsString() : null; int baseWeight = pocket.has("baseWeight") ? pocket.get("baseWeight").getAsInt() : 100; - pocketTemplates.add(new PocketTemplate(group, id, type, name, author, size, baseWeight)); + pocketTemplates.add(new PocketTemplate(group, id, type, name, author, null, null, size, baseWeight)); } return pocketTemplates.stream().sorted(Comparator.comparing(PocketTemplate::getId)).collect(Collectors.toList()); diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/LinkProperties.java b/src/main/java/org/dimdev/dimdoors/rift/registry/LinkProperties.java index 6f4714d8..3b625aa2 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/LinkProperties.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/LinkProperties.java @@ -27,12 +27,6 @@ public class LinkProperties { public static LinkPropertiesBuilder builder() {return new LinkPropertiesBuilder();} - @Override - public void fromTag(CompoundTag nbt) { AnnotatedNbt.fromTag(this, nbt); } - - @Override - public CompoundTag toTag(CompoundTag nbt) { return AnnotatedNbt.toTag(this, nbt); } - public boolean equals(final Object o) { if (o == this) return true; if (!(o instanceof LinkProperties)) return false; diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/PocketEntrancePointer.java b/src/main/java/org/dimdev/dimdoors/rift/registry/PocketEntrancePointer.java index 82fa10d1..bf4192ab 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/PocketEntrancePointer.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/PocketEntrancePointer.java @@ -1,14 +1,15 @@ package org.dimdev.dimdoors.rift.registry; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.World; import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.AnnotatedNbt; public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass? - @Saved public int pocketDim; + @Saved public World pocketDim; @Saved public int pocketId; - public PocketEntrancePointer(int pocketDim, int pocketId) { + public PocketEntrancePointer(World pocketDim, int pocketId) { this.pocketDim = pocketDim; this.pocketId = pocketId; } diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/RegistryVertex.java b/src/main/java/org/dimdev/dimdoors/rift/registry/RegistryVertex.java index b040f041..beeeac47 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/RegistryVertex.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/RegistryVertex.java @@ -1,41 +1,32 @@ package org.dimdev.dimdoors.rift.registry; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; import org.dimdev.annotatednbt.Saved; -import org.dimdev.dimdoors.DimDoors; import org.dimdev.annotatednbt.AnnotatedNbt; import java.util.UUID; public abstract class RegistryVertex { - public int dim; // The dimension to store this object in. Links are stored in both registries. + public ServerWorld world; // The dimension to store this object in. Links are stored in both registries. @Saved public UUID id = UUID.randomUUID(); // Used to create pointers to registry vertices. Should not be used for anything other than saving. public void sourceGone(RegistryVertex source) { - LOGGER.debug("Notified vertex " + this + " that source " + source + " is gone"); - RiftRegistry.instance().markSubregistryDirty(dim); } public void targetGone(RegistryVertex target) { - LOGGER.debug("Notified vertex " + this + " that target " + target + " is gone"); - RiftRegistry.instance().markSubregistryDirty(dim); } public void sourceAdded(RegistryVertex source) { - LOGGER.debug("Notified vertex " + this + " that source " + source + " was added"); - RiftRegistry.instance().markSubregistryDirty(dim); } public void targetAdded(RegistryVertex target) { - LOGGER.debug("Notified vertex " + this + " that target " + target + " was added"); - RiftRegistry.instance().markSubregistryDirty(dim); } - @Override public void fromTag(CompoundTag nbt) { AnnotatedNbt.fromTag(this, nbt); } - @Override public CompoundTag toTag(CompoundTag nbt) { return AnnotatedNbt.toTag(this, nbt); } - public String toString() {return "RegistryVertex(dim=" + this.dim + ", id=" + this.id + ")";} + public String toString() {return "RegistryVertex(dim=" + this.world + ", id=" + this.id + ")";} } diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/Rift.java b/src/main/java/org/dimdev/dimdoors/rift/registry/Rift.java index 6e9b4da0..0313b656 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/Rift.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/Rift.java @@ -50,8 +50,7 @@ public class Rift extends RegistryVertex { ((RiftBlockEntity) location.getBlockEntity()).updateColor(); } - public void markDirty() { // TODO: better name - RiftRegistry.instance().markSubregistryDirty(dim); + public void markDirty() { ((RiftBlockEntity) location.getBlockEntity()).updateColor(); for (Location location : RiftRegistry.instance().getSources(location)) { RiftRegistry.instance().getRift(location).targetChanged(this); diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/RiftPlaceholder.java b/src/main/java/org/dimdev/dimdoors/rift/registry/RiftPlaceholder.java index eb3cbb25..e6d1b6d1 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/RiftPlaceholder.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/RiftPlaceholder.java @@ -3,7 +3,6 @@ package org.dimdev.dimdoors.rift.registry; import net.minecraft.nbt.CompoundTag; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.dimdev.dimdoors.DimDoors; public class RiftPlaceholder extends Rift { // TODO: don't extend rift private static final Logger LOGGER = LogManager.getLogger(); @@ -25,7 +24,7 @@ public class RiftPlaceholder extends Rift { // TODO: don't extend rift @Override public void markDirty() { - RiftRegistry.instance().markSubregistryDirty(dim); + RiftRegistry.instance().markSubregistryDirty(world); } @Override diff --git a/src/main/java/org/dimdev/dimdoors/rift/registry/RiftRegistry.java b/src/main/java/org/dimdev/dimdoors/rift/registry/RiftRegistry.java index 883b413c..4683aea2 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/registry/RiftRegistry.java +++ b/src/main/java/org/dimdev/dimdoors/rift/registry/RiftRegistry.java @@ -3,9 +3,9 @@ package org.dimdev.dimdoors.rift.registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.util.Identifier; import net.minecraft.world.PersistentState; -import net.minecraft.world.storage.MapStorage; -import net.minecraftforge.common.DimensionManager; +import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.dimdev.pocketlib.Pocket; @@ -22,119 +22,17 @@ import java.util.stream.Collectors; public class RiftRegistry extends PersistentState { private static final Logger LOGGER = LogManager.getLogger(); + private static final String DATA_NAME = "rifts"; - private static final String DATA_NAME = "dimdoors_global_rifts"; - private static final String SUBREGISTRY_DATA_NAME = "dimdoors_rifts"; - - protected Map subregistries = new HashMap<>(); - private static RiftRegistry riftRegistry = null; // For use by RiftSubregistry only - private static int currentDim; // For use by RiftSubregistry only protected DefaultDirectedGraph graph = new DefaultDirectedGraph<>(DefaultEdge.class); - // TODO: add methods that automatically add vertices/edges and mark appropriate subregistries as dirty - - // Caches to avoid looping through vertices to find specific vertices protected Map locationMap = new HashMap<>(); protected Map pocketEntranceMap = new HashMap<>(); protected Map uuidMap = new HashMap<>(); - // These are stored in the main registry protected Map lastPrivatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket protected Map lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket protected Map overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld - // - - public static class RiftSubregistry extends PersistentState { - private int dim; - - public RiftSubregistry() { - super(SUBREGISTRY_DATA_NAME); - } - - public RiftSubregistry(String s) { - super(s); - } - - @Override - public void fromTag(CompoundTag nbt) { - dim = currentDim; - if (riftRegistry == null || riftRegistry.subregistries.get(dim) != null) return; - - // Read rifts in this dimension - ListTag riftsNBT = (ListTag) nbt.getTag("rifts"); - for (Tag riftNBT : riftsNBT) { - Rift rift = new Rift(); - rift.fromTag((CompoundTag) riftNBT); - rift.dim = dim; - riftRegistry.graph.addVertex(rift); - riftRegistry.uuidMap.put(rift.id, rift); - riftRegistry.locationMap.put(rift.location, rift); - } - - ListTag pocketsNBT = (ListTag) nbt.getTag("pockets"); - for (Tag pocketNBT : pocketsNBT) { - PocketEntrancePointer pocket = new PocketEntrancePointer(); - pocket.fromTag((CompoundTag) pocketNBT); - pocket.dim = dim; - riftRegistry.graph.addVertex(pocket); - riftRegistry.uuidMap.put(pocket.id, pocket); - riftRegistry.pocketEntranceMap.put(PocketRegistry.instance(pocket.dim).getPocket(pocket.pocketId), pocket); - } - - // Read the connections between links that have a source or destination in this dimension - ListTag linksNBT = (ListTag) nbt.getTag("links"); - for (Tag linkNBT : linksNBT) { - RegistryVertex from = riftRegistry.uuidMap.get(((CompoundTag) linkNBT).getUuid("from")); - RegistryVertex to = riftRegistry.uuidMap.get(((CompoundTag) linkNBT).getUuid("to")); - if (from != null && to != null) { - riftRegistry.graph.addEdge(from, to); - // We need a system for detecting links that are incomplete after processing them in the other subregistry too - } - } - } - - // Even though it seems like we could loop only once over the vertices and edges (in the RiftRegistry's toTag - // method rather than RiftSubregistry) and save each in the appropriate registry, we can't do this because it is not - // always the case that all worlds will be saved at once. - @Override - public CompoundTag toTag(CompoundTag nbt) { - if (riftRegistry == null) riftRegistry = RiftRegistry.instance(); - // Write rifts in this dimension - ListTag riftsNBT = new ListTag(); - ListTag pocketsNBT = new ListTag(); - for (RegistryVertex vertex : riftRegistry.graph.vertexSet()) { - if (vertex.dim == dim) { - CompoundTag vertexNBT = vertex.toTag(new CompoundTag()); - if (vertex instanceof Rift) { - riftsNBT.appendTag(vertexNBT); - } else if (vertex instanceof PocketEntrancePointer) { - pocketsNBT.appendTag(vertexNBT); - } else if (!(vertex instanceof PlayerRiftPointer)) { - throw new RuntimeException("Unsupported registry vertex type " + vertex.getClass().getName()); - } - } - } - nbt.put("rifts", riftsNBT); - nbt.put("pockets", pocketsNBT); - - // Write the connections between links that have a source or destination in this dimension - ListTag linksNBT = new ListTag(); - for (DefaultEdge edge : riftRegistry.graph.edgeSet()) { - RegistryVertex from = riftRegistry.graph.getEdgeSource(edge); - RegistryVertex to = riftRegistry.graph.getEdgeTarget(edge); - if (from.dim == dim || to.dim == dim && !(from instanceof PlayerRiftPointer)) { - CompoundTag linkNBT = new CompoundTag(); - linkNBT.putUuid("from", from.id); - linkNBT.putUuid("to", to.id); - linksNBT.appendTag(linkNBT); - } - } - nbt.put("links", linksNBT); - - return nbt; - } - } - public RiftRegistry() { super(DATA_NAME); } @@ -144,47 +42,78 @@ public class RiftRegistry extends PersistentState { } public static RiftRegistry instance() { - MapStorage storage = WorldUtils.getWorld(0).getMapStorage(); - RiftRegistry instance = (RiftRegistry) storage.getOrLoadData(RiftRegistry.class, DATA_NAME); - - if (instance == null) { - instance = new RiftRegistry(); - storage.setData(DATA_NAME, instance); - } - - return instance; + return WorldUtils.getWorld(DimensionType.OVERWORLD).getPersistentStateManager().get(RiftRegistry::new, DATA_NAME); } @Override public void fromTag(CompoundTag nbt) { + // Read rifts in this dimension - // Trigger the subregistry reading code for all dimensions. It would be better if there was some way of forcing - // them to be read from somewhere else, since this is technically more than just reading the NBT and can cause - // problems with recursion without riftRegistry. This has to be done first since links are only - // in the subregistries. - // TODO: If non-dirty but new WorldSavedDatas aren't automatically saved, then create the subregistries here - // TODO: rather then in the markSubregistryDirty method. - // TODO: try to get rid of this code: - riftRegistry = this; - for (int dim : DimensionManager.getStaticDimensionIDs()) { - MapStorage storage = WorldUtils.getWorld(dim).getPerWorldStorage(); - currentDim = dim; - RiftSubregistry instance = (RiftSubregistry) storage.getOrLoadData(RiftSubregistry.class, SUBREGISTRY_DATA_NAME); - if (instance != null) { - instance.dim = dim; - subregistries.put(dim, instance); + ListTag riftsNBT = (ListTag) nbt.get("rifts"); + for (Tag riftNBT : riftsNBT) { + Rift rift = new Rift(); + rift.fromTag((CompoundTag) riftNBT); + graph.addVertex(rift); + uuidMap.put(rift.id, rift); + locationMap.put(rift.location, rift); + } + + ListTag pocketsNBT = (ListTag) nbt.get("pockets"); + for (Tag pocketNBT : pocketsNBT) { + PocketEntrancePointer pocket = new PocketEntrancePointer(); + pocket.fromTag((CompoundTag) pocketNBT); + graph.addVertex(pocket); + uuidMap.put(pocket.id, pocket); + pocketEntranceMap.put(PocketRegistry.instance(pocket.world).getPocket(pocket.pocketId), pocket); + } + + // Read the connections between links that have a source or destination in this dimension + ListTag linksNBT = (ListTag) nbt.get("links"); + for (Tag linkNBT : linksNBT) { + RegistryVertex from = uuidMap.get(((CompoundTag) linkNBT).getUuidNew("from")); + RegistryVertex to = uuidMap.get(((CompoundTag) linkNBT).getUuidNew("to")); + if (from != null && to != null) { + graph.addEdge(from, to); + // We need a system for detecting links that are incomplete after processing them in the other subregistry too } } - riftRegistry = null; - // Read player to rift maps (this has to be done after the uuidMap has been filled by the subregistry code) - lastPrivatePocketEntrances = readPlayerRiftPointers((ListTag) nbt.getTag("lastPrivatePocketEntrances")); - lastPrivatePocketExits = readPlayerRiftPointers((ListTag) nbt.getTag("lastPrivatePocketExits")); - overworldRifts = readPlayerRiftPointers((ListTag) nbt.getTag("overworldRifts")); + lastPrivatePocketEntrances = readPlayerRiftPointers((ListTag) nbt.get("lastPrivatePocketEntrances")); + lastPrivatePocketExits = readPlayerRiftPointers((ListTag) nbt.get("lastPrivatePocketExits")); + overworldRifts = readPlayerRiftPointers((ListTag) nbt.get("overworldRifts")); } @Override public CompoundTag toTag(CompoundTag tag) { + if (this == null) {} + // Write rifts in this dimension + ListTag riftsNBT = new ListTag(); + ListTag pocketsNBT = new ListTag(); + for (RegistryVertex vertex : graph.vertexSet()) { + CompoundTag vertexNBT = vertex.toTag(new CompoundTag()); + if (vertex instanceof Rift) { + riftsNBT.add(vertexNBT); + } else if (vertex instanceof PocketEntrancePointer) { + pocketsNBT.add(vertexNBT); + } else if (!(vertex instanceof PlayerRiftPointer)) { + throw new RuntimeException("Unsupported registry vertex type " + vertex.getClass().getName()); + } + } + tag.put("rifts", riftsNBT); + tag.put("pockets", pocketsNBT); + + // Write the connections between links that have a source or destination in this dimension + ListTag linksNBT = new ListTag(); + for (DefaultEdge edge : graph.edgeSet()) { + RegistryVertex from = graph.getEdgeSource(edge); + RegistryVertex to = graph.getEdgeTarget(edge); + CompoundTag linkNBT = new CompoundTag(); + linkNBT.putUuidNew("from", from.id); + linkNBT.putUuidNew("to", to.id); + linksNBT.add(linkNBT); + } + tag.put("links", linksNBT); + // Subregistries are written automatically when the worlds are saved. tag.put("lastPrivatePocketEntrances", writePlayerRiftPointers(lastPrivatePocketEntrances)); tag.put("lastPrivatePocketExits", writePlayerRiftPointers(lastPrivatePocketExits)); @@ -195,8 +124,8 @@ public class RiftRegistry extends PersistentState { private Map readPlayerRiftPointers(ListTag tag) { Map pointerMap = new HashMap<>(); for (Tag entryNBT : tag) { - UUID player = ((CompoundTag) entryNBT).getUuid("player"); - UUID rift = ((CompoundTag) entryNBT).getUuid("rift"); + UUID player = ((CompoundTag) entryNBT).getUuidNew("player"); + UUID rift = ((CompoundTag) entryNBT).getUuidNew("rift"); PlayerRiftPointer pointer = new PlayerRiftPointer(player); pointerMap.put(player, pointer); uuidMap.put(pointer.id, pointer); @@ -210,10 +139,10 @@ public class RiftRegistry extends PersistentState { ListTag pointers = new ListTag(); for (Map.Entry entry : playerRiftPointerMap.entrySet()) { CompoundTag entryNBT = new CompoundTag(); - entryNBT.putUuid("player", entry.getKey()); + entryNBT.putUuidNew("player", entry.getKey()); int count = 0; for (DefaultEdge edge : graph.outgoingEdgesOf(entry.getValue())) { - entryNBT.putUuid("rift", graph.getEdgeTarget(edge).id); + entryNBT.putUuidNew("rift", graph.getEdgeTarget(edge).id); count++; } if (count != 1) throw new RuntimeException("PlayerRiftPointer points to more than one rift"); @@ -222,23 +151,6 @@ public class RiftRegistry extends PersistentState { return pointers; } - public void markSubregistryDirty(int dim) { - RiftSubregistry subregistry = subregistries.get(dim); - if (subregistry != null) { - subregistry.markDirty(); - } else { - // Create the subregistry - MapStorage storage = WorldUtils.getWorld(dim).getPerWorldStorage(); - RiftSubregistry instance = new RiftSubregistry(); - instance.dim = dim; - instance.markDirty(); - storage.setData(SUBREGISTRY_DATA_NAME, instance); - subregistries.put(dim, instance); - } - } - - // - public boolean isRiftAt(Location location) { Rift possibleRift = locationMap.get(location); return possibleRift != null && !(possibleRift instanceof RiftPlaceholder); @@ -255,12 +167,11 @@ public class RiftRegistry extends PersistentState { if (rift == null) { LOGGER.debug("Creating a rift placeholder at " + location); rift = new RiftPlaceholder(); - rift.dim = location.getDim(); + rift.world = location.world; rift.location = location; locationMap.put(location, rift); uuidMap.put(rift.id, rift); graph.addVertex(rift); - markSubregistryDirty(rift.dim); } return rift; } @@ -272,12 +183,12 @@ public class RiftRegistry extends PersistentState { if (currentRift instanceof RiftPlaceholder) { LOGGER.info("Converting a rift placeholder at " + location + " into a rift"); rift = new Rift(location); - rift.dim = location.getDim(); + rift.world = location.world; rift.id = currentRift.id; GraphUtils.replaceVertex(graph, currentRift, rift); } else if (currentRift == null) { rift = new Rift(location); - rift.dim = location.getDim(); + rift.world = location.world; graph.addVertex(rift); } else { throw new IllegalArgumentException("There is already a rift registered at " + location); @@ -298,7 +209,6 @@ public class RiftRegistry extends PersistentState { graph.removeVertex(rift); locationMap.remove(location); uuidMap.remove(rift.id); - markSubregistryDirty(rift.dim); // Notify the adjacent vertices of the change for (DefaultEdge edge : incomingEdges) graph.getEdgeSource(edge).targetGone(rift); @@ -311,24 +221,18 @@ public class RiftRegistry extends PersistentState { markDirty(); } else if (from instanceof Rift) { ((Rift) from).markDirty(); - } else { - markSubregistryDirty(from.dim); } if (to instanceof Rift) { ((Rift) to).markDirty(); - } else { - markSubregistryDirty(to.dim); } } private void removeEdge(RegistryVertex from, RegistryVertex to) { graph.removeEdge(from, to); + if (from instanceof PlayerRiftPointer) { markDirty(); - } else { - markSubregistryDirty(from.dim); } - markSubregistryDirty(to.dim); } public void addLink(Location locationFrom, Location locationTo) { @@ -388,7 +292,7 @@ public class RiftRegistry extends PersistentState { PocketEntrancePointer pointer = pocketEntranceMap.get(pocket); if (pointer == null) { pointer = new PocketEntrancePointer(pocket.world, pocket.id); - pointer.dim = pocket.world; + pointer.world = pocket.world; graph.addVertex(pointer); pocketEntranceMap.put(pocket, pointer); uuidMap.put(pointer.id, pointer); diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java index 0d448351..747ad153 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java @@ -2,6 +2,7 @@ package org.dimdev.dimdoors.rift.targets; import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.TranslatableText; import org.dimdev.dimdoors.block.entity.RiftBlockEntity; import org.dimdev.dimdoors.rift.registry.RiftRegistry; @@ -46,7 +47,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD if (uuid != null) { Location destLoc = RiftRegistry.instance().getOverworldRift(uuid); if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || canEscapeLimbo) { - TeleportUtil.teleport(entity, VirtualLocation.fromLocation(new Location(entity.world, entity.getBlockPos())).projectToWorld(false)); + TeleportUtil.teleport(entity, VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getSenseCenterPos())).projectToWorld(false)); return true; } else { if (destLoc == null) { diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/PrivatePocketExitTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/PrivatePocketExitTarget.java index daffbc2b..c4d3ad81 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/PrivatePocketExitTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/PrivatePocketExitTarget.java @@ -2,7 +2,7 @@ package org.dimdev.dimdoors.rift.targets; import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; -import org.dimdev.dimdoors.DimDoors; +import net.minecraft.text.TranslatableText; import org.dimdev.dimdoors.block.entity.RiftBlockEntity; import org.dimdev.dimdoors.rift.registry.RiftRegistry; import org.dimdev.dimdoors.world.limbo.LimboDimension; @@ -43,9 +43,9 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg } if (destLoc == null || !(destLoc.getBlockEntity() instanceof RiftBlockEntity)) { if (destLoc == null) { - DimDoors.sendTranslatedMessage(entity, "rifts.destinations.private_pocket_exit.did_not_use_rift"); + entity.sendMessage(new TranslatableText("rifts.destinations.private_pocket_exit.did_not_use_rift")); } else { - DimDoors.sendTranslatedMessage(entity, "rifts.destinations.private_pocket_exit.rift_has_closed"); + entity.sendMessage(new TranslatableText("rifts.destinations.private_pocket_exit.rift_has_closed")); } TeleportUtil.teleport(entity, LimboDimension.getLimboSkySpawn(entity)); return false; diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/RandomTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/RandomTarget.java index 5739ee5c..38078e23 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/RandomTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/RandomTarget.java @@ -2,6 +2,7 @@ package org.dimdev.dimdoors.rift.targets; import com.google.common.collect.Sets; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Heightmap; import net.minecraft.world.World; @@ -137,14 +138,14 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar depth /= depth > 0 ? positiveDepthFactor : negativeDepthFactor; double x = Math.cos(theta) * Math.cos(phi) * distance / coordFactor; double z = Math.cos(theta) * Math.sin(phi) * distance / coordFactor; - VirtualLocation virtualLocation = new VirtualLocation(virtualLocationHere.dimension, + VirtualLocation virtualLocation = new VirtualLocation(virtualLocationHere.world, virtualLocationHere.x + (int) Math.round(x), virtualLocationHere.z + (int) Math.round(z), virtualLocationHere.depth + (int) Math.round(depth)); if (virtualLocation.depth <= 0) { // This will lead to the overworld - World world = WorldUtils.getWorld(virtualLocation.dimension); + World world = virtualLocation.world; BlockPos pos = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, new BlockPos(virtualLocation.x, 0, virtualLocation.z)); if (pos.getY() == -1) { // No blocks at that XZ (hole in bedrock) @@ -157,8 +158,8 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar // TODO: Should the rift not be configured like the other link riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build()); - if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(new Location(world, pos), location); - if (!noLink) linkRifts(location, new Location(world, pos)); + if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(new Location((ServerWorld) world, pos), location); + if (!noLink) linkRifts(location, new Location((ServerWorld) world, pos)); return riftEntity.as(Targets.ENTITY); } else { // Make a new dungeon pocket diff --git a/src/main/java/org/dimdev/dimdoors/world/CustomSkyProvider.java b/src/main/java/org/dimdev/dimdoors/world/CustomSkyProvider.java deleted file mode 100644 index 10fe3a83..00000000 --- a/src/main/java/org/dimdev/dimdoors/world/CustomSkyProvider.java +++ /dev/null @@ -1,215 +0,0 @@ -//package org.dimdev.dimdoors.world; -// -//import net.minecraft.client.Minecraft; -//import net.minecraft.client.MinecraftClient; -//import net.minecraft.client.multiplayer.WorldClient; -//import net.minecraft.client.renderer.*; -//import net.minecraft.client.renderer.vertex.*; -//import net.minecraft.util.Identifier; -//import net.minecraft.util.math.MathHelper; -//import net.minecraft.util.math.Vec3d; -//import net.minecraftforge.client.IRenderHandler; -//import org.lwjgl.opengl.GL11; -// -//public class CustomSkyProvider extends IRenderHandler { -// -// private static final Identifier locationEndSkyPng = new Identifier("textures/environment/end_sky.png"); -// int starGLCallList; -// int glSkyList; -// int glSkyList2; -// -// public Identifier getMoonRenderPath() { -// return null; -// } -// -// public Identifier getSunRenderPath() { -// return null; -// } -// -// -// @Environment(EnvType.CLIENT) -// @Override -// public void render(float partialTicks, WorldClient world, Minecraft mc) { -// -// starGLCallList = GLAllocation.generateDisplayLists(3); -// glSkyList = starGLCallList + 1; -// glSkyList2 = starGLCallList + 2; -// RenderSystem.disableFog(); -// RenderSystem.disableAlpha(); -// RenderSystem.enableBlend(); -// RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); -// RenderHelper.disableStandardItemLighting(); -// RenderSystem.depthMask(false); -// -// MinecraftClient.getInstance().getTextureManager().bindTexture(locationEndSkyPng); -// -// if (mc.world.dimension.isSurfaceWorld()) { -// RenderSystem.disableTexture2D(); -// final Vec3d vec3 = world.getSkyColor(mc.getRenderViewEntity(), partialTicks); -// float f1 = (float) vec3.x; -// float f2 = (float) vec3.y; -// float f3 = (float) vec3.z; -// float f4; -// -// if (mc.gameSettings.anaglyph) { -// float f5 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F; -// float f6 = (f1 * 30.0F + f2 * 70.0F) / 100.0F; -// f4 = (f1 * 30.0F + f3 * 70.0F) / 100.0F; -// f1 = f5; -// f2 = f6; -// f3 = f4; -// } -// -// RenderSystem.color(f1, f2, f3); -// final Tessellator tessellator = Tessellator.getInstance(); -// final BufferBuilder buffer = tessellator.getBuffer(); -// RenderSystem.depthMask(false); -// RenderSystem.enableFog(); -// RenderSystem.color(f1, f2, f3); -// RenderSystem.callList(glSkyList); -// RenderSystem.disableFog(); -// RenderSystem.disableAlpha(); -// RenderSystem.enableBlend(); -// RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); -// RenderHelper.disableStandardItemLighting(); -// float[] afloat = world.dimension.calcSunriseSunsetColors(world.getCelestialAngle(partialTicks), partialTicks); -// float f7; -// float f8; -// float f9; -// float f10; -// -// if (afloat != null) { -// RenderSystem.disableTexture2D(); -// RenderSystem.shadeModel(GL11.GL_SMOOTH); -// RenderSystem.pushMatrix(); -// RenderSystem.rotate(90.0F, 1.0F, 0.0F, 0.0F); -// RenderSystem.rotate(MathHelper.sin(world.getCelestialAngleRadians(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F); -// RenderSystem.rotate(90.0F, 0.0F, 0.0F, 1.0F); -// f4 = afloat[0]; -// f7 = afloat[1]; -// f8 = afloat[2]; -// float f11; -// -// if (mc.gameSettings.anaglyph) { -// f9 = (f4 * 30.0F + f7 * 59.0F + f8 * 11.0F) / 100.0F; -// f10 = (f4 * 30.0F + f7 * 70.0F) / 100.0F; -// f11 = (f4 * 30.0F + f8 * 70.0F) / 100.0F; -// f4 = f9; -// f7 = f10; -// f8 = f11; -// } -// -// buffer.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR); -// buffer.color(f4, f7, f8, afloat[3]).pos(0.0, 100D, 0).endVertex(); -// byte b0 = 16; -// -// for (int j = 0; j <= b0; ++j) { -// f11 = j * (float) Math.PI * 2.0F / b0; -// float f12 = MathHelper.sin(f11); -// float f13 = MathHelper.cos(f11); -// buffer.color(afloat[0], afloat[1], afloat[2], 0.0F).pos(f12 * 120.0F, f13 * 120.0F, -f13 * 40.0F * afloat[3]).endVertex(); -// } -// -// tessellator.draw(); -// RenderSystem.popMatrix(); -// RenderSystem.shadeModel(GL11.GL_FLAT); -// } -// -// RenderSystem.enableTexture2D(); -// RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); -// RenderSystem.pushMatrix(); -// f4 = 1.0F - world.getRainStrength(partialTicks); -// f7 = 0.0F; -// f8 = 0.0F; -// f9 = 0.0F; -// RenderSystem.color(1.0F, 1.0F, 1.0F, f4); -// RenderSystem.translate(f7, f8, f9); -// RenderSystem.rotate(-90.0F, 0.0F, 1.0F, 0.0F); -// RenderSystem.rotate(world.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F); -// f10 = 30.0F; -// MinecraftClient.getInstance().getTextureManager().bindTexture(getSunRenderPath()); -// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); -// buffer.pos(-f10, 100, -f10).tex(0, 0).endVertex(); -// buffer.pos(f10, 100, -f10).tex(1, 0).endVertex(); -// buffer.pos(f10, 100, f10).tex(1, 1).endVertex(); -// buffer.pos(-f10, 100, f10).tex(0, 1).endVertex(); -// tessellator.draw(); -// -// f10 = 20.0F; -// MinecraftClient.getInstance().getTextureManager().bindTexture(getMoonRenderPath()); -// int k = world.getMoonPhase(); -// int i = k % 4; -// int i1 = k / 4 % 2; -// float f16 = i + 1; -// float f17 = i1 + 1; -// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); -// buffer.pos(-f10, -100, f10).tex(f16, f17).endVertex(); -// buffer.pos(f10, -100, f10).tex((float) i, f17).endVertex(); -// buffer.pos(f10, -100, -f10).tex((float) i, (float) i1).endVertex(); -// buffer.pos(-f10, -100, -f10).tex(f16, (float) i1).endVertex(); -// tessellator.draw(); -// RenderSystem.disableTexture2D(); -// float f18 = world.getStarBrightness(partialTicks) * f4; -// -// if (f18 > 0.0F) { -// RenderSystem.color(f18, f18, f18, f18); -// RenderSystem.callList(starGLCallList); -// } -// -// RenderSystem.color(1.0F, 1.0F, 1.0F, 1.0F); -// RenderSystem.disableBlend(); -// RenderSystem.enableAlpha(); -// RenderSystem.enableFog(); -// RenderSystem.popMatrix(); -// RenderSystem.disableTexture2D(); -// RenderSystem.color(0.0F, 0.0F, 0.0F); -// double d0 = mc.player.getLook(partialTicks).y - world.getHorizon(); -// -// if (d0 < 0.0D) { -// RenderSystem.pushMatrix(); -// RenderSystem.translate(0.0F, 12.0F, 0.0F); -// RenderSystem.callList(glSkyList2); -// RenderSystem.popMatrix(); -// f8 = 1.0F; -// f9 = -((float) (d0 + 65.0D)); -// f10 = -f8; -// -// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); -// buffer.pos(-f8, f9, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f9, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f9, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f9, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f9, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f9, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f9, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f9, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(-f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, f8).color(0, 0, 0, 1).endVertex(); -// buffer.pos(f8, f10, -f8).color(0, 0, 0, 1).endVertex(); -// tessellator.draw(); -// } -// -// if (world.dimension.isSkyColored()) { -// RenderSystem.color(f1 * 0.2F + 0.04F, f2 * 0.2F + 0.04F, f3 * 0.6F + 0.1F); -// } else { -// RenderSystem.color(f1, f2, f3); -// } -// -// RenderSystem.pushMatrix(); -// RenderSystem.translate(0.0F, -((float) (d0 - 16.0D)), 0.0F); -// RenderSystem.callList(glSkyList2); -// RenderSystem.popMatrix(); -// RenderSystem.enableTexture2D(); -// RenderSystem.depthMask(true); -// } -// } -//} diff --git a/src/main/java/org/dimdev/dimdoors/world/ModBiomes.java b/src/main/java/org/dimdev/dimdoors/world/ModBiomes.java index 3d49f2fb..6f010baf 100644 --- a/src/main/java/org/dimdev/dimdoors/world/ModBiomes.java +++ b/src/main/java/org/dimdev/dimdoors/world/ModBiomes.java @@ -1,16 +1,15 @@ package org.dimdev.dimdoors.world; -import org.dimdev.dimdoors.world.limbo.BiomeLimbo; -import org.dimdev.dimdoors.world.pocketdimension.BlankBiome; import net.minecraft.util.Identifier; import net.minecraft.world.biome.Biome; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.dimdev.dimdoors.world.limbo.LimboBiome; +import org.dimdev.dimdoors.world.pocketdimension.BlankBiome; public final class ModBiomes { - - public static final BiomeLimbo LIMBO = new BiomeLimbo(); + public static final LimboBiome LIMBO = new LimboBiome(); public static final BlankBiome WHITE_VOID = new BlankBiome(true, false); public static final BlankBiome BLACK_VOID = new BlankBiome(false, false); public static final BlankBiome DANGEROUS_BLACK_VOID = new BlankBiome(false, true); diff --git a/src/main/java/org/dimdev/dimdoors/world/ModDimensions.java b/src/main/java/org/dimdev/dimdoors/world/ModDimensions.java index f927f1d5..22d17adc 100644 --- a/src/main/java/org/dimdev/dimdoors/world/ModDimensions.java +++ b/src/main/java/org/dimdev/dimdoors/world/ModDimensions.java @@ -20,4 +20,8 @@ public final class ModDimensions { || world.dimension instanceof PersonalPocketDimension || world.dimension instanceof DungeonPocketDimension; } + + public static void init() { + // just loads the class + } } diff --git a/src/main/java/org/dimdev/dimdoors/world/fortresses/ComponentNetherGateway.java b/src/main/java/org/dimdev/dimdoors/world/fortresses/ComponentNetherGateway.java deleted file mode 100644 index fa43adba..00000000 --- a/src/main/java/org/dimdev/dimdoors/world/fortresses/ComponentNetherGateway.java +++ /dev/null @@ -1,165 +0,0 @@ -//package org.dimdev.dimdoors.world.fortresses; -// -//import net.minecraft.nbt.CompoundTag; -//import net.minecraft.util.Direction; -//import net.minecraft.world.World; -//import net.minecraft.world.gen.structure.StructureBoundingBox; -//import net.minecraft.world.gen.structure.StructureComponent; -//import net.minecraft.world.gen.structure.template.TemplateManager; -// -//import java.util.List; -//import java.util.Random; -// -//public class ComponentNetherGateway extends StructureComponent { -// // Note: In this case, it doesn't really matter which class we extend, since this class will -// // never be passed to Minecraft. We just need an instance to have access to structure-building methods. -// // If Forge supports adding custom fortress structures in the future, then we might have to change -// // our class to extend ComponentNetherBridgeCrossing or something along those lines. ~SenseiKiwi -// -// public ComponentNetherGateway(int componentType, Random random, StructureBoundingBox bounds, Direction coordBaseMode) { -// super(componentType); -// -// this.boundingBox = bounds; -// this.setCoordBaseMode(coordBaseMode); -// } -// -// /** -// * Creates and returns a new component piece. Or null if it could not find enough room to place it. -// */ -// public static ComponentNetherGateway createValidComponent(List components, Random random, int minX, int minY, int minZ, Direction coordBaseMode, int componentType) { -// StructureBoundingBox bounds = StructureBoundingBox.getComponentToAddBoundingBox(minX, minY, minZ, -2, 0, 0, 7, 9, 7, coordBaseMode); -// return isAboveGround(bounds) && StructureComponent.findIntersecting(components, bounds) == null ? new ComponentNetherGateway(componentType, random, bounds, coordBaseMode) : null; -// } -// -// public static ComponentNetherGateway createFromComponent(StructureComponent component, Random random) { -// // Create an instance of our gateway component using the same data as another component, -// // likely a component that we intend to replace during generation -// return new ComponentNetherGateway(component.getComponentType(), random, -// component.getBoundingBox(), component.getCoordBaseMode()); -// } -// -// /** -// * Checks if the bounding box's minY is > 10 -// */ -// protected static boolean isAboveGround(StructureBoundingBox par0StructureBoundingBox) { -// return par0StructureBoundingBox != null && par0StructureBoundingBox.minY > 10; -// } -// -// /** -// * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at -// * the end, it adds Fences... -// */ -// @Override -// public boolean addComponentParts(World world, Random random, StructureBoundingBox bounds) { -// /*int NETHER_SLAB_METADATA = 6; -// -// // Set all the blocks in the area of the room to air -// this.fillWithBlocks(world, bounds, 0, 2, 0, 6, 6, 6, Blocks.air, Blocks.air, false); -// // Set up the platform under the gateway -// this.fillWithBlocks(world, bounds, 0, 0, 0, 6, 1, 6, Blocks.nether_brick, Blocks.nether_brick, false); -// -// // Build the fence at the back of the room -// this.fillWithBlocks(world, bounds, 1, 2, 6, 5, 2, 6, Blocks.nether_brick, Blocks.nether_brick, false); -// this.fillWithBlocks(world, bounds, 1, 3, 6, 5, 3, 6, Blocks.nether_brick_fence, Blocks.nether_brick_fence, false); -// -// // Build the fences at the sides of the room -// this.fillWithBlocks(world, bounds, 0, 2, 0, 0, 2, 6, Blocks.nether_brick, Blocks.nether_brick, false); -// this.fillWithBlocks(world, bounds, 0, 3, 0, 0, 3, 6, Blocks.nether_brick_fence, Blocks.nether_brick_fence, false); -// -// this.fillWithBlocks(world, bounds, 6, 2, 0, 6, 2, 6, Blocks.nether_brick, Blocks.nether_brick, false); -// this.fillWithBlocks(world, bounds, 6, 3, 0, 6, 3, 6, Blocks.nether_brick_fence, Blocks.nether_brick_fence, false); -// -// // Build the fence portions closest to the entrance -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick, 0, 1, 2, 0, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 1, 3, 0, bounds); -// -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick, 0, 5, 2, 0, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 5, 3, 0, bounds); -// -// // Build the first layer of the gateway -// this.fillWithBlocks(world, bounds, 1, 2, 2, 5, 2, 5, Blocks.nether_brick, Blocks.nether_brick, false); -// this.fillWithMetadataBlocks(world, bounds, 1, 2, 1, 5, 2, 1, Blocks.stone_slab, NETHER_SLAB_METADATA, Blocks.stone_slab, NETHER_SLAB_METADATA, false); -// -// this.placeBlockAtCurrentPosition(world, Blocks.stone_slab, NETHER_SLAB_METADATA, 1, 2, 2, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.stone_slab, NETHER_SLAB_METADATA, 5, 2, 2, bounds); -// -// // Build the second layer of the gateway -// int orientation = this.getMetadataWithOffset(Blocks.nether_brick_stairs, 2); -// this.fillWithBlocks(world, bounds, 2, 3, 3, 2, 3, 4, Blocks.nether_brick, Blocks.nether_brick, false); -// this.fillWithBlocks(world, bounds, 4, 3, 3, 4, 3, 4, Blocks.nether_brick, Blocks.nether_brick, false); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick, 0, 3, 3, 4, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, orientation, 3, 3, 5, bounds); -// -// // Build the third layer of the gateway -// // We add 4 to get the rotated metadata for upside-down stairs -// // because Minecraft only supports metadata rotations for normal stairs -_- -// this.fillWithMetadataBlocks(world, bounds, 2, 4, 4, 4, 4, 4, Blocks.nether_brick_stairs, orientation, Blocks.nether_brick_stairs, orientation, false); -// -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 0) + 4, 2, 4, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 1) + 4, 4, 4, 3, bounds); -// -// // Build the fourth layer of the gateway -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick, 0, 3, 5, 3, bounds); -// -// this.placeBlockAtCurrentPosition(world, Blocks.netherrack, 0, 2, 5, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 0) + 4, 1, 5, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 3) + 4, 2, 5, 2, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 2) + 4, 2, 5, 4, bounds); -// -// this.placeBlockAtCurrentPosition(world, Blocks.netherrack, 0, 4, 5, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 1) + 4, 5, 5, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 3) + 4, 4, 5, 2, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_stairs, this.getMetadataWithOffset(Blocks.nether_brick_stairs, 2) + 4, 4, 5, 4, bounds); -// -// // Build the top layer of the gateway -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 3, 6, 3, bounds); -// -// this.placeBlockAtCurrentPosition(world, Blocks.fire, 0, 2, 6, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 1, 6, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 2, 6, 2, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 2, 6, 4, bounds); -// -// this.placeBlockAtCurrentPosition(world, Blocks.fire, 0, 4, 6, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 5, 6, 3, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 4, 6, 2, bounds); -// this.placeBlockAtCurrentPosition(world, Blocks.nether_brick_fence, 0, 4, 6, 4, bounds); -// -// // Place the transient door -// int y = this.getYWithOffset(3); -// int x = this.getXWithOffset(3, 3); -// int z = this.getZWithOffset(3, 3); -// DimLink link; -// NewDimData dimension; -// -// // This function might run multiple times for a single component -// // due to the way Minecraft handles structure generation! -// if (bounds.isVecInside(x, y, z) && bounds.isVecInside(x, y + 1, z)) -// { -// orientation = this.getMetadataWithOffset(Blocks.wooden_door, 1); -// dimension = PocketManager.createDimensionData(world); -// link = dimension.getLink(x, y + 1, z); -// if (link == null) -// { -// link = dimension.createLink(x, y + 1, z, LinkType.DUNGEON, orientation); -// } -// ItemDoor.placeDoorBlock(world, x, y, z, orientation, mod_pocketDim.transientDoor); -// } -// -// for (x = 0; x <= 6; ++x) -// { -// for (z = 0; z <= 6; ++z) -// { -// this.func_151554_b(world, Blocks.nether_brick, 0, x, -1, z, bounds); -// } -// } -// */ -// return true; -// } -// -// @Override -// protected void writeStructureToNBT(CompoundTag tag) { -// } -// -// @Override -// protected void readStructureFromNBT(CompoundTag tag, TemplateManager manager) { } -//} \ No newline at end of file diff --git a/src/main/java/org/dimdev/dimdoors/world/fortresses/DDNetherFortressGenerator.java b/src/main/java/org/dimdev/dimdoors/world/fortresses/DDNetherFortressGenerator.java deleted file mode 100644 index ea3219f4..00000000 --- a/src/main/java/org/dimdev/dimdoors/world/fortresses/DDNetherFortressGenerator.java +++ /dev/null @@ -1,25 +0,0 @@ -//package org.dimdev.dimdoors.world.fortresses; -// -//import net.minecraft.world.gen.structure.MapGenNetherBridge; -//import net.minecraft.world.gen.structure.MapGenStructureIO; -//import net.minecraft.world.gen.structure.StructureStart; -// -//public class DDNetherFortressGenerator extends MapGenNetherBridge -//{ -// public DDNetherFortressGenerator() -// { -// super(); -// -// // Register our custom StructureStart class with MapGenStructureIO -// // If we don't do this, Minecraft will crash when a fortress tries to generate. -// // Moreover, use Fortress as our structure identifier so that if DD is removed, -// // fortresses will generate properly using Vanilla code. -// //MapGenStructureIO.registerStructureComponent(DDStructureNetherBridgeStart.class, "Fortress"); -// } -// -// @Override -// protected StructureStart getStructureStart(int chunkX, int chunkZ) -// { -// return new DDStructureNetherBridgeStart(this.world, this.rand, chunkX, chunkZ); -// } -//} \ No newline at end of file diff --git a/src/main/java/org/dimdev/dimdoors/world/fortresses/DDStructureNetherBridgeStart.java b/src/main/java/org/dimdev/dimdoors/world/fortresses/DDStructureNetherBridgeStart.java deleted file mode 100644 index a46f037e..00000000 --- a/src/main/java/org/dimdev/dimdoors/world/fortresses/DDStructureNetherBridgeStart.java +++ /dev/null @@ -1,143 +0,0 @@ -//package org.dimdev.dimdoors.world.fortresses; -// -//import net.minecraft.nbt.CompoundTag; -//import net.minecraft.world.World; -//import net.minecraft.world.gen.structure.StructureBoundingBox; -//import net.minecraft.world.gen.structure.StructureComponent; -//import net.minecraft.world.gen.structure.StructureNetherBridgePieces; -//import net.minecraft.world.gen.structure.StructureStart; -// -//import java.util.ArrayList; -//import java.util.Iterator; -//import java.util.Random; -// -//public class DDStructureNetherBridgeStart extends StructureStart -//{ -// public static final int MAX_GATEWAY_GENERATION_CHANCE = 100; -// -// private boolean hasGateway; -// private int minX; -// private int minY; -// private int minZ; -// -// public DDStructureNetherBridgeStart() { } -// -// public DDStructureNetherBridgeStart(World world, Random random, int chunkX, int chunkZ) -// { -// // StructureNetherBridgeStart handles designing the fortress for us -// super(chunkX, chunkZ); -// -// Iterator componentIterator; -// StructureComponent component; -// StructureBoundingBox bounds; -// ArrayList spawnerRooms; -// hasGateway = false; -// -// // Randomly decide whether to build a gateway in this fortress -// //if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.FortressGatewayGenerationChance) -// //{ -// // Search for all the blaze spawners in a fortress -// spawnerRooms = new ArrayList(); -// componentIterator = this.components.iterator(); -// while (componentIterator.hasNext()) -// { -// component = (StructureComponent) componentIterator.next(); -// if (component instanceof StructureNetherBridgePieces.Throne) -// { -// spawnerRooms.add((StructureNetherBridgePieces.Throne) component); -// } -// } -// -// // If any spawner rooms were found, choose one to randomly replace -// if (!spawnerRooms.isEmpty()) -// { -// hasGateway = true; -// component = spawnerRooms.get(random.nextInt(spawnerRooms.size())); -// // Store enough data to identify the room when it's going to be built later -// bounds = component.getBoundingBox(); -// minX = bounds.minX; -// minY = bounds.minY; -// minZ = bounds.minZ; -// } -// //} -// } -// -// @Override -// public CompoundTag writeStructureComponentsToNBT(int chunkX, int chunkZ) { -// -// -// // We override the function for writing NBT data to add our own gateway data -// CompoundTag fortressTag = super.writeStructureComponentsToNBT(chunkX, chunkZ); -// -// // Add a compound tag with our data -// CompoundTag dimensionalTag = new CompoundTag(); -// dimensionalTag.setBoolean("HasGateway", this.hasGateway); -// if (hasGateway) { -// dimensionalTag.setInteger("GatewayMinX", this.minX); -// dimensionalTag.setInteger("GatewayMinY", this.minY); -// dimensionalTag.setInteger("GatewayMinZ", this.minZ); -// } -// fortressTag.put("DimensionalDoors", dimensionalTag); -// -// return fortressTag; -// } -// -// @Override -// public void readStructureComponentsFromNBT(World world, CompoundTag fortressTag) { -// // We override the function for reading NBT data to load gateway data -// super.readStructureComponentsFromNBT(world, fortressTag); -// -// CompoundTag dimensionalTag = fortressTag.getCompoundTag("DimensionalDoors"); -// if (dimensionalTag != null) -// { -// this.hasGateway = dimensionalTag.getBoolean("HasGateway"); -// if (hasGateway) -// { -// minX = dimensionalTag.getInteger("GatewayMinX"); -// minY = dimensionalTag.getInteger("GatewayMinY"); -// minZ = dimensionalTag.getInteger("GatewayMinZ"); -// } -// } -// } -// -// /** -// * Keeps iterating Structure Pieces and spawning them until the checks tell it to stop -// */ -// @Override -// public void generateStructure(World world, Random random, StructureBoundingBox generationBounds) -// { -// if (hasGateway) -// { -// // Use a modified version of Vanilla's fortress generation code -// // Try to detect the room that we intend to replace with our gateway -// Iterator iterator = this.components.iterator(); -// -// while (iterator.hasNext()) -// { -// StructureComponent component = (StructureComponent)iterator.next(); -// StructureBoundingBox bounds = component.getBoundingBox(); -// -// if (bounds.intersectsWith(generationBounds)) -// { -// // Check if this is our replacement target -// // Checking the location is enough because structures aren't allowed to have -// // intersecting bounding boxes - nothing else can have these min coordinates. -// if (bounds.minX == this.minX && bounds.minY == this.minY && bounds.minZ == this.minZ) -// { -// component = ComponentNetherGateway.createFromComponent(component, random); -// } -// // Now for the last bit of Vanilla's generation code -// if (!component.addComponentParts(world, random, generationBounds)) -// { -// iterator.remove(); -// } -// } -// } -// } -// else -// { -// // Just run the usual structure generation -// super.generateStructure(world, random, generationBounds); -// } -// } -//} \ No newline at end of file diff --git a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayGenerator.java b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayGenerator.java index 39a2f031..8809c93d 100644 --- a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayGenerator.java +++ b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayGenerator.java @@ -1,144 +1,142 @@ -package org.dimdev.dimdoors.world.gateways; - -import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldProviderEnd; -import net.minecraft.world.WorldProviderHell; -import net.minecraft.world.chunk.ChunkProvider; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.dimension.TheNetherDimension; -import net.minecraft.world.gen.IChunkGenerator; -import net.minecraft.world.gen.chunk.ChunkGenerator; -import net.minecraftforge.fml.common.IWorldGenerator; -import org.dimdev.dimdoors.ModConfig; -import org.dimdev.dimdoors.block.ModBlocks; -import org.dimdev.pocketlib.PocketWorldDimension; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Random; - -public class GatewayGenerator implements IWorldGenerator { - private static final int CLUSTER_GROWTH_CHANCE = 80; - private static final int MAX_CLUSTER_GROWTH_CHANCE = 100; - private static final int MIN_RIFT_Y = 4; - private static final int MAX_RIFT_Y = 240; - private static final int CHUNK_LENGTH = 16; - private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10; - - private ArrayList gateways; - private BaseGateway defaultGateway; - - public GatewayGenerator() { - gateways = new ArrayList<>(); - defaultGateway = new GatewayTwoPillars(); - - // Add gateways here - gateways.add(new GatewaySandstonePillars()); - gateways.add(new LimboGateway()); - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, ChunkGenerator chunkGenerator, ChunkProvider chunkProvider) { - // Don't generate rifts or gateways if the current world is a pocket dimension or the world is remote. - // Also don't generate anything in the Nether or The End. - if (world.isClient || world.dimension instanceof PocketWorldDimension || world.dimension instanceof TheNetherDimension || world.dimension instanceof WorldProviderEnd) { - return; - } - - int x, y, z; - int attempts; - boolean valid; - - // Check if we're allowed to generate rift clusters in this dimension. - // If so, randomly decide whether to one. - boolean clusterGenerated = false; - if (Arrays.binarySearch(ModConfig.WORLD.clusterDimBlacklist, world.dimension.getDimensionType().getId()) == -1) { - double clusterGenChance = ModConfig.WORLD.clusterGenChance; - while (clusterGenChance > 0.0) { - if (random.nextDouble() < clusterGenChance) { - do { - //Pick a random point on the surface of the chunk - x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); - z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); - y = world.getHeight(x, z); - - //If the point is within the acceptable altitude range, the block above is empty, and we're - //not building on bedrock, then generate a rift there - if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(new BlockPos(x, y + 1, z)) - && world.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.BEDROCK - && //<-- Stops Nether roof spawning. DO NOT REMOVE! - world.getBlockState(new BlockPos(x, y - 1, z)).getBlock() != Blocks.BEDROCK - && world.getBlockState(new BlockPos(x, y - 2, z)).getBlock() != Blocks.BEDROCK) { - //Create a link. If this is not the first time, create a child link and connect it to the first link. - world.setBlockState(new BlockPos(x, y, z), ModBlocks.DETACHED_RIFT.getDefaultState()); - } - } //Randomly decide whether to repeat the process and add another rift to the cluster - while (random.nextInt(MAX_CLUSTER_GROWTH_CHANCE) < CLUSTER_GROWTH_CHANCE); - clusterGenerated = true; - } - clusterGenChance -= 1.0; - } - } - - // Check if we can place a Rift Gateway in this dimension, then randomly decide whether to place one. - // This only happens if a rift cluster was NOT generated. - if (!clusterGenerated && Arrays.binarySearch(ModConfig.WORLD.gatewayDimBlacklist, world.dimension.getDimensionType().getId()) == -1) { - double gatewayGenChance = ModConfig.WORLD.gatewayGenChance; - while (gatewayGenChance > 0.0) { - if (random.nextDouble() < gatewayGenChance) { - valid = false; - x = y = z = 0; //Stop the compiler from freaking out - - //Check locations for the gateway until we are satisfied or run out of attempts. - for (attempts = 0; attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && !valid; attempts++) { - //Pick a random point on the surface of the chunk and check its materials - x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); - z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); - y = world.getHeight(x, z); - valid = checkGatewayLocation(world, new BlockPos(x, y, z)); - } - - // Build the gateway if we found a valid location - if (valid) { - ArrayList validGateways = new ArrayList<>(); - for (BaseGateway gateway : gateways) { - if (gateway.isLocationValid(world, x, y, z)) { - validGateways.add(gateway); - } - } - // Add the default gateway if the rest were rejected - if (validGateways.isEmpty()) { - validGateways.add(defaultGateway); - } - // Randomly select a gateway from the pool of viable gateways - validGateways.get(random.nextInt(validGateways.size())).generate(world, x, y - 1, z); - } - } - gatewayGenChance -= 1.0; - } - } - } - - private static boolean checkGatewayLocation(World world, BlockPos pos) { - //Check if the point is within the acceptable altitude range, the block above that point is empty, - //and the block two levels down is opaque and has a reasonable material. Plus that we're not building - //on top of bedrock. - return pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y - && world.isAirBlock(pos.up()) - && world.getBlockState(pos).getBlock() != Blocks.BEDROCK - && world.getBlockState(pos.down()) != Blocks.BEDROCK //<-- Stops Nether roof spawning. DO NOT REMOVE! - && checkFoundationMaterial(world, pos.down()); - } - - private static boolean checkFoundationMaterial(World world, BlockPos pos) { - //We check the material and opacity to prevent generating gateways on top of trees or houses, - //or on top of strange things like tall grass, water, slabs, or torches. - //We also want to avoid generating things on top of the Nether's bedrock! - Material material = world.getBlockState(pos).getMaterial(); - return material != Material.LEAVES && material != Material.WOOD && material != Material.GOURD - && world.isBlockNormalCube(pos, false) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK; - } -} +//package org.dimdev.dimdoors.world.gateways; +// +//import net.minecraft.block.Blocks; +//import net.minecraft.block.Material; +//import net.minecraft.util.math.BlockPos; +//import net.minecraft.world.Heightmap; +//import net.minecraft.world.World; +//import net.minecraft.world.WorldProviderEnd; +//import net.minecraft.world.chunk.ChunkProvider; +//import net.minecraft.world.dimension.TheNetherDimension; +//import net.minecraft.world.gen.chunk.ChunkGenerator; +//import net.minecraftforge.fml.common.IWorldGenerator; +//import org.dimdev.dimdoors.ModConfig; +//import org.dimdev.dimdoors.block.ModBlocks; +//import org.dimdev.pocketlib.PocketWorldDimension; +// +//import java.util.ArrayList; +//import java.util.Arrays; +//import java.util.Random; +// +//public class GatewayGenerator implements IWorldGenerator { +// private static final int CLUSTER_GROWTH_CHANCE = 80; +// private static final int MAX_CLUSTER_GROWTH_CHANCE = 100; +// private static final int MIN_RIFT_Y = 4; +// private static final int MAX_RIFT_Y = 240; +// private static final int CHUNK_LENGTH = 16; +// private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10; +// +// private ArrayList gateways; +// private BaseGateway defaultGateway; +// +// public GatewayGenerator() { +// gateways = new ArrayList<>(); +// defaultGateway = new GatewayTwoPillars(); +// +// // Add gateways here +// gateways.add(new GatewaySandstonePillars()); +// gateways.add(new LimboGateway()); +// } +// +// @Override +// public void generate(Random random, int chunkX, int chunkZ, World world, ChunkGenerator chunkGenerator, ChunkProvider chunkProvider) { +// // Don't generate rifts or gateways if the current world is a pocket dimension or the world is remote. +// // Also don't generate anything in the Nether or The End. +// if (world.isClient || world.dimension instanceof PocketWorldDimension || world.dimension instanceof TheNetherDimension || world.dimension instanceof WorldProviderEnd) { +// return; +// } +// +// int x, y, z; +// int attempts; +// boolean valid; +// +// // Check if we're allowed to generate rift clusters in this dimension. +// // If so, randomly decide whether to one. +// boolean clusterGenerated = false; +// if (!ModConfig.WORLD.clusterDimBlacklist.contains(world.dimension.getType().getSuffix())) { +// double clusterGenChance = ModConfig.WORLD.clusterGenChance; +// while (clusterGenChance > 0.0) { +// if (random.nextDouble() < clusterGenChance) { +// do { +// //Pick a random point on the surface of the chunk +// x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); +// z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); +// y = world.getHeight(x, z); +// +// //If the point is within the acceptable altitude range, the block above is empty, and we're +// //not building on bedrock, then generate a rift there +// if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(new BlockPos(x, y + 1, z)) +// && world.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.BEDROCK +// && //<-- Stops Nether roof spawning. DO NOT REMOVE! +// world.getBlockState(new BlockPos(x, y - 1, z)).getBlock() != Blocks.BEDROCK +// && world.getBlockState(new BlockPos(x, y - 2, z)).getBlock() != Blocks.BEDROCK) { +// //Create a link. If this is not the first time, create a child link and connect it to the first link. +// world.setBlockState(new BlockPos(x, y, z), ModBlocks.DETACHED_RIFT.getDefaultState()); +// } +// } //Randomly decide whether to repeat the process and add another rift to the cluster +// while (random.nextInt(MAX_CLUSTER_GROWTH_CHANCE) < CLUSTER_GROWTH_CHANCE); +// clusterGenerated = true; +// } +// clusterGenChance -= 1.0; +// } +// } +// +// // Check if we can place a Rift Gateway in this dimension, then randomly decide whether to place one. +// // This only happens if a rift cluster was NOT generated. +// if (!clusterGenerated && Arrays.binarySearch(ModConfig.WORLD.gatewayDimBlacklist, world.dimension.getDimensionType().getId()) == -1) { +// double gatewayGenChance = ModConfig.WORLD.gatewayGenChance; +// while (gatewayGenChance > 0.0) { +// if (random.nextDouble() < gatewayGenChance) { +// valid = false; +// x = y = z = 0; //Stop the compiler from freaking out +// +// //Check locations for the gateway until we are satisfied or run out of attempts. +// for (attempts = 0; attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && !valid; attempts++) { +// //Pick a random point on the surface of the chunk and check its materials +// x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); +// z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); +// y = world.getTopY(Heightmap.Type.WORLD_SURFACE, x, z); +// valid = checkGatewayLocation(world, new BlockPos(x, y, z)); +// } +// +// // Build the gateway if we found a valid location +// if (valid) { +// ArrayList validGateways = new ArrayList<>(); +// for (BaseGateway gateway : gateways) { +// if (gateway.isLocationValid(world, x, y, z)) { +// validGateways.add(gateway); +// } +// } +// // Add the default gateway if the rest were rejected +// if (validGateways.isEmpty()) { +// validGateways.add(defaultGateway); +// } +// // Randomly select a gateway from the pool of viable gateways +// validGateways.get(random.nextInt(validGateways.size())).generate(world, x, y - 1, z); +// } +// } +// gatewayGenChance -= 1.0; +// } +// } +// } +// +// private static boolean checkGatewayLocation(World world, BlockPos pos) { +// //Check if the point is within the acceptable altitude range, the block above that point is empty, +// //and the block two levels down is opaque and has a reasonable material. Plus that we're not building +// //on top of bedrock. +// return pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y +// && world.isAir(pos.up()) +// && world.getBlockState(pos).getBlock() != Blocks.BEDROCK +// && world.getBlockState(pos.down()).getBlock() != Blocks.BEDROCK //<-- Stops Nether roof spawning. DO NOT REMOVE! +// && checkFoundationMaterial(world, pos.down()); +// } +// +// private static boolean checkFoundationMaterial(World world, BlockPos pos) { +// //We check the material and opacity to prevent generating gateways on top of trees or houses, +// //or on top of strange things like tall grass, water, slabs, or torches. +// //We also want to avoid generating things on top of the Nether's bedrock! +// Material material = world.getBlockState(pos).getMaterial(); +// return material != Material.LEAVES && material != Material.WOOD && material != Material.PUMPKIN +// && world.getBlockState(pos).isFullCube(world, pos) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK; +// } +//} diff --git a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewaySandstonePillars.java b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewaySandstonePillars.java index 7380029e..76065a5d 100644 --- a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewaySandstonePillars.java +++ b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewaySandstonePillars.java @@ -1,7 +1,7 @@ package org.dimdev.dimdoors.world.gateways; -import net.minecraft.init.Biomes; import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; public class GatewaySandstonePillars extends BaseSchematicGateway { public GatewaySandstonePillars() { @@ -10,6 +10,6 @@ public class GatewaySandstonePillars extends BaseSchematicGateway { @Override public Biome[] getBiomes() { - return new Biome[] {Biomes.DESERT, Biomes.DESERT_HILLS, Biomes.MUTATED_DESERT}; + return new Biome[]{Biomes.DESERT, Biomes.DESERT_HILLS, Biomes.DESERT_LAKES}; } } diff --git a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayTwoPillars.java b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayTwoPillars.java index 83eb66c9..5446bd30 100644 --- a/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayTwoPillars.java +++ b/src/main/java/org/dimdev/dimdoors/world/gateways/GatewayTwoPillars.java @@ -1,7 +1,6 @@ package org.dimdev.dimdoors.world.gateways; -import net.minecraft.block.BlockStoneBrick; -import net.minecraft.init.Blocks; +import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -23,12 +22,12 @@ public class GatewayTwoPillars extends BaseSchematicGateway { if (world.getBlockState(new BlockPos(x + xc, y - 1, z + zc)).getMaterial().isSolid()) { //Randomly choose whether to place bricks or not. The math is designed so that the //chances of placing a block decrease as we get farther from the gateway's center. - if (Math.abs(xc) + Math.abs(zc) < world.rand.nextInt(2) + 3) { + if (Math.abs(xc) + Math.abs(zc) < world.random.nextInt(2) + 3) { //Place Stone Bricks - world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONEBRICK.getDefaultState()); - } else if (Math.abs(xc) + Math.abs(zc) < world.rand.nextInt(3) + 3) { + world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONE_BRICKS.getDefaultState()); + } else if (Math.abs(xc) + Math.abs(zc) < world.random.nextInt(3) + 3) { //Place Cracked Stone Bricks - world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.CRACKED)); + world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.CRACKED_STONE_BRICKS.getDefaultState()); } } } diff --git a/src/main/java/org/dimdev/dimdoors/world/limbo/BiomeLimbo.java b/src/main/java/org/dimdev/dimdoors/world/limbo/LimboBiome.java similarity index 84% rename from src/main/java/org/dimdev/dimdoors/world/limbo/BiomeLimbo.java rename to src/main/java/org/dimdev/dimdoors/world/limbo/LimboBiome.java index e25f480d..8b856a21 100644 --- a/src/main/java/org/dimdev/dimdoors/world/limbo/BiomeLimbo.java +++ b/src/main/java/org/dimdev/dimdoors/world/limbo/LimboBiome.java @@ -1,15 +1,17 @@ package org.dimdev.dimdoors.world.limbo; -import org.dimdev.dimdoors.entity.MonolithEntity; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.ChunkPrimer; +import org.dimdev.dimdoors.entity.MonolithEntity; + import java.util.Random; -public class BiomeLimbo extends Biome { - - public BiomeLimbo() { +public class LimboBiome extends Biome { + public LimboBiome() { super(new Biome.BiomeProperties("Limbo") .setRainDisabled() .setRainfall(0) @@ -38,9 +40,11 @@ public class BiomeLimbo extends Biome { // Some mods like RFTools rely on the decorator being present, so we need to create one even if we don't use it. //@Override public BiomeDecorator createBiomeDecorator() { return null; } - @Override public void decorate(World world, Random rand, BlockPos pos) {} + @Override + public void decorate(World world, Random rand, BlockPos pos) {} - @Override public void genTerrainBlocks(World world, Random rand, ChunkPrimer chunkPrimer, int x, int z, double noiseVal) {} + @Override + public void genTerrainBlocks(World world, Random rand, ChunkPrimer chunkPrimer, int x, int z, double noiseVal) {} // TODO: check that black/white grass and foliage in getModdedBiomeGrassColor is compatible with other mods such as Quark's greener grass option @Override diff --git a/src/main/java/org/dimdev/dimdoors/world/limbo/LimboChunkGenerator.java b/src/main/java/org/dimdev/dimdoors/world/limbo/LimboChunkGenerator.java index 1c7b00c2..378c5ee0 100644 --- a/src/main/java/org/dimdev/dimdoors/world/limbo/LimboChunkGenerator.java +++ b/src/main/java/org/dimdev/dimdoors/world/limbo/LimboChunkGenerator.java @@ -1,18 +1,35 @@ package org.dimdev.dimdoors.world.limbo; -import net.minecraft.util.math.noise.OctavePerlinNoiseSampler; -import net.minecraft.world.World; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.gen.chunk.SurfaceChunkGenerator; -import java.util.Random; +public class LimboChunkGenerator extends SurfaceChunkGenerator { + public LimboChunkGenerator(IWorld iWorld, BiomeSource biomeSource, int i, int j, int k, LimboChunkGeneratorConfig chunkGeneratorConfig, boolean bl) { + super(iWorld, biomeSource, i, j, k, chunkGeneratorConfig, bl); + } -public class LimboChunkGenerator implements SurfaceChunkGenerator { - private final double[] noiseFalloff = this.buildNoiseFalloff(); - - private double[] buildNoiseFalloff() { + @Override + protected double[] computeNoiseRange(int i, int j) { return new double[0]; } + @Override + protected double computeNoiseFalloff(double d, double e, int i) { + return 0; + } + + @Override + protected void sampleNoiseColumn(double[] ds, int i, int j) { + + } + + @Override + public int getSpawnHeight() { + return 0; + } + +// private final double[] noiseFalloff = this.buildNoiseFalloff(); // // @Override // public int getHeightOnGround(int x, int z, Heightmap.Type type) { @@ -97,42 +114,42 @@ public class LimboChunkGenerator implements SurfaceChunkGenerator createChunkGenerator() { - return new LimboChunkGenerator(); + return null; } - @Nullable @Override public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) { return null; } - @Nullable @Override public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) { return null; @@ -43,7 +46,7 @@ public class LimboDimension extends Dimension { } @Override - public Vec3d getFogColor(float f, float g) { + public Vec3d modifyFogColor(Vec3d vec3d, float f) { return null; } diff --git a/src/main/java/org/dimdev/dimdoors/world/limbo/LimboSkyProvider.java b/src/main/java/org/dimdev/dimdoors/world/limbo/LimboSkyProvider.java deleted file mode 100644 index f8a2e3fe..00000000 --- a/src/main/java/org/dimdev/dimdoors/world/limbo/LimboSkyProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.dimdev.dimdoors.world.limbo; - -import org.dimdev.dimdoors.world.CustomSkyProvider; -import net.minecraft.util.Identifier; - -/** - * Created by Jared Johnson on 1/24/2017. - */ -public class LimboSkyProvider extends CustomSkyProvider { - private static final Identifier moonRenderPath = new Identifier("dimdoors:textures/other/limbo_moon.png"); - private static final Identifier sunRenderPath = new Identifier("dimdoors:textures/other/limbo_sun.png"); - - @Override - public Identifier getMoonRenderPath() { - return moonRenderPath; - } - - @Override - public Identifier getSunRenderPath() { - return sunRenderPath; - } -} diff --git a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/DungeonPocketDimension.java b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/DungeonPocketDimension.java index bc5b85f2..7966bc5e 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/DungeonPocketDimension.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/DungeonPocketDimension.java @@ -1,47 +1,60 @@ package org.dimdev.dimdoors.world.pocketdimension; -import net.minecraft.world.DimensionType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; -import org.dimdev.util.render.CloudRenderBlank; -import org.dimdev.dimdoors.world.ModDimensions; -import org.dimdev.dimdoors.world.ModBiomes; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.biome.BiomeProviderSingle; +import net.minecraft.world.gen.chunk.ChunkGenerator; import org.dimdev.pocketlib.PocketWorldDimension; public class DungeonPocketDimension extends PocketWorldDimension { - public DungeonPocketDimension(World world, DimensionType dimensionType) { - + public DungeonPocketDimension(World world, DimensionType dimensionType, float f) { + super(world, dimensionType, f); } @Override - public void init() { - super.init(); - biomeProvider = new BiomeProviderSingle(ModBiomes.DANGEROUS_BLACK_VOID); + public ChunkGenerator createChunkGenerator() { + return null; } @Override - public int getRespawnDimension(EntityPlayerMP player) { - return ModDimensions.LIMBO.getId(); - } - - @SideOnly(Side.CLIENT) - @Override - public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) { - setCloudRenderer(new CloudRenderBlank()); - return Vec3d.ZERO; - } - - @Override public DimensionType getDimensionType() { - return ModDimensions.DUNGEON; + public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) { + return null; } @Override - @SideOnly(Side.CLIENT) - public Vec3d getFogColor(float celestialAngle, float partialTicks) { - return Vec3d.ZERO; + public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) { + return null; + } + + @Override + public float getSkyAngle(long l, float f) { + return 0; + } + + @Override + public boolean hasVisibleSky() { + return false; + } + + @Override + public Vec3d modifyFogColor(Vec3d vec3d, float f) { + return null; + } + + @Override + public boolean canPlayersSleep() { + return false; + } + + @Override + public boolean isFogThick(int i, int j) { + return false; + } + + @Override + public DimensionType getType() { + return null; } } diff --git a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PersonalPocketDimension.java b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PersonalPocketDimension.java index 5ab4c3a9..cf9b5228 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PersonalPocketDimension.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PersonalPocketDimension.java @@ -1,68 +1,60 @@ package org.dimdev.dimdoors.world.pocketdimension; -import net.minecraft.client.audio.MusicTicker; -import net.minecraft.entity.Entity; -import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.DimensionType; import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeProviderSingle; import net.minecraft.world.dimension.DimensionType; -import org.dimdev.dimdoors.DimDoors; -import org.dimdev.dimdoors.sound.ModSoundEvents; -import org.dimdev.dimdoors.world.ModBiomes; -import org.dimdev.dimdoors.world.ModDimensions; +import net.minecraft.world.gen.chunk.ChunkGenerator; import org.dimdev.pocketlib.PocketWorldDimension; public class PersonalPocketDimension extends PocketWorldDimension { - @SideOnly(Side.CLIENT) - private static MusicTicker.MusicType music; - - static { - if (DimDoors.proxy.isClient()) { - music = EnumHelper.addEnum(MusicTicker.MusicType.class, "limbo", new Class[]{SoundEvent.class, int.class, int.class}, ModSoundEvents.WHITE_VOID, 0, 0); - } - } - - public PersonalPocketDimension(World world, DimensionType dimensionType) { - + public PersonalPocketDimension(World world, DimensionType dimensionType, float f) { + super(world, dimensionType, f); } @Override - public void init() { - super.init(); - hasSkyLight = false; // TODO: figure out why relighting takes so long with private pockets only... - biomeProvider = new BiomeProviderSingle(ModBiomes.WHITE_VOID); - } - - // TODO: disable this to allow dark places in public pockets - @Override - protected void generateLightBrightnessTable() { - for (int i = 0; i <= 15; ++i) { - lightBrightnessTable[i] = 1; - } + public ChunkGenerator createChunkGenerator() { + return null; } @Override - public DimensionType getDimensionType() { - return ModDimensions.PERSONAL; - } - - @SideOnly(Side.CLIENT) - @Override - public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) { - return new Vec3d(0.99, 0.99, 0.99); // https://bugs.mojang.com/projects/MC/issues/MC-123703 + public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) { + return null; } @Override - @SideOnly(Side.CLIENT) - public Vec3d getFogColor(float celestialAngle, float partialTicks) { - return new Vec3d(0.99, 0.99, 0.99); // https://bugs.mojang.com/projects/MC/issues/MC-123703 + public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) { + return null; } @Override - @SideOnly(Side.CLIENT) - public MusicTicker.MusicType getMusicType() { - return music; + public float getSkyAngle(long l, float f) { + return 0; + } + + @Override + public boolean hasVisibleSky() { + return false; + } + + @Override + public Vec3d modifyFogColor(Vec3d vec3d, float f) { + return null; + } + + @Override + public boolean canPlayersSleep() { + return false; + } + + @Override + public boolean isFogThick(int i, int j) { + return false; + } + + @Override + public DimensionType getType() { + return null; } } diff --git a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PublicPocketDimension.java b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PublicPocketDimension.java index 1982ab4e..f674f07b 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PublicPocketDimension.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocketdimension/PublicPocketDimension.java @@ -1,41 +1,60 @@ package org.dimdev.dimdoors.world.pocketdimension; -import net.minecraft.world.DimensionType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; -import org.dimdev.util.render.CloudRenderBlank; -import org.dimdev.dimdoors.world.ModDimensions; -import org.dimdev.dimdoors.world.ModBiomes; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.biome.BiomeProviderSingle; +import net.minecraft.world.gen.chunk.ChunkGenerator; import org.dimdev.pocketlib.PocketWorldDimension; public class PublicPocketDimension extends PocketWorldDimension { - public PublicPocketDimension(World world, DimensionType dimensionType) { - + public PublicPocketDimension(World world, DimensionType dimensionType, float f) { + super(world, dimensionType, f); } @Override - public void init() { - super.init(); - biomeProvider = new BiomeProviderSingle(ModBiomes.BLACK_VOID); - } - - @SideOnly(Side.CLIENT) - @Override - public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) { - setCloudRenderer(new CloudRenderBlank()); - return Vec3d.ZERO; - } - - @Override public DimensionType getDimensionType() { - return ModDimensions.PUBLIC; + public ChunkGenerator createChunkGenerator() { + return null; } @Override - @SideOnly(Side.CLIENT) - public Vec3d getFogColor(float celestialAngle, float partialTicks) { - return Vec3d.ZERO; + public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) { + return null; + } + + @Override + public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) { + return null; + } + + @Override + public float getSkyAngle(long l, float f) { + return 0; + } + + @Override + public boolean hasVisibleSky() { + return false; + } + + @Override + public Vec3d modifyFogColor(Vec3d vec3d, float f) { + return null; + } + + @Override + public boolean canPlayersSleep() { + return false; + } + + @Override + public boolean isFogThick(int i, int j) { + return false; + } + + @Override + public DimensionType getType() { + return null; } } diff --git a/src/main/java/org/dimdev/pocketlib/Pocket.java b/src/main/java/org/dimdev/pocketlib/Pocket.java index e4bc3a63..9eea5030 100644 --- a/src/main/java/org/dimdev/pocketlib/Pocket.java +++ b/src/main/java/org/dimdev/pocketlib/Pocket.java @@ -1,21 +1,35 @@ package org.dimdev.pocketlib; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.TranslatableText; import net.minecraft.util.DyeColor; import net.minecraft.util.math.BlockBox; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.dimdev.annotatednbt.Saved; -import org.dimdev.dimdoors.DimDoors; +import org.dimdev.dimdoors.block.ModBlocks; +import org.dimdev.util.WorldUtils; + +import java.util.Arrays; +import java.util.Collections; public final class Pocket { + private static final int BLOCKS_PAINTED_PER_DYE = 1106; @Saved public final int id; @Saved public BlockBox box; @Saved public VirtualLocation virtualLocation; @Saved public DyeColor dyeColor = DyeColor.WHITE; @Saved public DyeColor nextDyeColor = null; @Saved public int count = 0; - public World world; + public ServerWorld world; + + public Pocket(int id, ServerWorld world, int x, int z) { + this.id = id; + this.world = world; + new BlockBox(x * 16, 0, z * 16, (x + 1) * 16, 255, (z + 1) * 16); + } boolean isInBounds(BlockPos pos) { return box.contains(pos); @@ -29,7 +43,7 @@ public final class Pocket { int maxDye = amountOfDyeRequiredToColor(this); if (dyeColor == color) { - DimDoors.sendTranslatedMessage(entity, "dimdoors.pockets.dyeAlreadyAbsorbed"); + entity.sendMessage(new TranslatableText("dimdoors.pockets.dyeAlreadyAbsorbed")); return false; } @@ -38,51 +52,51 @@ public final class Pocket { dyeColor = color; this.nextDyeColor = null; count = 0; - DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.pocketHasBeenDyed", dyeColor); + entity.sendMessage(new TranslatableText("dimdoors.pocket.pocketHasBeenDyed", dyeColor)); return true; } else { count++; - DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); + entity.sendMessage(new TranslatableText("dimdoors.pocket.remainingNeededDyes", count, maxDye, color)); return true; } } else { this.nextDyeColor = color; count = 1; - DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); + entity.sendMessage(new TranslatableText("dimdoors.pocket.remainingNeededDyes", count, maxDye, color)); return true; } } - /*private void repaint(DyeColor dyeColor) { - short size = (short) ((this.size + 1) * 16 - 1); - BlockPos origin = getOrigin(); - World world = WorldUtils.getWorld(dim); - BlockState innerWall = ModBlocks.FABRIC.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property - BlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor); - - for (int x = origin.getX(); x < origin.getX() + size; x++) { - for (int y = origin.getY(); y < origin.getY() + size; y++) { - for (int z = origin.getZ(); z < origin.getZ() + size; z++) { - int layer = Collections.min(Arrays.asList(x, y, z, size - 1 - x, size - 1 - y, size - 1 - z)); - if (layer == 0) { - if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) { - world.setBlockState(x, y, z, outerWall); - } - } else if (layer < 5) { - if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) { - world.setBlockState(x, y, z, innerWall); - } - } - } - } - } - - return schematic; - }*/ +// private void repaint(DyeColor dyeColor) { +// BlockPos origin = getOrigin(); +// World world = WorldUtils.getWorld(dim); +// BlockState innerWall = ModBlocks.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property +// BlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor); +// +// for (int x = origin.getX(); x < origin.getX() + size; x++) { +// for (int y = origin.getY(); y < origin.getY() + size; y++) { +// for (int z = origin.getZ(); z < origin.getZ() + size; z++) { +// int layer = Collections.min(Arrays.asList(x, y, z, size - 1 - x, size - 1 - y, size - 1 - z)); +// if (layer == 0) { +// if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) { +// world.setBlockState(x, y, z, outerWall); +// } +// } else if (layer < 5) { +// if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) { +// world.setBlockState(x, y, z, innerWall); +// } +// } +// } +// } +// } +// +// return schematic; +// } private static int amountOfDyeRequiredToColor(Pocket pocket) { - int s = 16 * pocket.getSize(); + int outerVolume = pocket.box.getBlockCountX() * pocket.box.getBlockCountY() * pocket.box.getBlockCountZ(); + int innerVolume = (pocket.box.getBlockCountX() - 5) * (pocket.box.getBlockCountY() - 5) * (pocket.box.getBlockCountZ() - 5); - return (int) ((Math.pow(s, 3) - Math.pow(s - 10, 3)) / 1106); + return (outerVolume - innerVolume) / BLOCKS_PAINTED_PER_DYE; } } diff --git a/src/main/java/org/dimdev/pocketlib/PocketRegistry.java b/src/main/java/org/dimdev/pocketlib/PocketRegistry.java index 24c0f529..dbb032f7 100644 --- a/src/main/java/org/dimdev/pocketlib/PocketRegistry.java +++ b/src/main/java/org/dimdev/pocketlib/PocketRegistry.java @@ -1,14 +1,14 @@ package org.dimdev.pocketlib; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.PersistentState; import net.minecraft.world.World; -import net.minecraft.world.storage.MapStorage; +import org.dimdev.annotatednbt.AnnotatedNbt; import org.dimdev.annotatednbt.Saved; import org.dimdev.dimdoors.ModConfig; import org.dimdev.util.math.GridUtil; -import org.dimdev.annotatednbt.AnnotatedNbt; import java.util.HashMap; import java.util.Map; @@ -23,10 +23,14 @@ public class PocketRegistry extends PersistentState { @Saved /*package-private*/ Map pockets; @Saved /*package-private*/ int nextID; - private World world; + private ServerWorld world; public PocketRegistry() { super(DATA_NAME); + gridSize = ModConfig.POCKETS.pocketGridSize; + + nextID = 0; + pockets = new HashMap<>(); } public PocketRegistry(String s) { @@ -44,19 +48,12 @@ public class PocketRegistry extends PersistentState { return tag; } - public static PocketRegistry instance(World world) { + public static PocketRegistry instance(ServerWorld world) { if (!(world.dimension instanceof PocketWorldDimension)) { throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!"); } - MapStorage storage = world.getPerWorldStorage(); - PocketRegistry instance = (PocketRegistry) storage.getOrLoadData(PocketRegistry.class, DATA_NAME); - - if (instance == null) { - instance = new PocketRegistry(); - instance.initNewRegistry(); - storage.setData(DATA_NAME, instance); - } + PocketRegistry instance = world.getPersistentStateManager().get(PocketRegistry::new, DATA_NAME); instance.world = world; for (Pocket pocket : instance.pockets.values()) { @@ -66,13 +63,6 @@ public class PocketRegistry extends PersistentState { return instance; } - public void initNewRegistry() { - gridSize = ModConfig.POCKETS.pocketGridSize; - - nextID = 0; - pockets = new HashMap<>(); - } - /** * Create a new blank pocket. * diff --git a/src/main/java/org/dimdev/pocketlib/PocketWorldDimension.java b/src/main/java/org/dimdev/pocketlib/PocketWorldDimension.java index 5d177784..15d2d7ab 100644 --- a/src/main/java/org/dimdev/pocketlib/PocketWorldDimension.java +++ b/src/main/java/org/dimdev/pocketlib/PocketWorldDimension.java @@ -1,61 +1,11 @@ package org.dimdev.pocketlib; -import net.minecraft.entity.Entity; -import net.minecraft.init.Biomes; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.biome.BiomeProviderSingle; +import net.minecraft.world.World; import net.minecraft.world.dimension.Dimension; -import net.minecraft.world.gen.IChunkGenerator; -import org.dimdev.dimdoors.DimDoors; -import org.dimdev.util.render.CloudRenderBlank; - -import javax.annotation.Nullable; +import net.minecraft.world.dimension.DimensionType; public abstract class PocketWorldDimension extends Dimension { - - @Override - public void init() { - hasSkyLight = true; - generateLightBrightnessTable(); - DimDoors.proxy.setCloudRenderer(this, new CloudRenderBlank()); - biomeProvider = new BiomeProviderSingle(Biomes.PLAINS); - } - - @Override - public IChunkGenerator createChunkGenerator() { - return new BlankChunkGenerator(world, world.getSeed()); - } - - @Override public float calculateCelestialAngle(long worldTime, float partialTicks) { return 0.0F; } - - @Override public boolean canRespawnHere() { return false; } - - @Override public boolean isSurfaceWorld() { return false; } - - @Override public boolean canCoordinateBeSpawn(int x, int z) { return true; } // Spawn is set even if it canCoordinateBeSpawn is false after 1000 tries anyway - - @Override public int getAverageGroundLevel() { return 0; } // Pocket worlds are mostly void-filled - - @Override public boolean shouldMapSpin(String entity, double x, double z, double rotation) { return true; } - - @Override @Nullable - @SideOnly(Side.CLIENT) public float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks) { return null; } - - @Override @SideOnly(Side.CLIENT) public boolean doesXZShowFog(int x, int z) { - return false; // TODO: set this to true outside of pockets - } - - @Override - @SideOnly(Side.CLIENT) - public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) { - return Vec3d.ZERO; - } - - @Override @SideOnly(Side.CLIENT) public Vec3d getFogColor(float celestialAngle, float partialTicks) { return Vec3d.ZERO; } - - @Override - @SideOnly(Side.CLIENT) - public double getVoidFogYFactor() { - return 1; + public PocketWorldDimension(World world, DimensionType dimensionType, float f) { + super(world, dimensionType, f); } } diff --git a/src/main/java/org/dimdev/pocketlib/PrivatePocketData.java b/src/main/java/org/dimdev/pocketlib/PrivatePocketData.java index f8259383..292883b6 100644 --- a/src/main/java/org/dimdev/pocketlib/PrivatePocketData.java +++ b/src/main/java/org/dimdev/pocketlib/PrivatePocketData.java @@ -3,9 +3,11 @@ package org.dimdev.pocketlib; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.Identifier; import net.minecraft.world.PersistentState; import net.minecraft.world.World; -import net.minecraft.world.storage.MapStorage; +import net.minecraft.world.dimension.DimensionType; import org.dimdev.annotatednbt.AnnotatedNbt; import org.dimdev.annotatednbt.Saved; import org.dimdev.util.WorldUtils; @@ -14,10 +16,10 @@ import java.util.UUID; public class PrivatePocketData extends PersistentState { protected static class PocketInfo { - @Saved public final World world; + @Saved public final ServerWorld world; @Saved public final int id; - public PocketInfo(World world, int id) { + public PocketInfo(ServerWorld world, int id) { this.world = world; this.id = id; } @@ -35,15 +37,7 @@ public class PrivatePocketData extends PersistentState { } public static PrivatePocketData instance() { - MapStorage storage = WorldUtils.getWorld(0).getMapStorage(); - PrivatePocketData instance = (PrivatePocketData) storage.getOrLoadData(PrivatePocketData.class, DATA_NAME); - - if (instance == null) { - instance = new PrivatePocketData(); - storage.setData(DATA_NAME, instance); - } - - return instance; + return WorldUtils.getWorld(DimensionType.OVERWORLD).getPersistentStateManager().get(PrivatePocketData::new, DATA_NAME); } @Override diff --git a/src/main/java/org/dimdev/pocketlib/VirtualLocation.java b/src/main/java/org/dimdev/pocketlib/VirtualLocation.java index d6f535cf..bfa8d304 100644 --- a/src/main/java/org/dimdev/pocketlib/VirtualLocation.java +++ b/src/main/java/org/dimdev/pocketlib/VirtualLocation.java @@ -1,6 +1,7 @@ package org.dimdev.pocketlib; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Heightmap; import net.minecraft.world.World; @@ -12,12 +13,12 @@ import org.dimdev.dimdoors.world.limbo.LimboDimension; import org.dimdev.util.Location; public class VirtualLocation { - @Saved public final World world; + @Saved public final ServerWorld world; @Saved public final int x; @Saved public final int z; @Saved public final int depth; - public VirtualLocation(World world, int x, int z, int depth) { + public VirtualLocation(ServerWorld world, int x, int z, int depth) { this.world = world; this.x = x; this.z = z; @@ -55,7 +56,7 @@ public class VirtualLocation { } public Location projectToWorld(boolean acceptLimbo) { - World world = this.world; + ServerWorld world = this.world; if (!acceptLimbo && world.dimension instanceof LimboDimension) { world = world.getServer().getWorld(DimensionType.OVERWORLD); diff --git a/src/main/java/org/dimdev/util/EntityUtils.java b/src/main/java/org/dimdev/util/EntityUtils.java index 06d5b88c..ca0c4ba2 100644 --- a/src/main/java/org/dimdev/util/EntityUtils.java +++ b/src/main/java/org/dimdev/util/EntityUtils.java @@ -5,10 +5,7 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ExplosiveProjectileEntity; -import net.minecraft.entity.projectile.FishingBobberEntity; -import net.minecraft.entity.projectile.LlamaSpitEntity; -import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.entity.projectile.*; import net.minecraft.entity.thrown.ThrownEntity; import net.minecraft.server.world.ServerWorld; @@ -17,10 +14,7 @@ public final class EntityUtils { Entity topmostEntity = null; // Thrower - if (entity instanceof ThrownEntity) topmostEntity = ((ThrownEntity) entity).getOwner(); - if (entity instanceof ProjectileEntity) topmostEntity = ((ProjectileEntity) entity).getOwner(); - if (entity instanceof ExplosiveProjectileEntity) topmostEntity = ((ExplosiveProjectileEntity) entity).owner; - if (entity instanceof LlamaSpitEntity) topmostEntity = ((LlamaSpitEntity) entity).owner; + if (entity instanceof Projectile) topmostEntity = ((Projectile) entity).getOwner(); if (entity instanceof FishingBobberEntity) topmostEntity = ((FishingBobberEntity) entity).getOwner(); if (entity instanceof ItemEntity) topmostEntity = ((ServerWorld) entity.getEntityWorld()).getEntity(((ItemEntity) entity).getThrower()); diff --git a/src/main/java/org/dimdev/util/Location.java b/src/main/java/org/dimdev/util/Location.java index 01b0b3c8..8dc591c7 100644 --- a/src/main/java/org/dimdev/util/Location.java +++ b/src/main/java/org/dimdev/util/Location.java @@ -3,6 +3,7 @@ package org.dimdev.util; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.fluid.FluidState; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -13,15 +14,15 @@ import org.dimdev.annotatednbt.Saved; import java.io.Serializable; public class Location implements AutoSerializable { - @Saved public final World world; + @Saved public final ServerWorld world; @Saved public final BlockPos pos; - public Location(World world, BlockPos pos) { + public Location(ServerWorld world, BlockPos pos) { this.world = world; this.pos = pos; } - public Location(World world, int x, int y, int z) { + public Location(ServerWorld world, int x, int y, int z) { this(world, new BlockPos(x, y, z)); } diff --git a/src/main/java/org/dimdev/util/RotatedLocation.java b/src/main/java/org/dimdev/util/RotatedLocation.java index 81ed4958..36d5851d 100644 --- a/src/main/java/org/dimdev/util/RotatedLocation.java +++ b/src/main/java/org/dimdev/util/RotatedLocation.java @@ -1,6 +1,7 @@ package org.dimdev.util; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.dimdev.annotatednbt.AutoSerializable; @@ -11,7 +12,7 @@ public class RotatedLocation extends Location implements AutoSerializable { @Saved public final float yaw; @Saved public final float pitch; - public RotatedLocation(World world, BlockPos pos, float yaw, float pitch) { + public RotatedLocation(ServerWorld world, BlockPos pos, float yaw, float pitch) { super(world, pos); this.yaw = yaw; this.pitch = pitch; diff --git a/src/main/java/org/dimdev/util/TeleportUtil.java b/src/main/java/org/dimdev/util/TeleportUtil.java index 4945876d..71dcd374 100644 --- a/src/main/java/org/dimdev/util/TeleportUtil.java +++ b/src/main/java/org/dimdev/util/TeleportUtil.java @@ -2,7 +2,6 @@ package org.dimdev.util; import net.fabricmc.fabric.api.dimension.v1.FabricDimensions; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldView; @@ -25,11 +24,9 @@ public final class TeleportUtil { public static void teleport(Entity entity, WorldView world, double x, double y, double z, float yaw, float pitch) { FabricDimensions.teleport(entity, world.getDimension().getType()); - entity.setPositionAndAngles(x, y, z, yaw, pitch); + entity.setPos(x, y, z); + entity.yaw = yaw; + entity.pitch = pitch; entity.setOnFireFor(0); // Workaround for https://bugs.mojang.com/browse/MC-100097 } - - public static void teleport(PlayerEntity player, BlockPos pos) { - - } } diff --git a/src/main/java/org/dimdev/util/WorldUtils.java b/src/main/java/org/dimdev/util/WorldUtils.java index 0133909a..d01acdfe 100644 --- a/src/main/java/org/dimdev/util/WorldUtils.java +++ b/src/main/java/org/dimdev/util/WorldUtils.java @@ -1,14 +1,10 @@ package org.dimdev.util; -import net.minecraft.util.Identifier; -import net.minecraft.world.World; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.dimension.DimensionType; public final class WorldUtils { - public static World getWorld(Identifier dimension) { - return null; // TODO - } - - public static Identifier getDim(World world) { - return null; // TODO + public static ServerWorld getWorld(DimensionType personal) { + return null; } } diff --git a/src/main/java/org/dimdev/util/schem/Schematic.java b/src/main/java/org/dimdev/util/schem/Schematic.java index 5e2a3674..bc150274 100644 --- a/src/main/java/org/dimdev/util/schem/Schematic.java +++ b/src/main/java/org/dimdev/util/schem/Schematic.java @@ -254,8 +254,8 @@ public class Schematic { // property is Property, value is Comparable, and the ?s refer to the same type because // IProperty.getAllowedValues() returns Collection, but the compiler doesn't keep track of // this, so casting to raw types: - //noinspection rawtypes - chosenState = chosenState.with(property, (Comparable) value); + //noinspection unchecked,RedundantCast,SingleStatementInBlock,rawtypes + chosenState = chosenState.with((Property) property, (Comparable) value); } } } @@ -357,7 +357,7 @@ public class Schematic { blockEntity.fromTag(BlockEntityNBT); // Correct the position - blockEntity.setWorld(world, pos); + blockEntity.setLocation(world, pos); blockEntity.markDirty(); } else { throw new RuntimeException("Schematic contained BlockEntity " + id + " at " + pos + " but the BlockEntity of that block (" + world.getBlockState(pos) + ") must be " + blockBlockEntityId); @@ -377,7 +377,7 @@ public class Schematic { newPosNBT.add(DoubleTag.of(posNBT.getDouble(2) + zBase)); CompoundTag adjustedEntityTag = entityNBT.copy(); adjustedEntityTag.put("Pos", newPosNBT); - adjustedEntityTag.putUuid("UUID", UUID.randomUUID()); + adjustedEntityTag.putUuidNew("UUID", UUID.randomUUID()); world.spawnEntity(EntityType.getEntityFromTag(adjustedEntityTag, world).orElseThrow(() -> new RuntimeException("missing entity type"))); }