Fix issue with ITeleporter allowing easier use of vanilla logic. (#7317)
This commit is contained in:
parent
b1659300e0
commit
8536521b7b
3 changed files with 45 additions and 20 deletions
|
@ -231,9 +231,8 @@
|
||||||
this.func_213319_R();
|
this.func_213319_R();
|
||||||
this.field_70170_p.func_217381_Z().func_76320_a("reposition");
|
this.field_70170_p.func_217381_Z().func_76320_a("reposition");
|
||||||
- PortalInfo portalinfo = this.func_241829_a(p_241206_1_);
|
- PortalInfo portalinfo = this.func_241829_a(p_241206_1_);
|
||||||
- if (portalinfo == null) {
|
+ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_241206_1_, this::func_241829_a);
|
||||||
+ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null;
|
if (portalinfo == null) {
|
||||||
+ if (portalinfo == null && teleporter.isVanilla()) {
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
+ Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic
|
+ Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic
|
||||||
|
|
|
@ -33,11 +33,10 @@
|
||||||
- serverworld.func_217434_e(this);
|
- serverworld.func_217434_e(this);
|
||||||
- this.field_70128_L = false;
|
- this.field_70128_L = false;
|
||||||
- PortalInfo portalinfo = this.func_241829_a(p_241206_1_);
|
- 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.
|
+ 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();
|
+ this.revive();
|
||||||
+ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null;
|
+ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_241206_1_, this::func_241829_a);
|
||||||
+ if (portalinfo != null || !teleporter.isVanilla()) {
|
if (portalinfo != null) {
|
||||||
+ Entity e = teleporter.placeEntity(this, serverworld, p_241206_1_, this.field_70177_z, spawnPortal -> {//Forge: Start vanilla logic
|
+ 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");
|
serverworld.func_217381_Z().func_76320_a("moving");
|
||||||
if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) {
|
if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) {
|
||||||
|
|
|
@ -21,47 +21,74 @@ package net.minecraftforge.common.util;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.block.PortalInfo;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.math.vector.Vector3d;
|
||||||
import net.minecraft.world.Teleporter;
|
import net.minecraft.world.Teleporter;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for handling the placement of entities during dimension change.
|
* Interface for handling the placement of entities during dimension change.
|
||||||
*
|
* <p>
|
||||||
* An implementation of this interface can be used to place the entity
|
* An implementation of this interface can be used to place the entity
|
||||||
* in a safe location, or generate a return portal, for instance.
|
* in a safe location, or generate a return portal, for instance.
|
||||||
*
|
* <p>
|
||||||
* See the {@link net.minecraft.world.Teleporter} class, which has
|
* See the {@link net.minecraft.world.Teleporter} class, which has
|
||||||
* been patched to implement this interface, for a vanilla example.
|
* 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.
|
* Called to handle placing the entity in the new world.
|
||||||
*
|
* <p>
|
||||||
* The initial position of the entity will be its
|
* The initial position of the entity will be its
|
||||||
* position in the origin world, multiplied horizontally
|
* position in the origin world, multiplied horizontally
|
||||||
* by the computed cross-dimensional movement factor.
|
* by the computed cross-dimensional movement factor.
|
||||||
*
|
* <p>
|
||||||
* Note that the supplied entity has not yet been spawned
|
* Note that the supplied entity has not yet been spawned
|
||||||
* in the destination world at the time.
|
* in the destination world at the time.
|
||||||
*
|
*
|
||||||
* @param entity the entity to be placed
|
* @param entity the entity to be placed
|
||||||
* @param currentWorld the entity's origin
|
* @param currentWorld the entity's origin
|
||||||
* @param destWorld the entity's destination
|
* @param destWorld the entity's destination
|
||||||
* @param yaw the suggested yaw value to apply
|
* @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.
|
* @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 <b>you are not allowed</b> 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)}
|
* @return the entity in the new World. Vanilla creates for most {@link Entity}s a new instance and copy the data. But <b>you are not allowed</b> 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<Boolean, Entity> repositionEntity) {
|
default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
|
||||||
return repositionEntity.apply(true);
|
{
|
||||||
|
return repositionEntity.apply(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the PortalInfo. defaultPortalInfo references the
|
||||||
|
* vanilla code and should not be used for your purposes.
|
||||||
|
* Override this method to handle your own logic.
|
||||||
|
* <p>
|
||||||
|
* 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<ServerWorld, PortalInfo> defaultPortalInfo)
|
||||||
|
{
|
||||||
|
return this.isVanilla() ? defaultPortalInfo.apply(destWorld) : new PortalInfo(entity.getPositionVec(), Vector3d.ZERO, entity.rotationYaw, entity.rotationPitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
//used internally to handle vanilla hardcoding
|
/**
|
||||||
|
* Is this teleporter the vanilla instance.
|
||||||
|
*/
|
||||||
default boolean isVanilla()
|
default boolean isVanilla()
|
||||||
{
|
{
|
||||||
return getClass() == Teleporter.class;
|
return this.getClass() == Teleporter.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue