Skip to content

Commit

Permalink
Always call placeInPortal for mods. Fixes SpongePowered/SpongeForge#2025
Browse files Browse the repository at this point in the history


If a custom teleporter is used, placeInPortal will always be called to
support mods.
  • Loading branch information
bloodmc committed Mar 13, 2018
1 parent aaca1ae commit efc94af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/spongepowered/common/entity/EntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public static MoveEntityEvent.Teleport handleDisplaceEntityTeleportEvent(Entity
public static MoveEntityEvent.Teleport.Portal handleDisplaceEntityPortalEvent(Entity entityIn, int targetDimensionId, @Nullable Teleporter teleporter) {
SpongeImplHooks.registerPortalAgentType(teleporter);
final MinecraftServer mcServer = SpongeImpl.getServer();
final IMixinTeleporter mixinTeleporter = (IMixinTeleporter) teleporter;
final IMixinPlayerList mixinPlayerList = (IMixinPlayerList) mcServer.getPlayerList();
final IMixinEntity mixinEntity = (IMixinEntity) entityIn;
final Transform<World> fromTransform = mixinEntity.getTransform();
Expand Down Expand Up @@ -385,10 +386,11 @@ public static MoveEntityEvent.Teleport.Portal handleDisplaceEntityPortalEvent(En

if (entityIn.isEntityAlive() && !(fromWorld.provider instanceof WorldProviderEnd)) {
fromWorld.profiler.startSection("placing");
// placeInPortal must be used to support mods
// Only place entity in portal if it collided with a portal block
// Note: To verify if this is true, entityIn.getLastPortalVec() should not be null
if (entityIn.getLastPortalVec() != null) {
// Only place entity in portal if one of the following are true :
// 1. The teleporter is custom. (not vanilla)
// 2. The last known portal vec is known. (Usually set after block collision)
// Note: We must always use placeInPortal to support mods.
if (!mixinTeleporter.isVanilla() || entityIn.getLastPortalVec() != null) {
teleporter.placeInPortal(entityIn, entityIn.rotationYaw);
}
fromWorld.profiler.endSection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface IMixinTeleporter {
void setPortalAgentType(PortalAgentType type);

void setPortalType(int dimensionId);

boolean isVanilla();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.interfaces.world.IMixinLocation;
import org.spongepowered.common.interfaces.world.IMixinTeleporter;
import org.spongepowered.common.interfaces.world.IMixinWorldServer;
Expand All @@ -59,6 +62,7 @@
@Mixin(Teleporter.class)
public class MixinTeleporter implements PortalAgent, IMixinTeleporter {

private boolean isVanilla;
private int searchRadius = 128;
private int creationRadius = 16;
private boolean createNetherPortal = true;
Expand All @@ -68,6 +72,11 @@ public class MixinTeleporter implements PortalAgent, IMixinTeleporter {
@Shadow @Final private Random random;
@Shadow @Final private Long2ObjectMap<Teleporter.PortalPosition> destinationCoordinateCache;

@Inject(method = "<init>", at = @At("RETURN"))
private void onConstruct(WorldServer worldIn, CallbackInfo ci) {
this.isVanilla = this.getClass().getName().startsWith("net.minecraft.");
}

@Override
public int getSearchRadius() {
return this.searchRadius;
Expand Down Expand Up @@ -527,6 +536,11 @@ public void setPortalType(int dimensionId) {
}
}

@Override
public boolean isVanilla() {
return this.isVanilla;
}

@Override
public String toString() {
return MoreObjects.toStringHelper("PortalAgent")
Expand Down

0 comments on commit efc94af

Please sign in to comment.