use of net.minecraftforge.common.util.ITeleporter in project Mekanism by mekanism.
the class TileEntityTeleporter method teleportPassenger.
private static void teleportPassenger(ServerWorld destWorld, Vector3d destination, Entity repositionedEntity, Entity passenger) {
if (!passenger.canChangeDimensions()) {
// If the passenger can't change dimensions just let it peacefully stay after dismounting rather than trying to teleport it
return;
}
// Note: We grab the passengers here instead of in placeEntity as changeDimension starts by removing any passengers
List<Entity> passengers = passenger.getPassengers();
passenger.changeDimension(destWorld, new ITeleporter() {
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
boolean invulnerable = entity.isInvulnerable();
// Make the entity invulnerable so that when we teleport it, it doesn't take damage
// we revert this state to the previous state after teleporting
entity.setInvulnerable(true);
Entity repositionedPassenger = repositionEntity.apply(false);
if (repositionedPassenger != null) {
// Force our passenger to start riding the new entity again
repositionedPassenger.startRiding(repositionedEntity, true);
// Teleport "nested" passengers
for (Entity passenger : passengers) {
teleportPassenger(destWorld, destination, repositionedPassenger, passenger);
}
repositionedPassenger.setInvulnerable(invulnerable);
}
entity.setInvulnerable(invulnerable);
return repositionedPassenger;
}
@Override
public PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) {
// This is needed to ensure the passenger starts getting tracked after teleporting
return new PortalInfo(destination, entity.getDeltaMovement(), entity.yRot, entity.xRot);
}
@Override
public boolean playTeleportSound(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) {
return false;
}
});
}
use of net.minecraftforge.common.util.ITeleporter in project EnderIO by SleepyTrousers.
the class TeleportUtil method serverPlayerDimensionTeleport.
private static void serverPlayerDimensionTeleport(@Nonnull final EntityPlayerMP player, @Nonnull final BlockPos pos, final int targetDim, final boolean conserveMotion, @Nonnull final TravelSource source) {
ChunkTicket.loadChunk(player, player.world, BlockCoord.get(player));
SoundHelper.playSound(player.world, player, source.sound, 1.0F, 1.0F);
player.mcServer.getPlayerList().transferPlayerToDimension(player, targetDim, new ITeleporter() {
@Override
public void placeEntity(World world, Entity entity, float yaw) {
// like Forge's teleport command:
entity.setLocationAndAngles(pos.getX() + 0.5, pos.getY() + 1.1, pos.getZ() + 0.5, entity.rotationYaw, entity.rotationPitch);
// like vanilla's nether teleporter:
((EntityPlayerMP) entity).connection.setPlayerLocation(pos.getX() + 0.5, pos.getY() + 1.1, pos.getZ() + 0.5, entity.rotationYaw, entity.rotationPitch);
// Note: Each one of the above should be enough, but there have been issues with setting the player position after a dimension change, so we're doing
// both to be on the safe side...
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
entity.fallDistance = 0;
}
});
SoundHelper.playSound(player.world, player, source.sound, 1.0F, 1.0F);
ChunkTicket.loadChunk(player, player.world, BlockCoord.get(player));
if (conserveMotion) {
Vector3d velocityVex = Util.getLookVecEio(player);
player.connection.sendPacket(new SPacketEntityVelocity(player.getEntityId(), velocityVex.x, velocityVex.y, velocityVex.z));
}
}
use of net.minecraftforge.common.util.ITeleporter in project EnderIO by SleepyTrousers.
the class TeleportUtil method serverEntityDimensionTeleport.
private static void serverEntityDimensionTeleport(@Nonnull Entity entity, @Nonnull BlockPos pos, int targetDim, @Nonnull TravelSource source) {
SoundHelper.playSound(entity.world, entity, source.sound, 1.0F, 1.0F);
entity.changeDimension(targetDim, new ITeleporter() {
@Override
public void placeEntity(World world, Entity entity2, float yaw) {
entity2.setLocationAndAngles(pos.getX() + 0.5, pos.getY() + 1.1, pos.getZ() + 0.5, entity2.rotationYaw, entity2.rotationPitch);
entity2.motionX = 0;
entity2.motionY = 0;
entity2.motionZ = 0;
entity2.fallDistance = 0;
}
});
SoundHelper.playSound(entity.world, entity, source.sound, 1.0F, 1.0F);
}
use of net.minecraftforge.common.util.ITeleporter in project Arclight by IzzelAliz.
the class ServerPlayerEntityMixin_1_15 method changeDimension.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(DimensionType dim, ITeleporter teleporter) {
DimensionType[] destination = { dim };
if (this.isSleeping())
return (ServerPlayerEntity) (Object) this;
if (!ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, destination[0]))
return null;
PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
// this.invulnerableDimensionChange = true;
DimensionType dimensiontype = this.dimension;
if (((DimensionTypeBridge) dimensiontype).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.OVERWORLD && teleporter instanceof Teleporter) {
// Forge: Fix non-vanilla teleporters triggering end credits
this.invulnerableDimensionChange = true;
this.detach();
// Forge: The player entity is cloned so keep the data until after cloning calls copyFrom
this.getServerWorld().removePlayer((ServerPlayerEntity) (Object) this, true);
if (!this.queuedEndExit) {
this.queuedEndExit = true;
this.connection.sendPacket(new SChangeGameStatePacket(4, this.seenCredits ? 0.0F : 1.0F));
this.seenCredits = true;
}
return (ServerPlayerEntity) (Object) this;
} else {
ServerWorld serverworld = this.server.getWorld(dimensiontype);
// this.dimension = destination;
ServerWorld[] serverworld1 = { this.server.getWorld(destination[0]) };
/*
WorldInfo worldinfo = serverworld1.getWorldInfo();
NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
this.connection.sendPacket(new SRespawnPacket(destination, WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
PlayerList playerlist = this.server.getPlayerList();
playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
serverworld.removeEntity((ServerPlayerEntity) (Object) 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();
*/
PlayerList[] playerlist = new PlayerList[1];
Entity e = teleporter.placeEntity((ServerPlayerEntity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> {
// Forge: Start vanilla logic
double d0 = this.getPosX();
double d1 = this.getPosY();
double d2 = this.getPosZ();
float f = this.rotationPitch;
float f1 = this.rotationYaw;
double d3 = 8.0D;
float f2 = f1;
serverworld.getProfiler().startSection("moving");
if (serverworld1[0] != null) {
double moveFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
d0 *= moveFactor;
d2 *= moveFactor;
if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_NETHER) {
this.enteredNetherPosition = this.getPositionVec();
} else if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_END) {
BlockPos blockpos = serverworld1[0].getSpawnCoordinate();
d0 = blockpos.getX();
d1 = blockpos.getY();
d2 = blockpos.getZ();
f1 = 90.0F;
f = 0.0F;
}
}
Location enter = this.bridge$getBukkitEntity().getLocation();
Location exit = (serverworld1[0] == null) ? null : new Location(((ServerWorldBridge) serverworld1[0]).bridge$getWorld(), d0, d1, d2, f1, f);
PlayerPortalEvent event = new PlayerPortalEvent(this.bridge$getBukkitEntity(), enter, exit, cause, 128, true, ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END ? 0 : 16);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null) {
return null;
}
exit = event.getTo();
if (exit == null) {
return null;
}
serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
d0 = exit.getX();
d1 = exit.getY();
d2 = exit.getZ();
// this.setLocationAndAngles(d0, d1, d2, f1, f);
serverworld.getProfiler().endSection();
serverworld.getProfiler().startSection("placing");
double d7 = Math.max(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
double d4 = Math.max(-2.9999872E7D, serverworld1[0].getWorldBorder().minZ() + 16.0D);
double d5 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxX() - 16.0D);
double d6 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxZ() - 16.0D);
d0 = MathHelper.clamp(d0, d7, d5);
d2 = MathHelper.clamp(d2, d4, d6);
// this.setLocationAndAngles(d0, d1, d2, f1, f);
Vec3d exitVelocity = Vec3d.ZERO;
BlockPos exitPosition = new BlockPos(d0, d1, d2);
if (((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END) {
int i = exitPosition.getX();
int j = exitPosition.getY() - 1;
int k = exitPosition.getZ();
if (event.getCanCreatePortal()) {
BlockStateListPopulator blockList = new BlockStateListPopulator(serverworld1[0]);
for (int j1 = -2; j1 <= 2; ++j1) {
for (int k1 = -2; k1 <= 2; ++k1) {
for (int l1 = -1; l1 < 3; ++l1) {
int i2 = i + k1 * 1 + j1 * 0;
int j2 = j + l1;
int k2 = k + k1 * 0 - j1 * 1;
boolean flag = l1 < 0;
blockList.setBlockState(new BlockPos(i2, j2, k2), flag ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
}
}
}
org.bukkit.World bworld = ((ServerWorldBridge) serverworld1[0]).bridge$getWorld();
PortalCreateEvent portalEvent = new PortalCreateEvent((List<BlockState>) (List) blockList.getList(), bworld, this.bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM);
Bukkit.getPluginManager().callEvent(portalEvent);
if (!portalEvent.isCancelled()) {
blockList.updateList();
}
}
// this.setLocationAndAngles(i, j, k, f1, 0.0F);
exit.setX(i);
exit.setY(j);
exit.setZ(k);
// this.setMotion(Vec3d.ZERO);
exitVelocity = Vec3d.ZERO;
} else {
BlockPattern.PortalInfo portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
if (spawnPortal && portalInfo == null && event.getCanCreatePortal()) {
if (((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$makePortal((ServerPlayerEntity) (Object) this, exitPosition, event.getCreationRadius())) {
// serverworld1.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f2);
portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
}
}
if (portalInfo == null) {
return null;
}
exitVelocity = portalInfo.motion;
exit.setX(portalInfo.pos.getX());
exit.setY(portalInfo.pos.getY());
exit.setZ(portalInfo.pos.getZ());
exit.setYaw(f2 + (float) portalInfo.rotation);
}
serverworld.getProfiler().endSection();
PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.bridge$getBukkitEntity(), enter, exit, cause);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
return null;
}
exit = tpEvent.getTo();
if (exit == null) {
return null;
}
serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
this.invulnerableDimensionChange = true;
destination[0] = serverworld1[0].getDimension().getType();
this.dimension = destination[0];
WorldInfo worldinfo = serverworld1[0].getWorldInfo();
NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
this.connection.sendPacket(new SRespawnPacket(destination[0], WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
playerlist[0] = this.server.getPlayerList();
playerlist[0].updatePermissionLevel((ServerPlayerEntity) (Object) this);
// Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call.
serverworld.removeEntity((ServerPlayerEntity) (Object) this, true);
this.revive();
this.setMotion(exitVelocity);
this.setWorld(serverworld1[0]);
serverworld1[0].addDuringPortalTeleport((ServerPlayerEntity) (Object) this);
this.func_213846_b(serverworld);
// this.connection.setPlayerLocation(this.getPosX(), this.getPosY(), this.getPosZ(), f1, f);
((ServerPlayNetHandlerBridge) this.connection).bridge$teleport(exit);
this.connection.captureCurrentPosition();
// forge: this is part of the ITeleporter patch
return (ServerPlayerEntity) (Object) this;
});
// Forge: End vanilla logic
if (e == null) {
return (ServerPlayerEntity) (Object) this;
} else if (e != (Object) this) {
throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this));
}
this.interactionManager.setWorld(serverworld1[0]);
this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
playerlist[0].sendWorldInfo((ServerPlayerEntity) (Object) this, serverworld1[0]);
playerlist[0].sendInventory((ServerPlayerEntity) (Object) this);
for (EffectInstance effectinstance : this.getActivePotionEffects()) {
this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), effectinstance));
}
this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
this.lastExperience = -1;
this.lastHealth = -1.0F;
this.lastFoodLevel = -1;
BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensiontype, destination[0]);
PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.bridge$getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld());
Bukkit.getPluginManager().callEvent(changeEvent);
return (ServerPlayerEntity) (Object) this;
}
}
use of net.minecraftforge.common.util.ITeleporter in project Mekanism by mekanism.
the class EntityRobit method goHome.
public void goHome() {
if (level.isClientSide()) {
return;
}
setFollowing(false);
if (level.dimension() == homeLocation.dimension) {
setDeltaMovement(0, 0, 0);
teleportTo(homeLocation.getX() + 0.5, homeLocation.getY() + 0.3, homeLocation.getZ() + 0.5);
} else {
ServerWorld newWorld = ((ServerWorld) this.level).getServer().getLevel(homeLocation.dimension);
if (newWorld != null) {
Vector3d destination = new Vector3d(homeLocation.getX() + 0.5, homeLocation.getY() + 0.3, homeLocation.getZ() + 0.5);
changeDimension(newWorld, new ITeleporter() {
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
return repositionEntity.apply(false);
}
@Override
public PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) {
return new PortalInfo(destination, Vector3d.ZERO, entity.yRot, entity.xRot);
}
@Override
public boolean playTeleportSound(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) {
return false;
}
});
}
}
}
Aggregations