[1.15] Reimplemented the ITeleporter interface (#6404)

This commit is contained in:
mcenderdragon 2020-01-29 18:18:07 +01:00 committed by GitHub
parent 509a28efd3
commit 44d9fff2b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 217 additions and 21 deletions

View File

@ -222,15 +222,27 @@
}
public boolean func_70028_i(Entity p_70028_1_) {
@@ -2046,6 +2073,7 @@
@@ -2046,6 +2073,11 @@
@Nullable
public Entity func_212321_a(DimensionType p_212321_1_) {
+ return this.changeDimension(p_212321_1_, func_184102_h().func_71218_a(p_212321_1_).func_85176_s());
+ }
+ @Nullable
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_212321_1_)) return null;
if (!this.field_70170_p.field_72995_K && !this.field_70128_L) {
this.field_70170_p.func_217381_Z().func_76320_a("changeDimension");
MinecraftServer minecraftserver = this.func_184102_h();
@@ -2063,16 +2091,9 @@
@@ -2055,6 +2087,7 @@
this.field_71093_bK = p_212321_1_;
this.func_213319_R();
this.field_70170_p.func_217381_Z().func_76320_a("reposition");
+ Entity transportedEntity = teleporter.placeEntity(this, serverworld, serverworld1, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic
Vec3d vec3d = this.func_213322_ci();
float f = 0.0F;
BlockPos blockpos;
@@ -2063,16 +2096,9 @@
} else if (p_212321_1_ == DimensionType.field_223229_c_) {
blockpos = serverworld1.func_180504_m();
} else {
@ -250,16 +262,41 @@
double d3 = Math.min(-2.9999872E7D, serverworld1.func_175723_af().func_177726_b() + 16.0D);
double d4 = Math.min(-2.9999872E7D, serverworld1.func_175723_af().func_177736_c() + 16.0D);
@@ -2101,7 +2122,7 @@
@@ -2082,6 +2108,7 @@
d1 = MathHelper.func_151237_a(d1, d4, d6);
Vec3d vec3d1 = this.func_181014_aG();
blockpos = new BlockPos(d0, this.func_226278_cu_(), d1);
+ if (spawnPortal) {
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1.func_85176_s().func_222272_a(blockpos, vec3d, this.func_181012_aH(), vec3d1.field_72450_a, vec3d1.field_72448_b, this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
@@ -2090,6 +2117,7 @@
blockpos = new BlockPos(blockpattern$portalinfo.field_222505_a);
vec3d = blockpattern$portalinfo.field_222506_b;
f = (float)blockpattern$portalinfo.field_222507_c;
+ }
}
this.field_70170_p.func_217381_Z().func_219895_b("reloading");
@@ -2100,13 +2128,15 @@
entity.func_213317_d(vec3d);
serverworld1.func_217460_e(entity);
}
+ return entity;
+ });//Forge: End vanilla logic
- this.field_70128_L = true;
+ this.remove(false);
this.field_70170_p.func_217381_Z().func_76319_b();
serverworld.func_82742_i();
serverworld1.func_82742_i();
@@ -2129,10 +2150,12 @@
this.field_70170_p.func_217381_Z().func_76319_b();
- return entity;
+ return transportedEntity;
} else {
return null;
}
@@ -2129,10 +2159,12 @@
}
public Vec3d func_181014_aG() {
@ -272,7 +309,7 @@
return this.field_181018_ap;
}
@@ -2261,7 +2284,7 @@
@@ -2261,7 +2293,7 @@
Pose pose = this.func_213283_Z();
EntitySize entitysize1 = this.func_213305_a(pose);
this.field_213325_aI = entitysize1;
@ -281,7 +318,7 @@
if (entitysize1.field_220315_a < entitysize.field_220315_a) {
double d0 = (double)entitysize1.field_220315_a / 2.0D;
this.func_174826_a(new AxisAlignedBB(this.func_226277_ct_() - d0, this.func_226278_cu_(), this.func_226281_cx_() - d0, this.func_226277_ct_() + d0, this.func_226278_cu_() + (double)entitysize1.field_220316_b, this.func_226281_cx_() + d0));
@@ -2713,6 +2736,7 @@
@@ -2713,6 +2745,7 @@
this.field_70165_t = p_226288_1_;
this.field_70163_u = p_226288_3_;
this.field_70161_v = p_226288_5_;
@ -289,7 +326,7 @@
}
public void func_70623_bb() {
@@ -2726,4 +2750,69 @@
@@ -2726,4 +2759,69 @@
public interface IMoveCallback {
void accept(Entity p_accept_1_, double p_accept_2_, double p_accept_4_, double p_accept_6_);
}

View File

@ -22,3 +22,17 @@
}
} else if (livingentity != null) {
livingentity.func_70634_a(this.func_226277_ct_(), this.func_226278_cu_(), this.func_226281_cx_());
@@ -121,11 +124,11 @@
}
@Nullable
- public Entity func_212321_a(DimensionType p_212321_1_) {
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
if (this.field_70192_c.field_71093_bK != p_212321_1_) {
this.field_70192_c = null;
}
- return super.func_212321_a(p_212321_1_);
+ return super.changeDimension(p_212321_1_, teleporter);
}
}

