Continue updating to 1.16

This commit is contained in:
Runemoro 2020-03-16 04:29:02 -04:00
parent d38791e92b
commit e6f7184193
68 changed files with 831 additions and 1459 deletions

View file

@ -30,9 +30,6 @@ There are many ways to contribute to the project. We encourage you to join our D
### Submitting dungeons ### Submitting dungeons
Use the `/pocket blank blank_pocket_<n>` to create a blank, closed pocket, or `/pocket blank void_pocket_<n>` to create a pocket containing only a frame marking the pocket bounds, where `<n>` 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 <name>` 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. Use the `/pocket blank blank_pocket_<n>` to create a blank, closed pocket, or `/pocket blank void_pocket_<n>` to create a pocket containing only a frame marking the pocket bounds, where `<n>` 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 <name>` 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 ### 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. [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.

View file

@ -5,7 +5,7 @@ buildscript {
} }
dependencies { 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 'com.flowpowered:flow-math:1.0.3'
modCompile 'org.jgrapht:jgrapht-core:1.1.0' modCompile 'org.jgrapht:jgrapht-core:1.1.0'
modCompile 'com.github.DimensionalDevelopment:poly2tri.java:master-SNAPSHOT' modCompile 'com.github.DimensionalDevelopment:poly2tri.java:master-SNAPSHOT'
modCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.10'
} }
version "4.0" version "4.0"

View file

@ -1,4 +1,4 @@
minecraft_version=1.15-pre3 minecraft_version=20w11a
yarn_version=1.15-pre3+build.2 yarn_version=20w11a+build.6
loader_version=0.7.1+build.173 loader_version=0.7.8+build.187
fabric_version=0.4.18+build.271-1.15 fabric_version=0.5.3+build.308-1.16

View file

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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

View file

@ -1,11 +1,9 @@
package org.dimdev.annotatednbt; package org.dimdev.annotatednbt;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import org.dimdev.dimdoors.rift.registry.PlayerRiftPointer;
import org.dimdev.util.RotatedLocation; import org.dimdev.util.RotatedLocation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class AnnotatedNbt { public final class AnnotatedNbt {
public static <T> T deserialize(Class<RotatedLocation> rotatedLocationClass, CompoundTag tag) { public static <T> T deserialize(Class<RotatedLocation> rotatedLocationClass, CompoundTag tag) {
return null; // TODO return null; // TODO
@ -22,4 +20,12 @@ public final class AnnotatedNbt {
public static void save(Object object, CompoundTag tag) { public static void save(Object object, CompoundTag tag) {
// TODO // TODO
} }
public static void fromTag(Object playerRiftPointer, CompoundTag nbt) {
}
public static CompoundTag toTag(Object playerRiftPointer, CompoundTag nbt) {
return null;
}
} }

View file

@ -2,27 +2,22 @@ package org.dimdev.dimdoors;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.text.TranslatableText;
import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.item.ModItems; import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.rift.targets.*; import org.dimdev.dimdoors.rift.targets.*;
import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.dimdoors.world.ModDimensions;
import java.io.File;
public class DimDoors implements ModInitializer { public class DimDoors implements ModInitializer {
public static void sendTranslatedMessage(Entity entity, String s, Object... args) {
// TODO
}
public static String getConfigurationFolder() { public static String getConfigurationFolder() {
return null; // TODO return "config"; // TODO
} }
@Override @Override
public void onInitialize() { public void onInitialize() {
ModBlocks.init(); ModBlocks.init();
ModItems.init(); ModItems.init();
ModDimensions.registerDimensions(); ModDimensions.init();
VirtualTarget.registry.put("available_link", RandomTarget.class); VirtualTarget.registry.put("available_link", RandomTarget.class);
VirtualTarget.registry.put("escape", EscapeTarget.class); VirtualTarget.registry.put("escape", EscapeTarget.class);

View file

@ -1,29 +1,19 @@
package org.dimdev.dimdoors; 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 { public final class EventHandler {
// @SubscribeEvent(priority = EventPriority.HIGHEST)
@SubscribeEvent(priority = EventPriority.HIGHEST) // public static void onLivingHurt(LivingHurtEvent event) {
public static void onLivingHurt(LivingHurtEvent event) { // Entity entity = event.getEntity();
Entity entity = event.getEntity(); // if (entity.dimension == ModDimensions.LIMBO && event.getSource() == DamageSource.FALL) {
if (entity.dimension == ModDimensions.LIMBO.getId() && event.getSource() == DamageSource.FALL) { // event.setCanceled(true);// no fall damage in limbo
event.setCanceled(true);// no fall damage in limbo // }
} // }
} //
// @SubscribeEvent(priority = EventPriority.LOWEST)
@SubscribeEvent(priority = EventPriority.LOWEST) // public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) {
public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) { // // TODO: Make this work with other mods (such as Dimensional Industry)
// TODO: Make this work with other mods (such as Dimensional Industry) // if (!ModDimensions.isDimDoorsPocketDimension(event.fromDim) && ModDimensions.isDimDoorsPocketDimension(event.toDim)) {
if (!ModDimensions.isDimDoorsPocketDimension(event.fromDim) && ModDimensions.isDimDoorsPocketDimension(event.toDim)) { // RiftRegistry.instance().setOverworldRift(event.player.getUniqueID(), null);
RiftRegistry.instance().setOverworldRift(event.player.getUniqueID(), null); // }
} // }
}
} }

View file

@ -1,5 +1,8 @@
package org.dimdev.dimdoors; package org.dimdev.dimdoors;
import java.util.LinkedHashSet;
import java.util.Set;
public final class ModConfig { public final class ModConfig {
public static final General GENERAL = new General(); public static final General GENERAL = new General();
public static final Pockets POCKETS = new Pockets(); public static final Pockets POCKETS = new Pockets();
@ -33,8 +36,8 @@ public final class ModConfig {
public static class World { public static class World {
public double clusterGenChance = 0.0002; public double clusterGenChance = 0.0002;
public double gatewayGenChance = 0.0015; public double gatewayGenChance = 0.0015;
public int[] clusterDimBlacklist = {}; public Set<Integer> clusterDimBlacklist = new LinkedHashSet<>();
public int[] gatewayDimBlacklist = {}; public Set<Integer> gatewayDimBlacklist = new LinkedHashSet<>();
} }
public static class Dungeons { public static class Dungeons {

View file

@ -15,12 +15,9 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity; import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import javax.annotation.Nullable;
public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<EntranceRiftBlockEntity> { public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<EntranceRiftBlockEntity> {
public DimensionalDoorBlock(Settings settings) { public DimensionalDoorBlock(Settings settings) {
super(settings); super(settings);
@ -54,19 +51,16 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
return super.canReplace(state, context) || state.getBlock() == ModBlocks.DETACHED_RIFT; return super.canReplace(state, context) || state.getBlock() == ModBlocks.DETACHED_RIFT;
} }
@Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity createBlockEntity(BlockView world) {
return new EntranceRiftBlockEntity(); return new EntranceRiftBlockEntity();
} }
@Override @Override
public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState blockState, @Nullable BlockEntity entity, ItemStack stack) { public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState blockState, BlockEntity entity, ItemStack stack) {
if (entity instanceof EntranceRiftBlockEntity) { if (entity instanceof EntranceRiftBlockEntity) {
EntranceRiftBlockEntity oldRift = (EntranceRiftBlockEntity) entity;
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState()); world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity newRift = (DetachedRiftBlockEntity) world.getBlockEntity(pos); ((DetachedRiftBlockEntity) world.getBlockEntity(pos)).load(((EntranceRiftBlockEntity) entity).serialize());
newRift.load(oldRift.serialize());
} }
} }

View file

@ -15,7 +15,6 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity; import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import javax.annotation.Nullable;
// TODO: Make this placeable on rifts // TODO: Make this placeable on rifts
public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvider<EntranceRiftBlockEntity> { public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvider<EntranceRiftBlockEntity> {
@ -31,7 +30,7 @@ public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvi
} }
} }
@Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockView blockView) { public BlockEntity createBlockEntity(BlockView blockView) {
return new EntranceRiftBlockEntity(); return new EntranceRiftBlockEntity();

View file

@ -19,7 +19,7 @@ public class FabricBlock extends Block {
} }
@Override @Override
@SuppressWarnings("deprecated") @SuppressWarnings({"deprecation"})
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 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(); ItemStack heldStack = hand == Hand.MAIN_HAND ? player.getMainHandStack() : player.getOffHandStack();
Block heldBlock = Block.getBlockFromItem(heldStack.getItem()); Block heldBlock = Block.getBlockFromItem(heldStack.getItem());

View file

@ -62,6 +62,10 @@ public final class ModBlocks {
return Registry.register(Registry.BLOCK, string, block); 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 private static class DoorBlock extends net.minecraft.block.DoorBlock { // TODO: use access transformer instead
protected DoorBlock(Settings settings) { protected DoorBlock(Settings settings) {
super(settings); super(settings);

View file

@ -1,6 +1,5 @@
package org.dimdev.dimdoors.block.entity; package org.dimdev.dimdoors.block.entity;
import lombok.Setter;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -8,13 +7,14 @@ import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType; import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Tickable; import net.minecraft.util.Tickable;
import org.dimdev.annotatednbt.AnnotatedNbt;
import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.util.Location; import org.dimdev.util.Location;
import org.dimdev.util.TeleportUtil; import org.dimdev.util.TeleportUtil;
import org.dimdev.annotatednbt.AnnotatedNbt;
import java.util.Random; import java.util.Random;
@ -27,7 +27,7 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable
@Saved public int spawnedEndermanId = 0; @Saved public int spawnedEndermanId = 0;
@Saved public float size = 0; @Saved public float size = 0;
@Setter private boolean unregisterDisabled = false; private boolean unregisterDisabled = false;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public double renderAngle; public double renderAngle;
@ -99,7 +99,9 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable
@Override @Override
public boolean receiveEntity(Entity entity, float relativeYaw, float relativePitch) { 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; return true;
} }
public void setUnregisterDisabled(boolean unregisterDisabled) {this.unregisterDisabled = unregisterDisabled; }
} }

View file

@ -43,7 +43,7 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
@Override @Override
public boolean receiveEntity(Entity entity, float relativeYaw, float relativePitch) { 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); TeleportUtil.teleport(entity, world, targetPos.x, targetPos.y, targetPos.z, entity.yaw + relativeYaw, entity.pitch + relativePitch);
return true; return true;

View file

@ -23,6 +23,6 @@ public class ModBlockEntityTypes {
); );
private static <E extends BlockEntity> BlockEntityType<E> register(String id, Supplier<? extends E> supplier, Block[] blocks) { private static <E extends BlockEntity> BlockEntityType<E> register(String id, Supplier<? extends E> 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));
} }
} }

View file

@ -1,12 +1,11 @@
package org.dimdev.dimdoors.block.entity; package org.dimdev.dimdoors.block.entity;
import lombok.Getter;
import lombok.ToString;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -21,17 +20,15 @@ import org.dimdev.dimdoors.rift.targets.*;
import org.dimdev.pocketlib.VirtualLocation; import org.dimdev.pocketlib.VirtualLocation;
import org.dimdev.util.Location; import org.dimdev.util.Location;
import javax.annotation.Nonnull;
import java.util.Arrays; import java.util.Arrays;
@ToString
public abstract class RiftBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Target, EntityTarget, AutoSerializable { public abstract class RiftBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Target, EntityTarget, AutoSerializable {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
/*@Saved*/ @Nonnull @Getter protected VirtualTarget destination; // How the rift acts as a source /*@Saved*/ protected VirtualTarget destination; // How the rift acts as a source
@Saved @Getter protected LinkProperties properties; @Saved protected LinkProperties properties;
@Saved @Getter protected boolean alwaysDelete; @Saved protected boolean alwaysDelete;
@Saved @Getter protected boolean forcedColor; @Saved protected boolean forcedColor;
@Saved @Getter protected float[] color = null; @Saved protected float[] color = null;
protected boolean riftStateChanged; // not saved protected boolean riftStateChanged; // not saved
@ -67,7 +64,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
this.destination = destination; this.destination = destination;
if (destination != null) { if (destination != null) {
if (world != null && pos != null) { if (world != null && pos != null) {
destination.setLocation(new Location(world, pos)); destination.setLocation(new Location((ServerWorld) world, pos));
} }
if (isRegistered()) destination.register(); if (isRegistered()) destination.register();
} }
@ -94,7 +91,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
} }
public boolean isRegistered() { 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() { public void register() {
@ -102,7 +99,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
return; return;
} }
Location loc = new Location(world, pos); Location loc = new Location((ServerWorld) world, pos);
RiftRegistry.instance().addRift(loc); RiftRegistry.instance().addRift(loc);
if (destination != null) destination.register(); if (destination != null) destination.register();
updateProperties(); updateProperties();
@ -110,19 +107,19 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
} }
public void updateProperties() { 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(); markDirty();
} }
public void unregister() { public void unregister() {
if (isRegistered()) { if (isRegistered()) {
RiftRegistry.instance().removeRift(new Location(world, pos)); RiftRegistry.instance().removeRift(new Location((ServerWorld) world, pos));
} }
} }
public void updateType() { public void updateType() {
if (!isRegistered()) return; 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.isDetached = isDetached();
rift.markDirty(); rift.markDirty();
} }
@ -144,7 +141,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
if (destination == null) { if (destination == null) {
return new MessageTarget("rifts.unlinked"); return new MessageTarget("rifts.unlinked");
} else { } else {
destination.setLocation(new Location(world, pos)); destination.setLocation(new Location((ServerWorld) world, pos));
return destination; return destination;
} }
} }
@ -157,7 +154,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
EntityTarget target = getTarget().as(Targets.ENTITY); EntityTarget target = getTarget().as(Targets.ENTITY);
if (target.receiveEntity(entity, entity.yaw, entity.pitch)) { 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)); entity.sendMessage(new TranslatableText("You are at x = " + vloc.x + ", y = ?, z = " + vloc.z + ", w = " + vloc.depth));
return true; return true;
} }
@ -176,7 +173,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
} else if (destination == null) { } else if (destination == null) {
color = new float[]{0.7f, 0.7f, 0.7f, 1}; color = new float[]{0.7f, 0.7f, 0.7f, 1};
} else { } else {
destination.setLocation(new Location(world, pos)); destination.setLocation(new Location((ServerWorld) world, pos));
float[] newColor = destination.getColor(); float[] newColor = destination.getColor();
if (color == null && newColor != null || !Arrays.equals(color, newColor)) { if (color == null && newColor != null || !Arrays.equals(color, newColor)) {
color = newColor; color = newColor;
@ -193,4 +190,24 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
alwaysDelete = rift.alwaysDelete; alwaysDelete = rift.alwaysDelete;
forcedColor = rift.forcedColor; 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;
}
} }

