diff --git a/patches/minecraft/net/minecraft/entity/Entity.java.patch b/patches/minecraft/net/minecraft/entity/Entity.java.patch index e25026ffc..5ab2078ef 100644 --- a/patches/minecraft/net/minecraft/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/entity/Entity.java.patch @@ -231,9 +231,8 @@ this.func_213319_R(); this.field_70170_p.func_217381_Z().func_76320_a("reposition"); - PortalInfo portalinfo = this.func_241829_a(p_241206_1_); -- if (portalinfo == null) { -+ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null; -+ if (portalinfo == null && teleporter.isVanilla()) { ++ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_241206_1_, this::func_241829_a); + if (portalinfo == null) { return null; } else { + Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic diff --git a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch index 2a55f3fd8..e8efb76e6 100644 --- a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch +++ b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch @@ -33,11 +33,10 @@ - serverworld.func_217434_e(this); - this.field_70128_L = false; - PortalInfo portalinfo = this.func_241829_a(p_241206_1_); -- if (portalinfo != null) { + serverworld.removeEntity(this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call. + this.revive(); -+ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null; -+ if (portalinfo != null || !teleporter.isVanilla()) { ++ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_241206_1_, this::func_241829_a); + if (portalinfo != null) { + Entity e = teleporter.placeEntity(this, serverworld, p_241206_1_, this.field_70177_z, spawnPortal -> {//Forge: Start vanilla logic serverworld.func_217381_Z().func_76320_a("moving"); if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) { diff --git a/src/main/java/net/minecraftforge/common/util/ITeleporter.java b/src/main/java/net/minecraftforge/common/util/ITeleporter.java index 63096ada4..91a68f250 100644 --- a/src/main/java/net/minecraftforge/common/util/ITeleporter.java +++ b/src/main/java/net/minecraftforge/common/util/ITeleporter.java @@ -21,47 +21,74 @@ package net.minecraftforge.common.util; import java.util.function.Function; +import javax.annotation.Nullable; + +import net.minecraft.block.PortalInfo; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.Teleporter; import net.minecraft.world.server.ServerWorld; /** * Interface for handling the placement of entities during dimension change. - * + *
* An implementation of this interface can be used to place the entity * in a safe location, or generate a return portal, for instance. - * + *
* See the {@link net.minecraft.world.Teleporter} class, which has * been patched to implement this interface, for a vanilla example. */ -public interface ITeleporter { - +public interface ITeleporter +{ /** * Called to handle placing the entity in the new world. - * + *
* The initial position of the entity will be its * position in the origin world, multiplied horizontally * by the computed cross-dimensional movement factor. - * + *
* Note that the supplied entity has not yet been spawned
* in the destination world at the time.
*
- * @param entity the entity to be placed
- * @param currentWorld the entity's origin
- * @param destWorld the entity's destination
- * @param yaw the suggested yaw value to apply
+ * @param entity the entity to be placed
+ * @param currentWorld the entity's origin
+ * @param destWorld the entity's destination
+ * @param yaw the suggested yaw value to apply
* @param repositionEntity a function to reposition the entity, which returns the new entity in the new dimension. This is the vanilla implementation of the dimension travel logic. If the supplied boolean is true, it is attempted to spawn a new portal.
+ *
* @return the entity in the new World. Vanilla creates for most {@link Entity}s a new instance and copy the data. But you are not allowed to create a new instance for {@link PlayerEntity}s! Move the player and update its state, see {@link ServerPlayerEntity#changeDimension(net.minecraft.world.server.ServerWorld, ITeleporter)}
*/
- default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function
+ * Return {@code null} to prevent teleporting.
+ *
+ * @param entity The entity teleporting before the teleport
+ * @param destWorld The world the entity is teleporting to
+ * @param defaultPortalInfo A reference to the vanilla method for getting portal info. You should implement your own logic instead of using this
+ *
+ * @return The location, rotation, and motion of the entity in the destWorld after the teleport
+ */
+ @Nullable
+ default PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function