View File

@ -109,6 +109,17 @@
this.func_70106_y();
itemstack.func_190920_e(i);
}
@@ -300,8 +328,8 @@
}
@Nullable
- public Entity func_212321_a(DimensionType p_212321_1_) {
- Entity entity = super.func_212321_a(p_212321_1_);
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
+ Entity entity = super.changeDimension(p_212321_1_, teleporter);
if (!this.field_70170_p.field_72995_K && entity instanceof ItemEntity) {
((ItemEntity)entity).func_85054_d();
}
@@ -366,7 +394,7 @@
public void func_174870_v() {

View File

@ -1,7 +1,14 @@
--- a/net/minecraft/entity/item/minecart/ContainerMinecartEntity.java
+++ b/net/minecraft/entity/item/minecart/ContainerMinecartEntity.java
@@ -115,12 +115,14 @@
return super.func_212321_a(p_212321_1_);
@@ -110,17 +110,19 @@
}
@Nullable
- public Entity func_212321_a(DimensionType p_212321_1_) {
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
this.field_94112_b = false;
- return super.func_212321_a(p_212321_1_);
+ return super.changeDimension(p_212321_1_, teleporter);
}
- public void func_70106_y() {

View File

@ -0,0 +1,14 @@
--- a/net/minecraft/entity/merchant/villager/AbstractVillagerEntity.java
+++ b/net/minecraft/entity/merchant/villager/AbstractVillagerEntity.java
@@ -179,9 +179,9 @@
}
@Nullable
- public Entity func_212321_a(DimensionType p_212321_1_) {
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
this.func_213750_eg();
- return super.func_212321_a(p_212321_1_);
+ return super.changeDimension(p_212321_1_, teleporter);
}
protected void func_213750_eg() {

View File

@ -14,7 +14,8 @@
+ @Override
@Nullable
public Entity func_212321_a(DimensionType p_212321_1_) {
- public Entity func_212321_a(DimensionType p_212321_1_) {
+ public Entity changeDimension(DimensionType p_212321_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_212321_1_)) return null;
this.field_184851_cj = true;
DimensionType dimensiontype = this.field_71093_bK;
@ -25,7 +26,7 @@
if (!this.field_71136_j) {
this.field_71136_j = true;
this.field_71135_a.func_147359_a(new SChangeGameStatePacket(4, this.field_192040_cp ? 0.0F : 1.0F));
@@ -569,12 +572,13 @@
@@ -569,12 +572,14 @@
this.field_71093_bK = p_212321_1_;
ServerWorld serverworld1 = this.field_71133_b.func_71218_a(p_212321_1_);
WorldInfo worldinfo = serverworld1.func_72912_H();
@ -38,10 +39,11 @@
- this.field_70128_L = false;
+ 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();
+ Entity e = teleporter.placeEntity(this, serverworld, serverworld1, this.field_70177_z, spawnPortal -> {//Forge: Start vanilla logic
double d0 = this.func_226277_ct_();
double d1 = this.func_226278_cu_();
double d2 = this.func_226281_cx_();
@@ -583,13 +587,11 @@
@@ -583,13 +588,11 @@
double d3 = 8.0D;
float f2 = f1;
serverworld.func_217381_Z().func_76320_a("moving");
@ -58,7 +60,26 @@
} else if (dimensiontype == DimensionType.field_223227_a_ && p_212321_1_ == DimensionType.field_223229_c_) {
BlockPos blockpos = serverworld1.func_180504_m();
d0 = (double)blockpos.func_177958_n();
@@ -653,6 +655,7 @@
@@ -630,7 +633,7 @@
this.func_70012_b((double)i, (double)j, (double)k, f1, 0.0F);
this.func_213317_d(Vec3d.field_186680_a);
- } else if (!serverworld1.func_85176_s().func_222268_a(this, f2)) {
+ } else if (spawnPortal && !serverworld1.func_85176_s().func_222268_a(this, f2)) {
serverworld1.func_85176_s().func_85188_a(this);
serverworld1.func_85176_s().func_222268_a(this, f2);
}
@@ -640,6 +643,9 @@
serverworld1.func_217447_b(this);
this.func_213846_b(serverworld);
this.field_71135_a.func_147364_a(this.func_226277_ct_(), this.func_226278_cu_(), this.func_226281_cx_(), f1, f);
+ return this;//forge: this is part of the ITeleporter patch
+ });//Forge: End vanilla logic
+ if (e != this) throw new java.lang.IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this));
this.field_71134_c.func_73080_a(serverworld1);
this.field_71135_a.func_147359_a(new SPlayerAbilitiesPacket(this.field_71075_bZ));
playerlist.func_72354_b(this, serverworld1);
@@ -653,6 +659,7 @@
this.field_71144_ck = -1;
this.field_71149_ch = -1.0F;
this.field_71146_ci = -1;
@ -66,7 +87,7 @@
return this;
}
}
@@ -788,6 +791,7 @@
@@ -788,6 +795,7 @@
this.field_71135_a.func_147359_a(new SOpenWindowPacket(container.field_75152_c, container.func_216957_a(), p_213829_1_.func_145748_c_()));
container.func_75132_a(this);
this.field_71070_bA = container;
@ -74,7 +95,7 @@
return OptionalInt.of(this.field_71139_cq);
}
}
@@ -806,6 +810,7 @@
@@ -806,6 +814,7 @@
this.field_71135_a.func_147359_a(new SOpenHorseWindowPacket(this.field_71139_cq, p_184826_2_.func_70302_i_(), p_184826_1_.func_145782_y()));
this.field_71070_bA = new HorseInventoryContainer(this.field_71139_cq, this.field_71071_by, p_184826_2_, p_184826_1_);
this.field_71070_bA.func_75132_a(this);
@ -82,7 +103,7 @@
}
public void func_184814_a(ItemStack p_184814_1_, Hand p_184814_2_) {
@@ -863,6 +868,7 @@
@@ -863,6 +872,7 @@
public void func_71128_l() {
this.field_71070_bA.func_75134_a(this);
@ -90,7 +111,7 @@
this.field_71070_bA = this.field_71069_bz;
}
@@ -989,6 +995,20 @@
@@ -989,6 +999,20 @@
this.field_193110_cw = p_193104_1_.field_193110_cw;
this.func_192029_h(p_193104_1_.func_192023_dk());
this.func_192031_i(p_193104_1_.func_192025_dl());
@ -111,7 +132,7 @@
}
protected void func_70670_a(EffectInstance p_70670_1_) {
@@ -1207,15 +1227,16 @@
@@ -1207,15 +1231,16 @@
this.func_184210_p();
if (p_200619_1_ == this.field_70170_p) {
this.field_71135_a.func_147364_a(p_200619_2_, p_200619_4_, p_200619_6_, p_200619_8_, p_200619_9_);
@ -131,7 +152,7 @@
this.func_70012_b(p_200619_2_, p_200619_4_, p_200619_6_, p_200619_8_, p_200619_9_);
this.func_70029_a(p_200619_1_);
p_200619_1_.func_217446_a(this);
@@ -1224,6 +1245,7 @@
@@ -1224,6 +1249,7 @@
this.field_71134_c.func_73080_a(p_200619_1_);
this.field_71133_b.func_184103_al().func_72354_b(this, p_200619_1_);
this.field_71133_b.func_184103_al().func_72385_f(this);
@ -139,7 +160,7 @@
}
}
@@ -1261,6 +1283,8 @@
@@ -1261,6 +1287,8 @@
if (itementity == null) {
return null;
} else {

View File

@ -0,0 +1,11 @@
--- a/net/minecraft/world/Teleporter.java
+++ b/net/minecraft/world/Teleporter.java
@@ -23,7 +23,7 @@
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.server.TicketType;
-public class Teleporter {
+public class Teleporter implements net.minecraftforge.common.util.ITeleporter {
protected final ServerWorld field_85192_a;
protected final Random field_77187_a;

View File

@ -0,0 +1,62 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.util;
import java.util.function.Function;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.dimension.Dimension;
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 {
/**
* 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
* (see {@link Dimension#getMovementFactor()}).
*
* 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 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.dimension.DimensionType, ITeleporter)}
*/
default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
return repositionEntity.apply(true);
}
}

View File

@ -28,6 +28,8 @@ import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -35,6 +37,7 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.Collection;
import java.util.function.Function;
public class CommandSetDimension
{
@ -54,6 +57,15 @@ public class CommandSetDimension
);
}
private static final ITeleporter PORTALLESS = new ITeleporter()
{
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
{
return repositionEntity.apply(false);
}
};
private static int execute(CommandSource sender, Collection<? extends Entity> entities, DimensionType dim, BlockPos pos) throws CommandSyntaxException
{
entities.removeIf(e -> !canEntityTeleport(e));
@ -64,7 +76,7 @@ public class CommandSetDimension
// throw INVALID_DIMENSION.create(dim);
entities.stream().filter(e -> e.dimension == dim).forEach(e -> sender.sendFeedback(new TranslationTextComponent("commands.forge.setdim.invalid.nochange", e.getDisplayName().getFormattedText(), dim), true));
entities.stream().filter(e -> e.dimension != dim).forEach(e -> e.changeDimension(dim));
entities.stream().filter(e -> e.dimension != dim).forEach(e -> e.changeDimension(dim, PORTALLESS));
return 0;
}

View File

@ -35,7 +35,14 @@ net/minecraft/client/resources/ClientResourcePackInfo.<init>(Ljava/lang/String;Z
net/minecraft/client/gui/ScreenManager.getScreenFactory(Lnet/minecraft/inventory/container/ContainerType;Lnet/minecraft/client/Minecraft;ILnet/minecraft/util/text/ITextComponent;)Ljava/util/Optional;=|p_216909_0_,p_216909_1_,p_216909_2_,p_216909_3_
net/minecraft/entity/EntityClassification.create(Ljava/lang/String;Ljava/lang/String;IZZ)Lnet/minecraft/entity/EntityClassification;=|name,p_i50381_3_,p_i50381_4_,p_i50381_5_,p_i50381_6_
net/minecraft/entity/Entity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/entity/item/EnderPearlEntity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/entity/item/ItemEntity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/entity/item/minecart/ContainerMinecartEntity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/entity/merchant/villager/AbstractVillagerEntity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/entity/player/PlayerEntity.getDigSpeed(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)F=|p_184813_1_,pos
net/minecraft/entity/player/ServerPlayerEntity.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/item/Rarity.create(Ljava/lang/String;Lnet/minecraft/util/text/TextFormatting;)Lnet/minecraft/item/EnumRarity;=|name,p_i48837_3_