View file

@ -14,7 +14,7 @@
//import org.dimdev.util.Location; //import org.dimdev.util.Location;
//import org.dimdev.util.TeleportUtil; //import org.dimdev.util.TeleportUtil;
// //
//import javax.annotation.Nullable; //
//import java.util.Arrays; //import java.util.Arrays;
//import java.util.Collections; //import java.util.Collections;
//import java.util.List; //import java.util.List;
@ -60,7 +60,7 @@
// } // }
// //
// @Override // @Override
// public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) { // public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) {
// if (args.length == 1) { // if (args.length == 1) {
// return Arrays.stream(DimensionManager.getStaticDimensionIDs()) // return Arrays.stream(DimensionManager.getStaticDimensionIDs())
// .map(Object::toString) // .map(Object::toString)

View file

@ -18,7 +18,7 @@
//import org.dimdev.dimdoors.world.ModDimensions; //import org.dimdev.dimdoors.world.ModDimensions;
//import org.dimdev.pocketlib.Pocket; //import org.dimdev.pocketlib.Pocket;
// //
//import javax.annotation.Nullable; //
//import java.util.ArrayList; //import java.util.ArrayList;
//import java.util.List; //import java.util.List;
//import java.util.stream.Collectors; //import java.util.stream.Collectors;
@ -76,7 +76,7 @@
// } // }
// //
// @Override // @Override
// public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) { // public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) {
// List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
// switch (args.length) { // switch (args.length) {
// case 1: // case 1:

View file

@ -15,6 +15,8 @@ public class ModEntityTypes {
true, true,
true, true,
true, true,
128,
32,
new EntityDimensions(3, 3, false) new EntityDimensions(3, 3, false)
); );
@ -26,10 +28,12 @@ public class ModEntityTypes {
true, true,
true, true,
true, true,
128,
32,
new EntityDimensions(1, 1, false) new EntityDimensions(1, 1, false)
); );
private static <E extends Entity> EntityType<E> register(String id, EntityType.EntityFactory<E> factory, EntityCategory category, boolean canSpawnFar, boolean saveable, boolean summonable, boolean immuneToFire, EntityDimensions dimensions) { private static <E extends Entity> EntityType<E> register(String id, EntityType.EntityFactory<E> 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, dimensions)); return Registry.register(Registry.ENTITY_TYPE, id, new EntityType<>(factory, category, canSpawnFar, saveable, summonable, immuneToFire, i, j, dimensions));
} }
} }

View file

@ -48,7 +48,7 @@ public class EternalLiquidFluid extends BaseFluid { // TODO
} }
@Override @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; return false;
} }

View file

@ -29,7 +29,6 @@ public class DimensionalDoorItem extends TallBlockItem {
@Override @Override
public ActionResult place(ItemPlacementContext context) { public ActionResult place(ItemPlacementContext context) {
BlockPos pos = context.getBlockPos(); BlockPos pos = context.getBlockPos();
BlockPos originalPos = context.getBlockPos(); // super.onItemUse needs the actual position
if (!context.getWorld().getBlockState(pos).canReplace(context)) { if (!context.getWorld().getBlockState(pos).canReplace(context)) {
pos = pos.offset(context.getPlayerFacing()); pos = pos.offset(context.getPlayerFacing());

View file

@ -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 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 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 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_HELMET = new WorldThreadArmorItem("world_thread_helmet", EquipmentSlot.HEAD, new Item.Settings());
public static final Item WOVEN_WORLD_THREAD_CHESTPLATE = new WorldThreadArmorItem("world_thread_chestplate", 1, EquipmentSlot.CHEST); 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", 2, EquipmentSlot.LEGS); 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", 1, EquipmentSlot.FEET); 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 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)); 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); 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 private static class MusicDiscItem extends net.minecraft.item.MusicDiscItem { // TODO: access transformers
protected MusicDiscItem(int i, SoundEvent soundEvent, Settings settings) { protected MusicDiscItem(int i, SoundEvent soundEvent, Settings settings) {
super(i, soundEvent, settings); super(i, soundEvent, settings);

View file

@ -4,6 +4,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem; import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterials; import net.minecraft.item.ToolMaterials;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -47,7 +48,7 @@ public class RiftBladeItem extends SwordItem {
if (RayTraceHelper.hitsLivingEntity(hit) || RayTraceHelper.hitsRift(hit, world)) { if (RayTraceHelper.hitsLivingEntity(hit) || RayTraceHelper.hitsRift(hit, world)) {
return new TypedActionResult<>(ActionResult.SUCCESS, stack); return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else { } else {
player.addChatMessage(new TranslatableText(getTranslationKey() + ".rift_miss"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".rift_miss"));
DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
return new TypedActionResult<>(ActionResult.FAIL, stack); 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 offsetDistance = Math.random() * damageMultiplier * 7 + 2; //TODO: make these offset distances configurable
double offsetRotationYaw = (Math.random() - 0.5) * damageMultiplier * 360; double offsetRotationYaw = (Math.random() - 0.5) * damageMultiplier * 360;
Vec3d playerVec = player.getPosVector(); Vec3d playerVec = player.getPos();
Vec3d entityVec = hit.getPos(); Vec3d entityVec = hit.getPos();
Vec3d offsetDirection = playerVec.subtract(entityVec).normalize(); Vec3d offsetDirection = playerVec.subtract(entityVec).normalize();
offsetDirection = offsetDirection.rotateY((float) (offsetRotationYaw * Math.PI) / 180); offsetDirection = offsetDirection.rotateY((float) (offsetRotationYaw * Math.PI) / 180);
BlockPos tpPos = new BlockPos(entityVec.add(offsetDirection.multiply(offsetDistance))); BlockPos tpPos = new BlockPos(entityVec.add(offsetDirection.multiply(offsetDistance)));
while (world.getBlockState(tpPos).getMaterial().blocksMovement()) tpPos = tpPos.up(); // TODO: move to ddutils 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 -> {}); stack.damage(1, player, a -> {});
return new TypedActionResult<>(ActionResult.SUCCESS, stack); return new TypedActionResult<>(ActionResult.SUCCESS, stack);

View file

@ -1,18 +1,15 @@
package org.dimdev.dimdoors.item; package org.dimdev.dimdoors.item;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.metadata.ModMetadataV0;
import net.minecraft.client.item.TooltipContext; import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EggItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; 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.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import static net.fabricmc.api.EnvType.CLIENT; import static net.fabricmc.api.EnvType.*;
public class RiftConfigurationToolItem extends Item { public class RiftConfigurationToolItem extends Item {
@ -41,7 +37,7 @@ public class RiftConfigurationToolItem extends Item {
if (world.isClient) { if (world.isClient) {
if (!RayTraceHelper.hitsRift(hit, world)) { 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; DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
} }
return new TypedActionResult<>(ActionResult.FAIL, stack); return new TypedActionResult<>(ActionResult.FAIL, stack);
@ -60,7 +56,7 @@ public class RiftConfigurationToolItem extends Item {
@Override @Override
@Environment(CLIENT) @Environment(CLIENT)
public void appendTooltip(ItemStack itemStack, @Nullable World world, List<Text> list, TooltipContext tooltipContext) { public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
if (I18n.hasTranslation(this.getTranslationKey() + ".info")) { if (I18n.hasTranslation(this.getTranslationKey() + ".info")) {
list.add(new TranslatableText(this.getTranslationKey() + ".info")); list.add(new TranslatableText(this.getTranslationKey() + ".info"));
} }

View file

@ -10,7 +10,6 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; 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.client.DetachedRiftBlockEntityRenderer;
import org.dimdev.dimdoors.sound.ModSoundEvents; import org.dimdev.dimdoors.sound.ModSoundEvents;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class RiftRemoverItem extends Item { public class RiftRemoverItem extends Item {
@ -31,7 +29,7 @@ public class RiftRemoverItem extends Item {
} }
@Override @Override
public void appendTooltip(ItemStack itemStack, @Nullable World world, List<Text> list, TooltipContext tooltipContext) { public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
if (I18n.hasTranslation(getTranslationKey() + ".info")) { if (I18n.hasTranslation(getTranslationKey() + ".info")) {
list.add(new TranslatableText(getTranslationKey() + ".info")); list.add(new TranslatableText(getTranslationKey() + ".info"));
} }
@ -45,7 +43,7 @@ public class RiftRemoverItem extends Item {
if (world.isClient) { if (world.isClient) {
if (!RayTraceHelper.hitsDetachedRift(hit, world)) { 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; DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
} }
return new TypedActionResult<>(ActionResult.FAIL, stack); return new TypedActionResult<>(ActionResult.FAIL, stack);
@ -55,12 +53,12 @@ public class RiftRemoverItem extends Item {
DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos())); DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
if (!rift.closing) { if (!rift.closing) {
rift.setClosing(true); 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 -> {}); stack.damage(10, player, a -> {});
player.addChatMessage(new TranslatableText(getTranslationKey() + ".closing"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".closing"));
return new TypedActionResult<>(ActionResult.SUCCESS, stack); return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else { } else {
player.addChatMessage(new TranslatableText(getTranslationKey() + ".already_closing"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".already_closing"));
} }
} }
return new TypedActionResult<>(ActionResult.FAIL, stack); return new TypedActionResult<>(ActionResult.FAIL, stack);

View file

@ -9,6 +9,7 @@ import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; 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.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.rift.targets.RiftReference; 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.Location;
import org.dimdev.util.RotatedLocation; import org.dimdev.util.RotatedLocation;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class RiftSignatureItem extends Item { public class RiftSignatureItem extends Item {
@ -66,38 +65,36 @@ public class RiftSignatureItem extends Item {
if (target == null) { if (target == null) {
// The link signature has not been used. Store its current target as the first location. // The link signature has not been used. Store its current target as the first location.
setSource(stack, new RotatedLocation(world, pos, player.yaw, 0)); setSource(stack, new RotatedLocation((ServerWorld) world, pos, player.yaw, 0));
player.addChatMessage(new TranslatableText(getTranslationKey() + ".stored"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".stored"));
world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1); world.playSound(null, player.getSenseCenterPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1);
} else { } else {
// Place a rift at the saved point // Place a rift at the saved point
if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) { if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) {
if (!target.getBlockState().getBlock().canMobSpawnInside()) { 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! clearSource(stack); // TODO: But is this fair? It's a rather hidden way of unbinding your signature!
return ActionResult.FAIL; return ActionResult.FAIL;
} }
World sourceWorld = ((Location) target).world; World sourceWorld = target.world;
sourceWorld.setBlockState(((Location) target).getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState()); sourceWorld.setBlockState(target.getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity(); DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity();
rift1.setDestination(RiftReference.tryMakeRelative(target, new Location(world, pos))); rift1.setDestination(RiftReference.tryMakeRelative(target, new Location((ServerWorld) world, pos)));
rift1.setTeleportTargetRotation(target.yaw, 0); // setting pitch to 0 because player is always facing down to place rift
rift1.register(); rift1.register();
} }
// Place a rift at the target point // Place a rift at the target point
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState()); world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos); DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos);
rift2.setDestination(RiftReference.tryMakeRelative(new Location(world, pos), target)); rift2.setDestination(RiftReference.tryMakeRelative(new Location((ServerWorld) world, pos), target));
rift2.setTeleportTargetRotation(player.yaw, 0);
rift2.register(); rift2.register();
stack.damage(1, player, a -> {}); // TODO: calculate damage based on position? stack.damage(1, player, a -> {}); // TODO: calculate damage based on position?
clearSource(stack); 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 // 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; return ActionResult.SUCCESS;
@ -116,8 +113,7 @@ public class RiftSignatureItem extends Item {
public static RotatedLocation getSource(ItemStack itemStack) { public static RotatedLocation getSource(ItemStack itemStack) {
if (itemStack.hasTag() && itemStack.getTag().contains("destination")) { if (itemStack.hasTag() && itemStack.getTag().contains("destination")) {
RotatedLocation transform = RotatedLocation.deserialize(itemStack.getTag().getCompound("destination")); return RotatedLocation.deserialize(itemStack.getTag().getCompound("destination"));
return transform;
} else { } else {
return null; return null;
} }
@ -125,7 +121,7 @@ public class RiftSignatureItem extends Item {
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack itemStack, @Nullable World world, List<Text> list, TooltipContext tooltipContext) { public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
RotatedLocation transform = getSource(itemStack); RotatedLocation transform = getSource(itemStack);
if (transform != null) { if (transform != null) {
list.add(new TranslatableText(getTranslationKey() + ".bound.info", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId())); list.add(new TranslatableText(getTranslationKey() + ".bound.info", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId()));

View file

@ -20,7 +20,7 @@ import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer;
import org.dimdev.dimdoors.sound.ModSoundEvents; import org.dimdev.dimdoors.sound.ModSoundEvents;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class RiftStabilizerItem extends Item { 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 // TODO: not necessarily success, fix this and all other similar cases to make arm swing correct
return new TypedActionResult<>(ActionResult.SUCCESS, stack); return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else { } else {
player.addChatMessage(new TranslatableText("tools.rift_miss"), true); player.sendMessage(new TranslatableText("tools.rift_miss"));
DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor; DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
return new TypedActionResult<>(ActionResult.FAIL, stack); return new TypedActionResult<>(ActionResult.FAIL, stack);
} }
@ -50,12 +50,12 @@ public class RiftStabilizerItem extends Item {
DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos())); DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
if (!rift.stabilized && !rift.closing) { if (!rift.stabilized && !rift.closing) {
rift.setStabilized(true); 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 -> {}); stack.damage(1, player, a -> {});
player.addChatMessage(new TranslatableText(getTranslationKey() + ".stabilized"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".stabilized"));
return new TypedActionResult<>(ActionResult.SUCCESS, stack); return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else { } else {
player.addChatMessage(new TranslatableText(getTranslationKey() + ".already_stabilized"), true); player.sendMessage(new TranslatableText(getTranslationKey() + ".already_stabilized"));
} }
} }
return new TypedActionResult<>(ActionResult.FAIL, stack); return new TypedActionResult<>(ActionResult.FAIL, stack);
@ -63,7 +63,7 @@ public class RiftStabilizerItem extends Item {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@Override @Override
public void appendTooltip(ItemStack itemStack, @Nullable World world, List<Text> list, TooltipContext tooltipContext) { public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
list.add(new TranslatableText(getTranslationKey() + ".info")); list.add(new TranslatableText(getTranslationKey() + ".info"));
} }
} }

View file

@ -7,6 +7,7 @@ import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; 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.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.rift.targets.RiftReference; 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.Location;
import org.dimdev.util.RotatedLocation; import org.dimdev.util.RotatedLocation;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class StabilizedRiftSignatureItem extends Item { // TODO: common superclass with rift signature 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) { if (target == null) {
// The link signature has not been used. Store its current target as the first location. // The link signature has not been used. Store its current target as the first location.
setSource(stack, new RotatedLocation(world, pos, player.yaw, 0)); 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); world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1);
} else { } else {
// Place a rift at the target point // Place a rift at the target point
if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) { if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) {
if (!target.getBlockState().getBlock().canReplace(world.getBlockState(((Location) target).getBlockPos()), itemPlacementContext)) { 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 // Don't clear source, stabilized signatures always stay bound
return ActionResult.FAIL; return ActionResult.FAIL;
} }
World targetWorld = ((Location) target).world; World targetWorld = ((Location) target).world;
targetWorld.setBlockState(((Location) target).getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState()); targetWorld.setBlockState(((Location) target).getBlockPos(), ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity(); DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity();
rift1.setTeleportTargetRotation(target.yaw, 0);
rift1.register(); rift1.register();
} }
// Place a rift at the source point // Place a rift at the source point
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState()); world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos); DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos);
rift2.setDestination(RiftReference.tryMakeRelative(new Location(world, pos), target)); rift2.setDestination(RiftReference.tryMakeRelative(new Location((ServerWorld) world, pos), target));
rift2.setTeleportTargetRotation(player.yaw, 0);
rift2.register(); rift2.register();
stack.damage(1, player, playerEntity -> {}); 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); 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 @Override
public void appendTooltip(ItemStack itemStack, @Nullable World world, List<Text> list, TooltipContext tooltipContext) { public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
RotatedLocation transform = getTarget(itemStack); RotatedLocation transform = getTarget(itemStack);
if (transform != null) { if (transform != null) {

View file

@ -1,27 +1,56 @@
package org.dimdev.dimdoors.item; package org.dimdev.dimdoors.item;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial; import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.ItemStack; import net.minecraft.item.Item;
import net.minecraft.sound.SoundEvents; import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvent;
public class WorldThreadArmorItem extends ArmorItem { public class WorldThreadArmorItem extends ArmorItem {
public static final ArmorMaterial WOVEN_WORLD_THREAD = EnumHelper.addArmorMaterial( public static final ArmorMaterial MATERIAL = new ArmorMaterial() {
"woven_world_thread", @Override
"dimdoors:woven_world_thread", public int getDurability(EquipmentSlot equipmentSlot) {
20, return 20;
new int[]{2, 3, 4, 5}, }
20,
SoundEvents.ITEM_ARMOR_EQUIP_GENERIC,
1.0f)
.setRepairItem(new ItemStack(ModItems.WORLD_THREAD));
public WorldThreadArmorItem(String name, int renderIndex, EquipmentSlot equipmentSlot) { @Override
super(WOVEN_WORLD_THREAD, renderIndex, equipmentSlot); public int getProtectionAmount(EquipmentSlot equipmentSlot) {
setRegistryName("dimdoors", name); return new int[]{2, 3, 4, 5}[equipmentSlot.getEntitySlotId()];
setTranslationKey(name); }
setCreativeTab(ModItemGroups.DIMENSIONAL_DOORS);
@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);
} }
} }

View file

@ -1,46 +1,53 @@
package org.dimdev.dimdoors.pockets; 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.ModConfig;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.rift.registry.LinkProperties; import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.pocketlib.Pocket; import org.dimdev.pocketlib.Pocket;
import org.dimdev.pocketlib.PocketRegistry; import org.dimdev.pocketlib.PocketRegistry;
import org.dimdev.pocketlib.VirtualLocation; import org.dimdev.pocketlib.VirtualLocation;
import org.dimdev.util.WorldUtils;
import java.util.Random; import java.util.Random;
public final class PocketGenerator { 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); LOGGER.info("Generating pocket from template " + pocketTemplate.getId() + " at virtual location " + virtualLocation);
Pocket pocket = PocketRegistry.instance(dim).newPocket(); Pocket pocket = PocketRegistry.instance(world).newPocket();
pocketTemplate.place(pocket, setup); pocketTemplate.place(pocket, setup);
pocket.setVirtualLocation(virtualLocation); pocket.virtualLocation = virtualLocation;
return pocket; return pocket;
} }
public static Pocket generatePocketFromTemplate(int dim, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) { public static Pocket generatePocketFromTemplate(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, boolean setup) {
Pocket pocket = prepareAndPlacePocket(dim, pocketTemplate, virtualLocation, setup); Pocket pocket = prepareAndPlacePocket(world, pocketTemplate, virtualLocation, setup);
if (setup) pocketTemplate.setup(pocket, null, null); if (setup) pocketTemplate.setup(pocket, null, null);
return pocket; return pocket;
} }
public static Pocket generatePocketFromTemplate(int dim, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) { public static Pocket generatePocketFromTemplate(ServerWorld world, PocketTemplate pocketTemplate, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
Pocket pocket = prepareAndPlacePocket(dim, pocketTemplate, virtualLocation, true); Pocket pocket = prepareAndPlacePocket(world, pocketTemplate, virtualLocation, true);
pocketTemplate.setup(pocket, linkTo, linkProperties); pocketTemplate.setup(pocket, linkTo, linkProperties);
return pocket; return pocket;
} }
public static Pocket generatePrivatePocket(VirtualLocation virtualLocation) { public static Pocket generatePrivatePocket(VirtualLocation virtualLocation) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate(); 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 // TODO: size of public pockets should increase with depth
public static Pocket generatePublicPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) { public static Pocket generatePublicPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPublicPocketTemplate(); 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) { public static Pocket generateDungeonPocket(VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
int depth = virtualLocation.depth; 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(); Random random = new Random();
String group = random.nextFloat() < netherProbability ? "nether" : "ruins"; String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, ModConfig.POCKETS.maxPocketSize, false); 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);
} }
} }

View file

@ -1,69 +1,79 @@
package org.dimdev.dimdoors.pockets; 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.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity; import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity; 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.inventory.Inventory;
import net.minecraft.loot.LootTable; import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext; import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextTypes; import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.CoordinateArgument; import net.minecraft.server.world.ServerWorld;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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.LogManager;
import org.apache.logging.log4j.Logger; 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.ModBlockEntityTypes;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.entity.ModEntityTypes; 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.Location;
import org.dimdev.util.math.MathUtil; import org.dimdev.util.math.MathUtil;
import org.dimdev.util.schem.Schematic; 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 * @author Robijnvogel
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class PocketTemplate { public class PocketTemplate {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@Getter private final String group; private final String group;
@Getter private final String id; private final String id;
@Getter private final String type; private final String type;
@Getter private final String name; private final String name;
@Getter private final String author; private final String author;
@Getter @Setter private Schematic schematic; private Schematic schematic;
@Setter private byte[] schematicBytecode; private byte[] schematicBytecode;
@Getter private int size; // number of chunks (16 blocks) on each side - 1 private int size; // number of chunks (16 blocks) on each side - 1
@Getter private int baseWeight; private int baseWeight;
@Getter private static boolean isReplacingPlaceholders = false; 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) { public float getWeight(int depth) {
//noinspection IfStatementWithIdenticalBranches
if (depth == -1) { if (depth == -1) {
return baseWeight; return baseWeight;
} else { } else {
@ -102,7 +112,6 @@ public class PocketTemplate {
rift.setPos(new BlockPos(x, y, z)); rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties); rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
rift.setDestination(DefaultDungeonDestinations.overworldDestination); rift.setDestination(DefaultDungeonDestinations.overworldDestination);
rift.setLeaveRiftOnBreak(true);
newNBT = rift.toTag(newNBT); newNBT = rift.toTag(newNBT);
break; break;
case "entrance_door": case "entrance_door":
@ -131,7 +140,7 @@ public class PocketTemplate {
List<CompoundTag> entities = new ArrayList<>(); List<CompoundTag> entities = new ArrayList<>();
for (CompoundTag entitiesNBT : schematic.entities) { for (CompoundTag entitiesNBT : schematic.entities) {
if (entitiesNBT.hasKey("placeholder")) { if (entitiesNBT.contains("placeholder")) {
double x = entitiesNBT.getDouble("x"); double x = entitiesNBT.getDouble("x");
double y = entitiesNBT.getDouble("y"); double y = entitiesNBT.getDouble("y");
double z = entitiesNBT.getDouble("z"); double z = entitiesNBT.getDouble("z");
@ -141,8 +150,10 @@ public class PocketTemplate {
CompoundTag newNBT; CompoundTag newNBT;
if ("monolith".equals(entitiesNBT.getString("placeholder"))) { if ("monolith".equals(entitiesNBT.getString("placeholder"))) {
MonolithEntity monolith = ModEntityTypes.MONOLITH.create(null); MonolithEntity monolith = ModEntityTypes.MONOLITH.create(null);
monolith.setPositionAndAngles(x, y, z, yaw, pitch); monolith.setPos(x, y, z);
newNBT = monolith.serializeNBT(); monolith.yaw = yaw;
monolith.pitch = pitch;
newNBT = monolith.toTag(new CompoundTag());
} else { } else {
throw new RuntimeException("Unknown entity placeholder: " + entitiesNBT.getString("placeholder")); throw new RuntimeException("Unknown entity placeholder: " + entitiesNBT.getString("placeholder"));
} }
@ -201,7 +212,7 @@ public class PocketTemplate {
if (tile instanceof RiftBlockEntity) { if (tile instanceof RiftBlockEntity) {
LOGGER.debug("Rift found in schematic at " + pos); LOGGER.debug("Rift found in schematic at " + pos);
RiftBlockEntity rift = (RiftBlockEntity) tile; 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); rifts.add(rift);
} else if (tile instanceof Inventory) { } else if (tile instanceof Inventory) {
Inventory inventory = (Inventory) tile; Inventory inventory = (Inventory) tile;
@ -250,7 +261,7 @@ public class PocketTemplate {
PocketRegistry.instance(world).markDirty(); PocketRegistry.instance(world).markDirty();
rift.setDestination(((PocketEntranceMarker) dest).getIfDestination()); rift.setDestination(((PocketEntranceMarker) dest).getIfDestination());
rift.register(); rift.register();
RiftRegistry.instance().addPocketEntrance(pocket, new Location(rift.getWorld(), rift.getPos())); RiftRegistry.instance().addPocketEntrance(pocket, new Location((ServerWorld) rift.getWorld(), rift.getPos()));
} else { } else {
rift.setDestination(((PocketEntranceMarker) dest).getOtherwiseDestination()); rift.setDestination(((PocketEntranceMarker) dest).getOtherwiseDestination());
} }
@ -263,9 +274,6 @@ public class PocketTemplate {
if (dest instanceof PocketExitMarker) { if (dest instanceof PocketExitMarker) {
if (linkProperties != null) rift.setProperties(linkProperties); if (linkProperties != null) rift.setProperties(linkProperties);
rift.setDestination(rift.getProperties() == null || !rift.getProperties().oneWay ? linkTo : null); 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
}
} }
} }
@ -280,4 +288,24 @@ public class PocketTemplate {
schematic = null; 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; }
} }

View file

@ -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 name = pocket.has("name") ? pocket.get("name").getAsString() : null;
String author = pocket.has("author") ? pocket.get("author").getAsString() : null; String author = pocket.has("author") ? pocket.get("author").getAsString() : null;
int baseWeight = pocket.has("baseWeight") ? pocket.get("baseWeight").getAsInt() : 100; 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()); return pocketTemplates.stream().sorted(Comparator.comparing(PocketTemplate::getId)).collect(Collectors.toList());

View file

@ -27,12 +27,6 @@ public class LinkProperties {
public static LinkPropertiesBuilder builder() {return new LinkPropertiesBuilder();} 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) { public boolean equals(final Object o) {
if (o == this) return true; if (o == this) return true;
if (!(o instanceof LinkProperties)) return false; if (!(o instanceof LinkProperties)) return false;

View file

@ -1,14 +1,15 @@
package org.dimdev.dimdoors.rift.registry; package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.World;
import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.Saved;
import org.dimdev.annotatednbt.AnnotatedNbt; import org.dimdev.annotatednbt.AnnotatedNbt;
public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass? public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass?
@Saved public int pocketDim; @Saved public World pocketDim;
@Saved public int pocketId; @Saved public int pocketId;
public PocketEntrancePointer(int pocketDim, int pocketId) { public PocketEntrancePointer(World pocketDim, int pocketId) {
this.pocketDim = pocketDim; this.pocketDim = pocketDim;
this.pocketId = pocketId; this.pocketId = pocketId;
} }

View file

@ -1,41 +1,32 @@
package org.dimdev.dimdoors.rift.registry; package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.annotatednbt.AnnotatedNbt; import org.dimdev.annotatednbt.AnnotatedNbt;
import java.util.UUID; import java.util.UUID;
public abstract class RegistryVertex { 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. @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) { public void sourceGone(RegistryVertex source) {
LOGGER.debug("Notified vertex " + this + " that source " + source + " is gone");
RiftRegistry.instance().markSubregistryDirty(dim);
} }
public void targetGone(RegistryVertex target) { public void targetGone(RegistryVertex target) {
LOGGER.debug("Notified vertex " + this + " that target " + target + " is gone");
RiftRegistry.instance().markSubregistryDirty(dim);
} }
public void sourceAdded(RegistryVertex source) { public void sourceAdded(RegistryVertex source) {
LOGGER.debug("Notified vertex " + this + " that source " + source + " was added");
RiftRegistry.instance().markSubregistryDirty(dim);
} }
public void targetAdded(RegistryVertex target) { 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); } public void fromTag(CompoundTag nbt) { AnnotatedNbt.fromTag(this, nbt); }
@Override
public CompoundTag toTag(CompoundTag nbt) { return AnnotatedNbt.toTag(this, nbt); } 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 + ")";}
} }

View file

@ -50,8 +50,7 @@ public class Rift extends RegistryVertex {
((RiftBlockEntity) location.getBlockEntity()).updateColor(); ((RiftBlockEntity) location.getBlockEntity()).updateColor();
} }
public void markDirty() { // TODO: better name public void markDirty() {
RiftRegistry.instance().markSubregistryDirty(dim);
((RiftBlockEntity) location.getBlockEntity()).updateColor(); ((RiftBlockEntity) location.getBlockEntity()).updateColor();
for (Location location : RiftRegistry.instance().getSources(location)) { for (Location location : RiftRegistry.instance().getSources(location)) {
RiftRegistry.instance().getRift(location).targetChanged(this); RiftRegistry.instance().getRift(location).targetChanged(this);

View file

@ -3,7 +3,6 @@ package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimDoors;
public class RiftPlaceholder extends Rift { // TODO: don't extend rift public class RiftPlaceholder extends Rift { // TODO: don't extend rift
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@ -25,7 +24,7 @@ public class RiftPlaceholder extends Rift { // TODO: don't extend rift
@Override @Override
public void markDirty() { public void markDirty() {
RiftRegistry.instance().markSubregistryDirty(dim); RiftRegistry.instance().markSubregistryDirty(world);
} }
@Override @Override

View file

@ -3,9 +3,9 @@ package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.world.PersistentState; import net.minecraft.world.PersistentState;
import net.minecraft.world.storage.MapStorage; import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.common.DimensionManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dimdev.pocketlib.Pocket; import org.dimdev.pocketlib.Pocket;
@ -22,119 +22,17 @@ import java.util.stream.Collectors;
public class RiftRegistry extends PersistentState { public class RiftRegistry extends PersistentState {
private static final Logger LOGGER = LogManager.getLogger(); 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<Integer, RiftSubregistry> subregistries = new HashMap<>();
private static RiftRegistry riftRegistry = null; // For use by RiftSubregistry only
private static int currentDim; // For use by RiftSubregistry only
protected DefaultDirectedGraph<RegistryVertex, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); protected DefaultDirectedGraph<RegistryVertex, DefaultEdge> 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<Location, Rift> locationMap = new HashMap<>(); protected Map<Location, Rift> locationMap = new HashMap<>();
protected Map<Pocket, PocketEntrancePointer> pocketEntranceMap = new HashMap<>(); protected Map<Pocket, PocketEntrancePointer> pocketEntranceMap = new HashMap<>();
protected Map<UUID, RegistryVertex> uuidMap = new HashMap<>(); protected Map<UUID, RegistryVertex> uuidMap = new HashMap<>();
// These are stored in the main registry
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket protected Map<UUID, PlayerRiftPointer> lastPrivatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld
// <editor-fold defaultstate="collapsed" desc="Code for reading/writing/getting the registry">
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() { public RiftRegistry() {
super(DATA_NAME); super(DATA_NAME);
} }
@ -144,47 +42,78 @@ public class RiftRegistry extends PersistentState {
} }
public static RiftRegistry instance() { public static RiftRegistry instance() {
MapStorage storage = WorldUtils.getWorld(0).getMapStorage(); return WorldUtils.getWorld(DimensionType.OVERWORLD).getPersistentStateManager().get(RiftRegistry::new, DATA_NAME);
RiftRegistry instance = (RiftRegistry) storage.getOrLoadData(RiftRegistry.class, DATA_NAME);
if (instance == null) {
instance = new RiftRegistry();
storage.setData(DATA_NAME, instance);
}
return instance;
} }
@Override @Override
public void fromTag(CompoundTag nbt) { 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 ListTag riftsNBT = (ListTag) nbt.get("rifts");
// them to be read from somewhere else, since this is technically more than just reading the NBT and can cause for (Tag riftNBT : riftsNBT) {
// problems with recursion without riftRegistry. This has to be done first since links are only Rift rift = new Rift();
// in the subregistries. rift.fromTag((CompoundTag) riftNBT);
// TODO: If non-dirty but new WorldSavedDatas aren't automatically saved, then create the subregistries here graph.addVertex(rift);
// TODO: rather then in the markSubregistryDirty method. uuidMap.put(rift.id, rift);
// TODO: try to get rid of this code: locationMap.put(rift.location, rift);
riftRegistry = this; }
for (int dim : DimensionManager.getStaticDimensionIDs()) {
MapStorage storage = WorldUtils.getWorld(dim).getPerWorldStorage(); ListTag pocketsNBT = (ListTag) nbt.get("pockets");
currentDim = dim; for (Tag pocketNBT : pocketsNBT) {
RiftSubregistry instance = (RiftSubregistry) storage.getOrLoadData(RiftSubregistry.class, SUBREGISTRY_DATA_NAME); PocketEntrancePointer pocket = new PocketEntrancePointer();
if (instance != null) { pocket.fromTag((CompoundTag) pocketNBT);
instance.dim = dim; graph.addVertex(pocket);
subregistries.put(dim, instance); 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.get("lastPrivatePocketEntrances"));
lastPrivatePocketEntrances = readPlayerRiftPointers((ListTag) nbt.getTag("lastPrivatePocketEntrances")); lastPrivatePocketExits = readPlayerRiftPointers((ListTag) nbt.get("lastPrivatePocketExits"));
lastPrivatePocketExits = readPlayerRiftPointers((ListTag) nbt.getTag("lastPrivatePocketExits")); overworldRifts = readPlayerRiftPointers((ListTag) nbt.get("overworldRifts"));
overworldRifts = readPlayerRiftPointers((ListTag) nbt.getTag("overworldRifts"));
} }
@Override @Override
public CompoundTag toTag(CompoundTag tag) { 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. // Subregistries are written automatically when the worlds are saved.
tag.put("lastPrivatePocketEntrances", writePlayerRiftPointers(lastPrivatePocketEntrances)); tag.put("lastPrivatePocketEntrances", writePlayerRiftPointers(lastPrivatePocketEntrances));
tag.put("lastPrivatePocketExits", writePlayerRiftPointers(lastPrivatePocketExits)); tag.put("lastPrivatePocketExits", writePlayerRiftPointers(lastPrivatePocketExits));
@ -195,8 +124,8 @@ public class RiftRegistry extends PersistentState {
private Map<UUID, PlayerRiftPointer> readPlayerRiftPointers(ListTag tag) { private Map<UUID, PlayerRiftPointer> readPlayerRiftPointers(ListTag tag) {
Map<UUID, PlayerRiftPointer> pointerMap = new HashMap<>(); Map<UUID, PlayerRiftPointer> pointerMap = new HashMap<>();
for (Tag entryNBT : tag) { for (Tag entryNBT : tag) {
UUID player = ((CompoundTag) entryNBT).getUuid("player"); UUID player = ((CompoundTag) entryNBT).getUuidNew("player");
UUID rift = ((CompoundTag) entryNBT).getUuid("rift"); UUID rift = ((CompoundTag) entryNBT).getUuidNew("rift");
PlayerRiftPointer pointer = new PlayerRiftPointer(player); PlayerRiftPointer pointer = new PlayerRiftPointer(player);
pointerMap.put(player, pointer); pointerMap.put(player, pointer);
uuidMap.put(pointer.id, pointer); uuidMap.put(pointer.id, pointer);
@ -210,10 +139,10 @@ public class RiftRegistry extends PersistentState {
ListTag pointers = new ListTag(); ListTag pointers = new ListTag();
for (Map.Entry<UUID, PlayerRiftPointer> entry : playerRiftPointerMap.entrySet()) { for (Map.Entry<UUID, PlayerRiftPointer> entry : playerRiftPointerMap.entrySet()) {
CompoundTag entryNBT = new CompoundTag(); CompoundTag entryNBT = new CompoundTag();
entryNBT.putUuid("player", entry.getKey()); entryNBT.putUuidNew("player", entry.getKey());
int count = 0; int count = 0;
for (DefaultEdge edge : graph.outgoingEdgesOf(entry.getValue())) { for (DefaultEdge edge : graph.outgoingEdgesOf(entry.getValue())) {
entryNBT.putUuid("rift", graph.getEdgeTarget(edge).id); entryNBT.putUuidNew("rift", graph.getEdgeTarget(edge).id);
count++; count++;
} }
if (count != 1) throw new RuntimeException("PlayerRiftPointer points to more than one rift"); if (count != 1) throw new RuntimeException("PlayerRiftPointer points to more than one rift");
@ -222,23 +151,6 @@ public class RiftRegistry extends PersistentState {
return pointers; 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);
}
}
// </editor-fold>
public boolean isRiftAt(Location location) { public boolean isRiftAt(Location location) {
Rift possibleRift = locationMap.get(location); Rift possibleRift = locationMap.get(location);
return possibleRift != null && !(possibleRift instanceof RiftPlaceholder); return possibleRift != null && !(possibleRift instanceof RiftPlaceholder);
@ -255,12 +167,11 @@ public class RiftRegistry extends PersistentState {
if (rift == null) { if (rift == null) {
LOGGER.debug("Creating a rift placeholder at " + location); LOGGER.debug("Creating a rift placeholder at " + location);
rift = new RiftPlaceholder(); rift = new RiftPlaceholder();
rift.dim = location.getDim(); rift.world = location.world;
rift.location = location; rift.location = location;
locationMap.put(location, rift); locationMap.put(location, rift);
uuidMap.put(rift.id, rift); uuidMap.put(rift.id, rift);
graph.addVertex(rift); graph.addVertex(rift);
markSubregistryDirty(rift.dim);
} }
return rift; return rift;
} }
@ -272,12 +183,12 @@ public class RiftRegistry extends PersistentState {
if (currentRift instanceof RiftPlaceholder) { if (currentRift instanceof RiftPlaceholder) {
LOGGER.info("Converting a rift placeholder at " + location + " into a rift"); LOGGER.info("Converting a rift placeholder at " + location + " into a rift");
rift = new Rift(location); rift = new Rift(location);
rift.dim = location.getDim(); rift.world = location.world;
rift.id = currentRift.id; rift.id = currentRift.id;
GraphUtils.replaceVertex(graph, currentRift, rift); GraphUtils.replaceVertex(graph, currentRift, rift);
} else if (currentRift == null) { } else if (currentRift == null) {
rift = new Rift(location); rift = new Rift(location);
rift.dim = location.getDim(); rift.world = location.world;
graph.addVertex(rift); graph.addVertex(rift);
} else { } else {
throw new IllegalArgumentException("There is already a rift registered at " + location); throw new IllegalArgumentException("There is already a rift registered at " + location);
@ -298,7 +209,6 @@ public class RiftRegistry extends PersistentState {
graph.removeVertex(rift); graph.removeVertex(rift);
locationMap.remove(location); locationMap.remove(location);
uuidMap.remove(rift.id); uuidMap.remove(rift.id);
markSubregistryDirty(rift.dim);
// Notify the adjacent vertices of the change // Notify the adjacent vertices of the change
for (DefaultEdge edge : incomingEdges) graph.getEdgeSource(edge).targetGone(rift); for (DefaultEdge edge : incomingEdges) graph.getEdgeSource(edge).targetGone(rift);
@ -311,24 +221,18 @@ public class RiftRegistry extends PersistentState {
markDirty(); markDirty();
} else if (from instanceof Rift) { } else if (from instanceof Rift) {
((Rift) from).markDirty(); ((Rift) from).markDirty();
} else {
markSubregistryDirty(from.dim);
} }
if (to instanceof Rift) { if (to instanceof Rift) {
((Rift) to).markDirty(); ((Rift) to).markDirty();
} else {
markSubregistryDirty(to.dim);
} }
} }
private void removeEdge(RegistryVertex from, RegistryVertex to) { private void removeEdge(RegistryVertex from, RegistryVertex to) {
graph.removeEdge(from, to); graph.removeEdge(from, to);
if (from instanceof PlayerRiftPointer) { if (from instanceof PlayerRiftPointer) {
markDirty(); markDirty();
} else {
markSubregistryDirty(from.dim);
} }
markSubregistryDirty(to.dim);
} }
public void addLink(Location locationFrom, Location locationTo) { public void addLink(Location locationFrom, Location locationTo) {
@ -388,7 +292,7 @@ public class RiftRegistry extends PersistentState {
PocketEntrancePointer pointer = pocketEntranceMap.get(pocket); PocketEntrancePointer pointer = pocketEntranceMap.get(pocket);
if (pointer == null) { if (pointer == null) {
pointer = new PocketEntrancePointer(pocket.world, pocket.id); pointer = new PocketEntrancePointer(pocket.world, pocket.id);
pointer.dim = pocket.world; pointer.world = pocket.world;
graph.addVertex(pointer); graph.addVertex(pointer);
pocketEntranceMap.put(pocket, pointer); pocketEntranceMap.put(pocket, pointer);
uuidMap.put(pointer.id, pointer); uuidMap.put(pointer.id, pointer);

View file

@ -2,6 +2,7 @@ package org.dimdev.dimdoors.rift.targets;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity; import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.RiftRegistry; import org.dimdev.dimdoors.rift.registry.RiftRegistry;
@ -46,7 +47,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
if (uuid != null) { if (uuid != null) {
Location destLoc = RiftRegistry.instance().getOverworldRift(uuid); Location destLoc = RiftRegistry.instance().getOverworldRift(uuid);
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || canEscapeLimbo) { 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; return true;
} else { } else {
if (destLoc == null) { if (destLoc == null) {

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.rift.targets;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag; 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.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.RiftRegistry; import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.world.limbo.LimboDimension; 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 || !(destLoc.getBlockEntity() instanceof RiftBlockEntity)) {
if (destLoc == null) { 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 { } 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)); TeleportUtil.teleport(entity, LimboDimension.getLimboSkySpawn(entity));
return false; return false;

View file

@ -2,6 +2,7 @@ package org.dimdev.dimdoors.rift.targets;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -137,14 +138,14 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
depth /= depth > 0 ? positiveDepthFactor : negativeDepthFactor; depth /= depth > 0 ? positiveDepthFactor : negativeDepthFactor;
double x = Math.cos(theta) * Math.cos(phi) * distance / coordFactor; double x = Math.cos(theta) * Math.cos(phi) * distance / coordFactor;
double z = Math.cos(theta) * Math.sin(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.x + (int) Math.round(x),
virtualLocationHere.z + (int) Math.round(z), virtualLocationHere.z + (int) Math.round(z),
virtualLocationHere.depth + (int) Math.round(depth)); virtualLocationHere.depth + (int) Math.round(depth));
if (virtualLocation.depth <= 0) { if (virtualLocation.depth <= 0) {
// This will lead to the overworld // 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)); BlockPos pos = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, new BlockPos(virtualLocation.x, 0, virtualLocation.z));
if (pos.getY() == -1) { if (pos.getY() == -1) {
// No blocks at that XZ (hole in bedrock) // 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 // TODO: Should the rift not be configured like the other link
riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build()); riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build());
if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(new Location(world, pos), location); if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(new Location((ServerWorld) world, pos), location);
if (!noLink) linkRifts(location, new Location(world, pos)); if (!noLink) linkRifts(location, new Location((ServerWorld) world, pos));
return riftEntity.as(Targets.ENTITY); return riftEntity.as(Targets.ENTITY);
} else { } else {
// Make a new dungeon pocket // Make a new dungeon pocket

View file

@ -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);
// }
// }
//}

View file

@ -1,16 +1,15 @@
package org.dimdev.dimdoors.world; 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.util.Identifier;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 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 final class ModBiomes {
public static final LimboBiome LIMBO = new LimboBiome();
public static final BiomeLimbo LIMBO = new BiomeLimbo();
public static final BlankBiome WHITE_VOID = new BlankBiome(true, false); public static final BlankBiome WHITE_VOID = new BlankBiome(true, false);
public static final BlankBiome BLACK_VOID = new BlankBiome(false, false); public static final BlankBiome BLACK_VOID = new BlankBiome(false, false);
public static final BlankBiome DANGEROUS_BLACK_VOID = new BlankBiome(false, true); public static final BlankBiome DANGEROUS_BLACK_VOID = new BlankBiome(false, true);

View file

@ -20,4 +20,8 @@ public final class ModDimensions {
|| world.dimension instanceof PersonalPocketDimension || world.dimension instanceof PersonalPocketDimension
|| world.dimension instanceof DungeonPocketDimension; || world.dimension instanceof DungeonPocketDimension;
} }
public static void init() {
// just loads the class
}
} }

View file

@ -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) { }
//}

View file

@ -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);
// }
//}

View file

@ -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<StructureNetherBridgePieces.Throne> 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<StructureNetherBridgePieces.Throne>();
// 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);
// }
// }
//}

View file

@ -1,144 +1,142 @@
package org.dimdev.dimdoors.world.gateways; //package org.dimdev.dimdoors.world.gateways;
//
import net.minecraft.block.material.Material; //import net.minecraft.block.Blocks;
import net.minecraft.init.Blocks; //import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos; //import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; //import net.minecraft.world.Heightmap;
import net.minecraft.world.WorldProviderEnd; //import net.minecraft.world.World;
import net.minecraft.world.WorldProviderHell; //import net.minecraft.world.WorldProviderEnd;
import net.minecraft.world.chunk.ChunkProvider; //import net.minecraft.world.chunk.ChunkProvider;
import net.minecraft.world.chunk.IChunkProvider; //import net.minecraft.world.dimension.TheNetherDimension;
import net.minecraft.world.dimension.TheNetherDimension; //import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.IChunkGenerator; //import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraft.world.gen.chunk.ChunkGenerator; //import org.dimdev.dimdoors.ModConfig;
import net.minecraftforge.fml.common.IWorldGenerator; //import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.ModConfig; //import org.dimdev.pocketlib.PocketWorldDimension;
import org.dimdev.dimdoors.block.ModBlocks; //
import org.dimdev.pocketlib.PocketWorldDimension; //import java.util.ArrayList;
//import java.util.Arrays;
import java.util.ArrayList; //import java.util.Random;
import java.util.Arrays; //
import java.util.Random; //public class GatewayGenerator implements IWorldGenerator {
// private static final int CLUSTER_GROWTH_CHANCE = 80;
public class GatewayGenerator implements IWorldGenerator { // private static final int MAX_CLUSTER_GROWTH_CHANCE = 100;
private static final int CLUSTER_GROWTH_CHANCE = 80; // private static final int MIN_RIFT_Y = 4;
private static final int MAX_CLUSTER_GROWTH_CHANCE = 100; // private static final int MAX_RIFT_Y = 240;
private static final int MIN_RIFT_Y = 4; // private static final int CHUNK_LENGTH = 16;
private static final int MAX_RIFT_Y = 240; // private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10;
private static final int CHUNK_LENGTH = 16; //
private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10; // private ArrayList<BaseGateway> gateways;
// private BaseGateway defaultGateway;
private ArrayList<BaseGateway> gateways; //
private BaseGateway defaultGateway; // public GatewayGenerator() {
// gateways = new ArrayList<>();
public GatewayGenerator() { // defaultGateway = new GatewayTwoPillars();
gateways = new ArrayList<>(); //
defaultGateway = new GatewayTwoPillars(); // // Add gateways here
// gateways.add(new GatewaySandstonePillars());
// Add gateways here // gateways.add(new LimboGateway());
gateways.add(new GatewaySandstonePillars()); // }
gateways.add(new LimboGateway()); //
} // @Override
// public void generate(Random random, int chunkX, int chunkZ, World world, ChunkGenerator chunkGenerator, ChunkProvider chunkProvider) {
@Override // // Don't generate rifts or gateways if the current world is a pocket dimension or the world is remote.
public void generate(Random random, int chunkX, int chunkZ, World world, ChunkGenerator chunkGenerator, ChunkProvider chunkProvider) { // // Also don't generate anything in the Nether or The End.
// Don't generate rifts or gateways if the current world is a pocket dimension or the world is remote. // if (world.isClient || world.dimension instanceof PocketWorldDimension || world.dimension instanceof TheNetherDimension || world.dimension instanceof WorldProviderEnd) {
// Also don't generate anything in the Nether or The End. // return;
if (world.isClient || world.dimension instanceof PocketWorldDimension || world.dimension instanceof TheNetherDimension || world.dimension instanceof WorldProviderEnd) { // }
return; //
} // int x, y, z;
// int attempts;
int x, y, z; // boolean valid;
int attempts; //
boolean valid; // // Check if we're allowed to generate rift clusters in this dimension.
// // If so, randomly decide whether to one.
// Check if we're allowed to generate rift clusters in this dimension. // boolean clusterGenerated = false;
// If so, randomly decide whether to one. // if (!ModConfig.WORLD.clusterDimBlacklist.contains(world.dimension.getType().getSuffix())) {
boolean clusterGenerated = false; // double clusterGenChance = ModConfig.WORLD.clusterGenChance;
if (Arrays.binarySearch(ModConfig.WORLD.clusterDimBlacklist, world.dimension.getDimensionType().getId()) == -1) { // while (clusterGenChance > 0.0) {
double clusterGenChance = ModConfig.WORLD.clusterGenChance; // if (random.nextDouble() < clusterGenChance) {
while (clusterGenChance > 0.0) { // do {
if (random.nextDouble() < clusterGenChance) { // //Pick a random point on the surface of the chunk
do { // x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH);
//Pick a random point on the surface of the chunk // z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH);
x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); // y = world.getHeight(x, z);
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 the point is within the acceptable altitude range, the block above is empty, and we're // if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(new BlockPos(x, y + 1, z))
//not building on bedrock, then generate a rift there // && world.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.BEDROCK
if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(new BlockPos(x, y + 1, z)) // && //<-- Stops Nether roof spawning. DO NOT REMOVE!
&& world.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.BEDROCK // world.getBlockState(new BlockPos(x, y - 1, z)).getBlock() != Blocks.BEDROCK
&& //<-- Stops Nether roof spawning. DO NOT REMOVE! // && world.getBlockState(new BlockPos(x, y - 2, z)).getBlock() != Blocks.BEDROCK) {
world.getBlockState(new BlockPos(x, y - 1, 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.getBlockState(new BlockPos(x, y - 2, z)).getBlock() != Blocks.BEDROCK) { // world.setBlockState(new BlockPos(x, y, z), ModBlocks.DETACHED_RIFT.getDefaultState());
//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);
} //Randomly decide whether to repeat the process and add another rift to the cluster // clusterGenerated = true;
while (random.nextInt(MAX_CLUSTER_GROWTH_CHANCE) < CLUSTER_GROWTH_CHANCE); // }
clusterGenerated = true; // clusterGenChance -= 1.0;
} // }
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.
// Check if we can place a Rift Gateway in this dimension, then randomly decide whether to place one. // if (!clusterGenerated && Arrays.binarySearch(ModConfig.WORLD.gatewayDimBlacklist, world.dimension.getDimensionType().getId()) == -1) {
// This only happens if a rift cluster was NOT generated. // double gatewayGenChance = ModConfig.WORLD.gatewayGenChance;
if (!clusterGenerated && Arrays.binarySearch(ModConfig.WORLD.gatewayDimBlacklist, world.dimension.getDimensionType().getId()) == -1) { // while (gatewayGenChance > 0.0) {
double gatewayGenChance = ModConfig.WORLD.gatewayGenChance; // if (random.nextDouble() < gatewayGenChance) {
while (gatewayGenChance > 0.0) { // valid = false;
if (random.nextDouble() < gatewayGenChance) { // x = y = z = 0; //Stop the compiler from freaking out
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++) {
//Check locations for the gateway until we are satisfied or run out of attempts. // //Pick a random point on the surface of the chunk and check its materials
for (attempts = 0; attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && !valid; attempts++) { // x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH);
//Pick a random point on the surface of the chunk and check its materials // z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH);
x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); // y = world.getTopY(Heightmap.Type.WORLD_SURFACE, x, z);
z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); // valid = checkGatewayLocation(world, new BlockPos(x, y, z));
y = world.getHeight(x, z); // }
valid = checkGatewayLocation(world, new BlockPos(x, y, z)); //
} // // Build the gateway if we found a valid location
// if (valid) {
// Build the gateway if we found a valid location // ArrayList<BaseGateway> validGateways = new ArrayList<>();
if (valid) { // for (BaseGateway gateway : gateways) {
ArrayList<BaseGateway> validGateways = new ArrayList<>(); // if (gateway.isLocationValid(world, x, y, z)) {
for (BaseGateway gateway : gateways) { // validGateways.add(gateway);
if (gateway.isLocationValid(world, x, y, z)) { // }
validGateways.add(gateway); // }
} // // Add the default gateway if the rest were rejected
} // if (validGateways.isEmpty()) {
// Add the default gateway if the rest were rejected // validGateways.add(defaultGateway);
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);
// 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;
} // }
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,
private static boolean checkGatewayLocation(World world, BlockPos pos) { // //and the block two levels down is opaque and has a reasonable material. Plus that we're not building
//Check if the point is within the acceptable altitude range, the block above that point is empty, // //on top of bedrock.
//and the block two levels down is opaque and has a reasonable material. Plus that we're not building // return pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y
//on top of bedrock. // && world.isAir(pos.up())
return pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y // && world.getBlockState(pos).getBlock() != Blocks.BEDROCK
&& world.isAirBlock(pos.up()) // && world.getBlockState(pos.down()).getBlock() != Blocks.BEDROCK //<-- Stops Nether roof spawning. DO NOT REMOVE!
&& world.getBlockState(pos).getBlock() != Blocks.BEDROCK // && checkFoundationMaterial(world, pos.down());
&& 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,
private static boolean checkFoundationMaterial(World world, BlockPos pos) { // //or on top of strange things like tall grass, water, slabs, or torches.
//We check the material and opacity to prevent generating gateways on top of trees or houses, // //We also want to avoid generating things on top of the Nether's bedrock!
//or on top of strange things like tall grass, water, slabs, or torches. // Material material = world.getBlockState(pos).getMaterial();
//We also want to avoid generating things on top of the Nether's bedrock! // return material != Material.LEAVES && material != Material.WOOD && material != Material.PUMPKIN
Material material = world.getBlockState(pos).getMaterial(); // && world.getBlockState(pos).isFullCube(world, pos) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK;
return material != Material.LEAVES && material != Material.WOOD && material != Material.GOURD // }
&& world.isBlockNormalCube(pos, false) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK; //}
}
}

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.world.gateways; package org.dimdev.dimdoors.world.gateways;
import net.minecraft.init.Biomes;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
public class GatewaySandstonePillars extends BaseSchematicGateway { public class GatewaySandstonePillars extends BaseSchematicGateway {
public GatewaySandstonePillars() { public GatewaySandstonePillars() {
@ -10,6 +10,6 @@ public class GatewaySandstonePillars extends BaseSchematicGateway {
@Override @Override
public Biome[] getBiomes() { 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};
} }
} }

View file

@ -1,7 +1,6 @@
package org.dimdev.dimdoors.world.gateways; package org.dimdev.dimdoors.world.gateways;
import net.minecraft.block.BlockStoneBrick; import net.minecraft.block.Blocks;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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()) { 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 //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. //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 //Place Stone Bricks
world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONEBRICK.getDefaultState()); world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONE_BRICKS.getDefaultState());
} else if (Math.abs(xc) + Math.abs(zc) < world.rand.nextInt(3) + 3) { } else if (Math.abs(xc) + Math.abs(zc) < world.random.nextInt(3) + 3) {
//Place Cracked Stone Bricks //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());
} }
} }
} }

View file

@ -1,15 +1,17 @@
package org.dimdev.dimdoors.world.limbo; 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.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.ChunkPrimer; import net.minecraft.world.chunk.ChunkPrimer;
import org.dimdev.dimdoors.entity.MonolithEntity;
import java.util.Random; import java.util.Random;
public class BiomeLimbo extends Biome { public class LimboBiome extends Biome {
public LimboBiome() {
public BiomeLimbo() {
super(new Biome.BiomeProperties("Limbo") super(new Biome.BiomeProperties("Limbo")
.setRainDisabled() .setRainDisabled()
.setRainfall(0) .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. // 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 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 // TODO: check that black/white grass and foliage in getModdedBiomeGrassColor is compatible with other mods such as Quark's greener grass option
@Override @Override

View file

@ -1,18 +1,35 @@
package org.dimdev.dimdoors.world.limbo; package org.dimdev.dimdoors.world.limbo;
import net.minecraft.util.math.noise.OctavePerlinNoiseSampler; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.chunk.SurfaceChunkGenerator; import net.minecraft.world.gen.chunk.SurfaceChunkGenerator;
import java.util.Random; public class LimboChunkGenerator extends SurfaceChunkGenerator<LimboChunkGeneratorConfig> {
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<LimboChunkGeneratorConfig> { @Override
private final double[] noiseFalloff = this.buildNoiseFalloff(); protected double[] computeNoiseRange(int i, int j) {
private double[] buildNoiseFalloff() {
return new double[0]; 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 // @Override
// public int getHeightOnGround(int x, int z, Heightmap.Type type) { // public int getHeightOnGround(int x, int z, Heightmap.Type type) {
@ -97,42 +114,42 @@ public class LimboChunkGenerator implements SurfaceChunkGenerator<LimboChunkGene
// //
private Random rand; // private Random rand;
// //
// // Noise generators // // Noise generators
private OctavePerlinNoiseSampler minLimitPerlinNoise; // private OctavePerlinNoiseSampler minLimitPerlinNoise;
private OctavePerlinNoiseSampler maxLimitPerlinNoise; // private OctavePerlinNoiseSampler maxLimitPerlinNoise;
private OctavePerlinNoiseSampler mainPerlinNoise; // private OctavePerlinNoiseSampler mainPerlinNoise;
public OctavePerlinNoiseSampler depthNoise; // public OctavePerlinNoiseSampler depthNoise;
// double[] mainNoiseRegion;
// double[] minLimitRegion;
// double[] maxLimitRegion;
// //
double[] mainNoiseRegion; // private World world;
double[] minLimitRegion; // private double[] heightMap;
double[] maxLimitRegion; //
// double[] depthRegion;
private World world; //
private double[] heightMap; // @Override
// protected double[] computeNoiseRange(int i, int j) {
double[] depthRegion; // return new double[]{0, 0};
// }
@Override //
protected double[] computeNoiseRange(int i, int j) { // @Override
return new double[]{0, 0}; // protected double computeNoiseFalloff(double d, double e, int i) {
} // return 0;
// }
@Override //
protected double computeNoiseFalloff(double d, double e, int i) { // @Override
return 0; // protected void sampleNoiseColumn(double[] ds, int i, int j) {
} //
// }
@Override //
protected void sampleNoiseColumn(double[] ds, int i, int j) { // @Override
// public int getSpawnHeight() {
} // return 0;
// }
@Override
public int getSpawnHeight() {
return 0;
}
// //
// public LimboChunkGenerator(World world, long seed) { // public LimboChunkGenerator(World world, long seed) {
@ -252,7 +269,7 @@ public class LimboChunkGenerator implements SurfaceChunkGenerator<LimboChunkGene
// return biome.getSpawnableList(creatureType); // return biome.getSpawnableList(creatureType);
// } // }
// //
// @Nullable //
// @Override // @Override
// public BlockPos getNearestStructurePos(World world, String structureName, BlockPos position, boolean findUnexplored) { // public BlockPos getNearestStructurePos(World world, String structureName, BlockPos position, boolean findUnexplored) {
// return null; // return null;

View file

@ -1,5 +1,6 @@
package org.dimdev.dimdoors.world.limbo; package org.dimdev.dimdoors.world.limbo;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -7,26 +8,28 @@ import net.minecraft.world.World;
import net.minecraft.world.dimension.Dimension; import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.dimdev.util.Location;
import javax.annotation.Nullable;
public class LimboDimension extends Dimension { public class LimboDimension extends Dimension {
public LimboDimension(World world, DimensionType type) { public LimboDimension(World world, DimensionType dimensionType, float f) {
super(world, type, 0.1f); super(world, dimensionType, f);
}
public static Location getLimboSkySpawn(Entity entity) {
return null; // TODO
} }
@Override @Override
public ChunkGenerator<?> createChunkGenerator() { public ChunkGenerator<?> createChunkGenerator() {
return new LimboChunkGenerator(); return null;
} }
@Nullable
@Override @Override
public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) { public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) {
return null; return null;
} }
@Nullable
@Override @Override
public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) { public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) {
return null; return null;
@ -43,7 +46,7 @@ public class LimboDimension extends Dimension {
} }
@Override @Override
public Vec3d getFogColor(float f, float g) { public Vec3d modifyFogColor(Vec3d vec3d, float f) {
return null; return null;
} }

View file

@ -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;
}
}

View file

@ -1,47 +1,60 @@
package org.dimdev.dimdoors.world.pocketdimension; 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.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import org.dimdev.util.render.CloudRenderBlank; import net.minecraft.world.gen.chunk.ChunkGenerator;
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 org.dimdev.pocketlib.PocketWorldDimension; import org.dimdev.pocketlib.PocketWorldDimension;
public class DungeonPocketDimension extends 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 @Override
public void init() { public ChunkGenerator<?> createChunkGenerator() {
super.init(); return null;
biomeProvider = new BiomeProviderSingle(ModBiomes.DANGEROUS_BLACK_VOID);
} }
@Override @Override
public int getRespawnDimension(EntityPlayerMP player) { public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) {
return ModDimensions.LIMBO.getId(); return null;
}
@SideOnly(Side.CLIENT)
@Override
public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) {
setCloudRenderer(new CloudRenderBlank());
return Vec3d.ZERO;
}
@Override public DimensionType getDimensionType() {
return ModDimensions.DUNGEON;
} }
@Override @Override
@SideOnly(Side.CLIENT) public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) {
public Vec3d getFogColor(float celestialAngle, float partialTicks) { return null;
return Vec3d.ZERO; }
@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;
} }
} }

View file

@ -1,68 +1,60 @@
package org.dimdev.dimdoors.world.pocketdimension; package org.dimdev.dimdoors.world.pocketdimension;
import net.minecraft.client.audio.MusicTicker; import net.minecraft.util.math.BlockPos;
import net.minecraft.entity.Entity; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeProviderSingle;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import org.dimdev.dimdoors.DimDoors; import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.world.ModBiomes;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.pocketlib.PocketWorldDimension; import org.dimdev.pocketlib.PocketWorldDimension;
public class PersonalPocketDimension extends PocketWorldDimension { public class PersonalPocketDimension extends PocketWorldDimension {
@SideOnly(Side.CLIENT) public PersonalPocketDimension(World world, DimensionType dimensionType, float f) {
private static MusicTicker.MusicType music; super(world, dimensionType, f);
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) {
} }
@Override @Override
public void init() { public ChunkGenerator<?> createChunkGenerator() {
super.init(); return null;
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;
}
} }
@Override @Override
public DimensionType getDimensionType() { public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) {
return ModDimensions.PERSONAL; return null;
}
@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
} }
@Override @Override
@SideOnly(Side.CLIENT) public BlockPos getTopSpawningBlockPosition(int i, int j, boolean bl) {
public Vec3d getFogColor(float celestialAngle, float partialTicks) { return null;
return new Vec3d(0.99, 0.99, 0.99); // https://bugs.mojang.com/projects/MC/issues/MC-123703
} }
@Override @Override
@SideOnly(Side.CLIENT) public float getSkyAngle(long l, float f) {
public MusicTicker.MusicType getMusicType() { return 0;
return music; }
@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;
} }
} }

View file

@ -1,41 +1,60 @@
package org.dimdev.dimdoors.world.pocketdimension; 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.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import org.dimdev.util.render.CloudRenderBlank; import net.minecraft.world.gen.chunk.ChunkGenerator;
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 org.dimdev.pocketlib.PocketWorldDimension; import org.dimdev.pocketlib.PocketWorldDimension;
public class PublicPocketDimension extends 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 @Override
public void init() { public ChunkGenerator<?> createChunkGenerator() {
super.init(); return null;
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;
} }
@Override @Override
@SideOnly(Side.CLIENT) public BlockPos getSpawningBlockInChunk(ChunkPos chunkPos, boolean bl) {
public Vec3d getFogColor(float celestialAngle, float partialTicks) { return null;
return Vec3d.ZERO; }
@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;
} }
} }

View file

@ -1,21 +1,35 @@
package org.dimdev.pocketlib; package org.dimdev.pocketlib;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; 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.DyeColor;
import net.minecraft.util.math.BlockBox; import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.annotatednbt.Saved; 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 { public final class Pocket {
private static final int BLOCKS_PAINTED_PER_DYE = 1106;
@Saved public final int id; @Saved public final int id;
@Saved public BlockBox box; @Saved public BlockBox box;
@Saved public VirtualLocation virtualLocation; @Saved public VirtualLocation virtualLocation;
@Saved public DyeColor dyeColor = DyeColor.WHITE; @Saved public DyeColor dyeColor = DyeColor.WHITE;
@Saved public DyeColor nextDyeColor = null; @Saved public DyeColor nextDyeColor = null;
@Saved public int count = 0; @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) { boolean isInBounds(BlockPos pos) {
return box.contains(pos); return box.contains(pos);
@ -29,7 +43,7 @@ public final class Pocket {
int maxDye = amountOfDyeRequiredToColor(this); int maxDye = amountOfDyeRequiredToColor(this);
if (dyeColor == color) { if (dyeColor == color) {
DimDoors.sendTranslatedMessage(entity, "dimdoors.pockets.dyeAlreadyAbsorbed"); entity.sendMessage(new TranslatableText("dimdoors.pockets.dyeAlreadyAbsorbed"));
return false; return false;
} }
@ -38,51 +52,51 @@ public final class Pocket {
dyeColor = color; dyeColor = color;
this.nextDyeColor = null; this.nextDyeColor = null;
count = 0; count = 0;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.pocketHasBeenDyed", dyeColor); entity.sendMessage(new TranslatableText("dimdoors.pocket.pocketHasBeenDyed", dyeColor));
return true; return true;
} else { } else {
count++; count++;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); entity.sendMessage(new TranslatableText("dimdoors.pocket.remainingNeededDyes", count, maxDye, color));
return true; return true;
} }
} else { } else {
this.nextDyeColor = color; this.nextDyeColor = color;
count = 1; count = 1;
DimDoors.sendTranslatedMessage(entity, "dimdoors.pocket.remainingNeededDyes", count, maxDye, color); entity.sendMessage(new TranslatableText("dimdoors.pocket.remainingNeededDyes", count, maxDye, color));
return true; return true;
} }
} }
/*private void repaint(DyeColor dyeColor) { // private void repaint(DyeColor dyeColor) {
short size = (short) ((this.size + 1) * 16 - 1); // BlockPos origin = getOrigin();
BlockPos origin = getOrigin(); // World world = WorldUtils.getWorld(dim);
World world = WorldUtils.getWorld(dim); // BlockState innerWall = ModBlocks.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property
BlockState innerWall = ModBlocks.FABRIC.getDefaultState()..withProperty(..., dyeColor); // <-- forgot the exact name of the color property // BlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor);
BlockState outerWall = ModBlocks.ETERNAL_FABRIC.getDefaultState().withProperty(..., dyeColor); //
// for (int x = origin.getX(); x < origin.getX() + size; x++) {
for (int x = origin.getX(); x < origin.getX() + size; x++) { // for (int y = origin.getY(); y < origin.getY() + size; y++) {
for (int y = origin.getY(); y < origin.getY() + size; y++) { // for (int z = origin.getZ(); z < origin.getZ() + size; z++) {
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));
int layer = Collections.min(Arrays.asList(x, y, z, size - 1 - x, size - 1 - y, size - 1 - z)); // if (layer == 0) {
if (layer == 0) { // if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) {
if (world.getBlockState(x, y, z).getBlock() == ModBlocks.ETERNAL_FABRIC) { // world.setBlockState(x, y, z, outerWall);
world.setBlockState(x, y, z, outerWall); // }
} // } else if (layer < 5) {
} else if (layer < 5) { // if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) {
if (world.getBlockState(x, y, z).getBlock() == ModBlocks.FABRIC) { // world.setBlockState(x, y, z, innerWall);
world.setBlockState(x, y, z, innerWall); // }
} // }
} // }
} // }
} // }
} //
// return schematic;
return schematic; // }
}*/
private static int amountOfDyeRequiredToColor(Pocket pocket) { 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;
} }
} }

View file

@ -1,14 +1,14 @@
package org.dimdev.pocketlib; package org.dimdev.pocketlib;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.PersistentState; import net.minecraft.world.PersistentState;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.storage.MapStorage; import org.dimdev.annotatednbt.AnnotatedNbt;
import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.Saved;
import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.ModConfig;
import org.dimdev.util.math.GridUtil; import org.dimdev.util.math.GridUtil;
import org.dimdev.annotatednbt.AnnotatedNbt;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,10 +23,14 @@ public class PocketRegistry extends PersistentState {
@Saved /*package-private*/ Map<Integer, Pocket> pockets; @Saved /*package-private*/ Map<Integer, Pocket> pockets;
@Saved /*package-private*/ int nextID; @Saved /*package-private*/ int nextID;
private World world; private ServerWorld world;
public PocketRegistry() { public PocketRegistry() {
super(DATA_NAME); super(DATA_NAME);
gridSize = ModConfig.POCKETS.pocketGridSize;
nextID = 0;
pockets = new HashMap<>();
} }
public PocketRegistry(String s) { public PocketRegistry(String s) {
@ -44,19 +48,12 @@ public class PocketRegistry extends PersistentState {
return tag; return tag;
} }
public static PocketRegistry instance(World world) { public static PocketRegistry instance(ServerWorld world) {
if (!(world.dimension instanceof PocketWorldDimension)) { if (!(world.dimension instanceof PocketWorldDimension)) {
throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!"); throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!");
} }
MapStorage storage = world.getPerWorldStorage(); PocketRegistry instance = world.getPersistentStateManager().get(PocketRegistry::new, DATA_NAME);
PocketRegistry instance = (PocketRegistry) storage.getOrLoadData(PocketRegistry.class, DATA_NAME);
if (instance == null) {
instance = new PocketRegistry();
instance.initNewRegistry();
storage.setData(DATA_NAME, instance);
}
instance.world = world; instance.world = world;
for (Pocket pocket : instance.pockets.values()) { for (Pocket pocket : instance.pockets.values()) {
@ -66,13 +63,6 @@ public class PocketRegistry extends PersistentState {
return instance; return instance;
} }
public void initNewRegistry() {
gridSize = ModConfig.POCKETS.pocketGridSize;
nextID = 0;
pockets = new HashMap<>();
}
/** /**
* Create a new blank pocket. * Create a new blank pocket.
* *

View file

@ -1,61 +1,11 @@
package org.dimdev.pocketlib; package org.dimdev.pocketlib;
import net.minecraft.entity.Entity; import net.minecraft.world.World;
import net.minecraft.init.Biomes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.biome.BiomeProviderSingle;
import net.minecraft.world.dimension.Dimension; import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.dimension.DimensionType;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.util.render.CloudRenderBlank;
import javax.annotation.Nullable;
public abstract class PocketWorldDimension extends Dimension { public abstract class PocketWorldDimension extends Dimension {
public PocketWorldDimension(World world, DimensionType dimensionType, float f) {
@Override super(world, dimensionType, f);
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;
} }
} }

View file

@ -3,9 +3,11 @@ package org.dimdev.pocketlib;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import net.minecraft.nbt.CompoundTag; 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.PersistentState;
import net.minecraft.world.World; 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.AnnotatedNbt;
import org.dimdev.annotatednbt.Saved; import org.dimdev.annotatednbt.Saved;
import org.dimdev.util.WorldUtils; import org.dimdev.util.WorldUtils;
@ -14,10 +16,10 @@ import java.util.UUID;
public class PrivatePocketData extends PersistentState { public class PrivatePocketData extends PersistentState {
protected static class PocketInfo { protected static class PocketInfo {
@Saved public final World world; @Saved public final ServerWorld world;
@Saved public final int id; @Saved public final int id;
public PocketInfo(World world, int id) { public PocketInfo(ServerWorld world, int id) {
this.world = world; this.world = world;
this.id = id; this.id = id;
} }
@ -35,15 +37,7 @@ public class PrivatePocketData extends PersistentState {
} }
public static PrivatePocketData instance() { public static PrivatePocketData instance() {
MapStorage storage = WorldUtils.getWorld(0).getMapStorage(); return WorldUtils.getWorld(DimensionType.OVERWORLD).getPersistentStateManager().get(PrivatePocketData::new, DATA_NAME);
PrivatePocketData instance = (PrivatePocketData) storage.getOrLoadData(PrivatePocketData.class, DATA_NAME);
if (instance == null) {
instance = new PrivatePocketData();
storage.setData(DATA_NAME, instance);
}
return instance;
} }
@Override @Override

View file

@ -1,6 +1,7 @@
package org.dimdev.pocketlib; package org.dimdev.pocketlib;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -12,12 +13,12 @@ import org.dimdev.dimdoors.world.limbo.LimboDimension;
import org.dimdev.util.Location; import org.dimdev.util.Location;
public class VirtualLocation { public class VirtualLocation {
@Saved public final World world; @Saved public final ServerWorld world;
@Saved public final int x; @Saved public final int x;
@Saved public final int z; @Saved public final int z;
@Saved public final int depth; @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.world = world;
this.x = x; this.x = x;
this.z = z; this.z = z;
@ -55,7 +56,7 @@ public class VirtualLocation {
} }
public Location projectToWorld(boolean acceptLimbo) { public Location projectToWorld(boolean acceptLimbo) {
World world = this.world; ServerWorld world = this.world;
if (!acceptLimbo && world.dimension instanceof LimboDimension) { if (!acceptLimbo && world.dimension instanceof LimboDimension) {
world = world.getServer().getWorld(DimensionType.OVERWORLD); world = world.getServer().getWorld(DimensionType.OVERWORLD);

View file

@ -5,10 +5,7 @@ import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ExplosiveProjectileEntity; import net.minecraft.entity.projectile.*;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.entity.projectile.LlamaSpitEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.thrown.ThrownEntity; import net.minecraft.entity.thrown.ThrownEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -17,10 +14,7 @@ public final class EntityUtils {
Entity topmostEntity = null; Entity topmostEntity = null;
// Thrower // Thrower
if (entity instanceof ThrownEntity) topmostEntity = ((ThrownEntity) entity).getOwner(); if (entity instanceof Projectile) topmostEntity = ((Projectile) 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 FishingBobberEntity) topmostEntity = ((FishingBobberEntity) entity).getOwner(); if (entity instanceof FishingBobberEntity) topmostEntity = ((FishingBobberEntity) entity).getOwner();
if (entity instanceof ItemEntity) topmostEntity = ((ServerWorld) entity.getEntityWorld()).getEntity(((ItemEntity) entity).getThrower()); if (entity instanceof ItemEntity) topmostEntity = ((ServerWorld) entity.getEntityWorld()).getEntity(((ItemEntity) entity).getThrower());

View file

@ -3,6 +3,7 @@ package org.dimdev.util;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -13,15 +14,15 @@ import org.dimdev.annotatednbt.Saved;
import java.io.Serializable; import java.io.Serializable;
public class Location implements AutoSerializable { public class Location implements AutoSerializable {
@Saved public final World world; @Saved public final ServerWorld world;
@Saved public final BlockPos pos; @Saved public final BlockPos pos;
public Location(World world, BlockPos pos) { public Location(ServerWorld world, BlockPos pos) {
this.world = world; this.world = world;
this.pos = pos; 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)); this(world, new BlockPos(x, y, z));
} }

View file

@ -1,6 +1,7 @@
package org.dimdev.util; package org.dimdev.util;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.annotatednbt.AutoSerializable; 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 yaw;
@Saved public final float pitch; @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); super(world, pos);
this.yaw = yaw; this.yaw = yaw;
this.pitch = pitch; this.pitch = pitch;

View file

@ -2,7 +2,6 @@ package org.dimdev.util;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions; import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView; 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) { public static void teleport(Entity entity, WorldView world, double x, double y, double z, float yaw, float pitch) {
FabricDimensions.teleport(entity, world.getDimension().getType()); 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 entity.setOnFireFor(0); // Workaround for https://bugs.mojang.com/browse/MC-100097
} }
public static void teleport(PlayerEntity player, BlockPos pos) {
}
} }

View file

@ -1,14 +1,10 @@
package org.dimdev.util; package org.dimdev.util;
import net.minecraft.util.Identifier; import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType;
public final class WorldUtils { public final class WorldUtils {
public static World getWorld(Identifier dimension) { public static ServerWorld getWorld(DimensionType personal) {
return null; // TODO return null;
}
public static Identifier getDim(World world) {
return null; // TODO
} }
} }

View file

@ -254,8 +254,8 @@ public class Schematic {
// property is Property<?>, value is Comparable<?>, and the ?s refer to the same type because // property is Property<?>, value is Comparable<?>, and the ?s refer to the same type because
// IProperty<T>.getAllowedValues() returns Collection<T>, but the compiler doesn't keep track of // IProperty<T>.getAllowedValues() returns Collection<T>, but the compiler doesn't keep track of
// this, so casting to raw types: // this, so casting to raw types:
//noinspection rawtypes //noinspection unchecked,RedundantCast,SingleStatementInBlock,rawtypes
chosenState = chosenState.with(property, (Comparable) value); chosenState = chosenState.with((Property) property, (Comparable) value);
} }
} }
} }
@ -357,7 +357,7 @@ public class Schematic {
blockEntity.fromTag(BlockEntityNBT); blockEntity.fromTag(BlockEntityNBT);
// Correct the position // Correct the position
blockEntity.setWorld(world, pos); blockEntity.setLocation(world, pos);
blockEntity.markDirty(); blockEntity.markDirty();
} else { } else {
throw new RuntimeException("Schematic contained BlockEntity " + id + " at " + pos + " but the BlockEntity of that block (" + world.getBlockState(pos) + ") must be " + blockBlockEntityId); 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)); newPosNBT.add(DoubleTag.of(posNBT.getDouble(2) + zBase));
CompoundTag adjustedEntityTag = entityNBT.copy(); CompoundTag adjustedEntityTag = entityNBT.copy();
adjustedEntityTag.put("Pos", newPosNBT); 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"))); world.spawnEntity(EntityType.getEntityFromTag(adjustedEntityTag, world).orElseThrow(() -> new RuntimeException("missing entity type")));
} }