Skip to content

Commit

Permalink
Merge branch 'release-1.16' into 1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Apr 2, 2021
2 parents a645bba + 5b1f8c9 commit 1a44873
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
minecraftVersion=1.16.5
api_version=3.2.8
api_version=3.2.8.1
59 changes: 42 additions & 17 deletions src/main/java/com/hrznstudio/titanium/util/TeleportationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

package com.hrznstudio.titanium.util;

import net.minecraft.block.PortalInfo;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.network.play.server.SSetPassengersPacket;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;

Expand All @@ -21,26 +25,47 @@ public class TeleportationUtils {


public static Entity teleportEntity(Entity entity, RegistryKey<World> dimension, double xCoord, double yCoord, double zCoord, float yaw, float pitch) {
if (entity == null || entity.world.isRemote) {
return teleportEntityTo(entity, new BlockPos(xCoord, yCoord, zCoord), dimension, yaw ,pitch);
}

public static Entity teleportEntityTo(Entity entity, BlockPos target, RegistryKey<World> destinationDimension, float yaw, float pitch) {
if (entity.getEntityWorld().getDimensionKey() == destinationDimension) {
entity.rotationYaw = yaw;
entity.rotationPitch = pitch;
entity.setPositionAndUpdate(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);

if (!entity.getPassengers().isEmpty()) {
//Force re-apply any passengers so that players don't get "stuck" outside what they may be riding
((ServerChunkProvider) entity.getEntityWorld().getChunkProvider()).sendToAllTracking(entity, new SSetPassengersPacket(entity));
}
return entity;
}
} else {
ServerWorld newWorld = ((ServerWorld) entity.getEntityWorld()).getServer().getWorld(destinationDimension);
if (newWorld != null) {
Vector3d destination = new Vector3d(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);
//Note: We grab the passengers here instead of in placeEntity as changeDimension starts by removing any passengers
List<Entity> passengers = entity.getPassengers();
return entity.changeDimension(newWorld, new ITeleporter() {
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
Entity repositionedEntity = repositionEntity.apply(false);
if (repositionedEntity != null) {
//Teleport all passengers to the other dimension and then make them start riding the entity again
for (Entity passenger : passengers) {
teleportPassenger(destWorld, repositionedEntity, passenger);
}
}
return repositionedEntity;
}

MinecraftServer server = entity.getServer();
List<Entity> passengers = entity.getPassengers();
return entity.changeDimension(server.getWorld(dimension), new ITeleporter() {
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yawE, Function<Boolean, Entity> repositionEntity) {
Entity repositionedEntity = repositionEntity.apply(false);
if (repositionedEntity != null){
repositionedEntity.setPositionAndRotation(xCoord, yCoord, zCoord, yaw, pitch);
repositionedEntity.setPositionAndUpdate(xCoord, yCoord, zCoord);
for (Entity passenger : passengers) {
teleportPassenger(destWorld, repositionedEntity, passenger);
@Override
public PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) {
return new PortalInfo(destination, entity.getMotion(), pitch, yaw);
}
}
return repositionedEntity;
});
}
});
}
return null;
}

private static void teleportPassenger(ServerWorld destWorld, Entity repositionedEntity, Entity passenger) {
Expand Down

0 comments on commit 1a44873

Please sign in to comment.