use of io.izzel.arclight.common.bridge.entity.InternalEntityBridge in project Arclight by IzzelAliz.
the class EntityMixin_1_14 method changeDimension.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
@Nullable
public Entity changeDimension(DimensionType destination) {
BlockPos location = ((InternalEntityBridge) this).internal$capturedPos();
if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination))
return null;
if (!this.world.isRemote && !this.removed) {
this.world.getProfiler().startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
DimensionType dimensiontype = this.dimension;
ServerWorld serverworld = minecraftserver.func_71218_a(dimensiontype);
ServerWorld serverworld1 = minecraftserver.func_71218_a(destination);
if (serverworld1 == null) {
return null;
}
// this.dimension = destination;
// this.detach();
this.world.getProfiler().startSection("reposition");
Vec3d vec3d = this.getMotion();
float f = 0.0F;
BlockPos blockpos = location;
if (blockpos == null) {
if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
blockpos = serverworld1.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1.getSpawnPoint());
} else if (destination == DimensionType.THE_END) {
blockpos = serverworld1.getSpawnCoordinate();
} else {
double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1.getDimension().getMovementFactor();
double d0 = this.posX * movementFactor;
double d1 = this.posZ * movementFactor;
double d3 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minX() + 16.0D);
double d4 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minZ() + 16.0D);
double d5 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxX() - 16.0D);
double d6 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxZ() - 16.0D);
d0 = MathHelper.clamp(d0, d3, d5);
d1 = MathHelper.clamp(d1, d4, d6);
Vec3d vec3d1 = this.getLastPortalVec();
blockpos = new BlockPos(d0, this.posY, d1);
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1.getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
}
blockpos = new BlockPos(blockpattern$portalinfo.pos);
vec3d = blockpattern$portalinfo.motion;
f = (float) blockpattern$portalinfo.rotation;
}
}
if (location == null) {
Location enter = ((InternalEntityBridge) this).internal$getBukkitEntity().getLocation();
Location exit = new Location(((ServerWorldBridge) serverworld1).bridge$getWorld(), blockpos.getX(), blockpos.getY(), blockpos.getZ());
EntityPortalEvent event = new EntityPortalEvent(((InternalEntityBridge) this).internal$getBukkitEntity(), enter, exit);
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !this.isAlive()) {
return null;
}
exit = event.getTo();
serverworld1 = ((CraftWorld) exit.getWorld()).getHandle();
blockpos = new BlockPos(exit.getX(), exit.getY(), exit.getZ());
}
this.dimension = destination;
this.detach();
this.world.getProfiler().endStartSection("reloading");
Entity entity = this.getType().create(serverworld1);
if (entity != null) {
entity.copyDataFromOld((Entity) (Object) this);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
entity.setMotion(vec3d);
serverworld1.func_217460_e(entity);
((InternalEntityBridge) this).internal$getBukkitEntity().setHandle(entity);
((EntityBridge) entity).bridge$setBukkitEntity(((InternalEntityBridge) this).internal$getBukkitEntity());
if ((Object) this instanceof MobEntity) {
((MobEntity) (Object) this).clearLeashed(true, false);
}
}
this.remove(false);
this.world.getProfiler().endSection();
serverworld.resetUpdateEntityTick();
serverworld1.resetUpdateEntityTick();
this.world.getProfiler().endSection();
return entity;
} else {
return null;
}
}
use of io.izzel.arclight.common.bridge.entity.InternalEntityBridge in project Arclight by IzzelAliz.
the class EntityMixin_1_15 method changeDimension.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(DimensionType destination, ITeleporter teleporter) {
BlockPos location = ((InternalEntityBridge) this).internal$capturedPos();
if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination))
return null;
if (!this.world.isRemote && !this.removed) {
this.world.getProfiler().startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
DimensionType dimensiontype = this.dimension;
ServerWorld serverworld = minecraftserver.getWorld(dimensiontype);
ServerWorld[] serverworld1 = new ServerWorld[] { minecraftserver.getWorld(destination) };
if (serverworld1 == null) {
return null;
}
// this.dimension = destination;
// this.detach();
this.world.getProfiler().startSection("reposition");
Entity transportedEntity = teleporter.placeEntity((Entity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> {
// Forge: Start vanilla logic
Vec3d vec3d = this.getMotion();
float f = 0.0F;
BlockPos blockpos = location;
if (blockpos == null) {
if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint()), 0);
if (event == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
// blockpos = serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint());
} else if (destination == DimensionType.THE_END) {
EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], (serverworld1[0].getSpawnCoordinate() != null) ? serverworld1[0].getSpawnCoordinate() : serverworld1[0].getSpawnPoint(), 0);
if (event == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
// blockpos = serverworld1[0].getSpawnCoordinate();
} else {
double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
double d0 = this.getPosX() * movementFactor;
double d1 = this.getPosZ() * movementFactor;
double d3 = Math.min(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
double d4 = Math.min(-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, d3, d5);
d1 = MathHelper.clamp(d1, d4, d6);
Vec3d vec3d1 = this.getLastPortalVec();
blockpos = new BlockPos(d0, this.getPosY(), d1);
EntityPortalEvent event2 = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], blockpos, 128);
if (event2 == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event2.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event2.getTo().getX(), event2.getTo().getY(), event2.getTo().getZ());
int searchRadius = event2.getSearchRadius();
if (spawnPortal) {
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1[0].getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
}
blockpos = new BlockPos(blockpattern$portalinfo.pos);
vec3d = blockpattern$portalinfo.motion;
f = (float) blockpattern$portalinfo.rotation;
}
}
}
this.dimension = destination;
this.detach();
this.world.getProfiler().endStartSection("reloading");
Entity entity = this.getType().create(serverworld1[0]);
if (entity != null) {
entity.copyDataFromOld((Entity) (Object) this);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
entity.setMotion(vec3d);
serverworld1[0].addFromAnotherDimension(entity);
((InternalEntityBridge) this).internal$getBukkitEntity().setHandle(entity);
((EntityBridge) entity).bridge$setBukkitEntity(((InternalEntityBridge) this).internal$getBukkitEntity());
if ((Object) this instanceof MobEntity) {
((MobEntity) (Object) this).clearLeashed(true, false);
}
}
return entity;
});
// Forge: End vanilla logic
this.remove(false);
this.world.getProfiler().endSection();
serverworld.resetUpdateEntityTick();
serverworld1[0].resetUpdateEntityTick();
this.world.getProfiler().endSection();
return transportedEntity;
} else {
return null;
}
}
use of io.izzel.arclight.common.bridge.entity.InternalEntityBridge in project Arclight by IzzelAliz.
the class PlayerListMixin method recreatePlayerEntity.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ServerPlayerEntity recreatePlayerEntity(ServerPlayerEntity playerIn, DimensionType dimension, boolean conqueredEnd) {
Location location = arclight$loc;
arclight$loc = null;
boolean avoidSuffocation = arclight$suffo == null ? true : arclight$suffo;
arclight$suffo = null;
playerIn.stopRiding();
org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
ServerWorld world = server.getWorld(dimension);
if (world == null)
dimension = playerIn.getSpawnDimension();
else if (!world.getDimension().canRespawnHere())
dimension = world.getDimension().getRespawnDimension(playerIn);
if (server.getWorld(dimension) == null)
dimension = DimensionType.OVERWORLD;
this.removePlayer(playerIn);
// Forge: keep data until copyFrom called
playerIn.getServerWorld().removePlayer(playerIn, true);
BlockPos blockpos = playerIn.getBedLocation(dimension);
boolean flag = playerIn.isSpawnForced(dimension);
// playerIn.dimension = dimension;
PlayerInteractionManager playerinteractionmanager;
if (this.server.isDemo()) {
playerinteractionmanager = new DemoPlayerInteractionManager(this.server.getWorld(playerIn.dimension));
} else {
playerinteractionmanager = new PlayerInteractionManager(this.server.getWorld(playerIn.dimension));
}
playerIn.queuedEndExit = false;
if (location == null) {
boolean isBedSpawn = false;
CraftWorld cworld = (CraftWorld) Bukkit.getWorld(((PlayerEntityBridge) playerIn).bridge$getSpawnWorld());
if (cworld != null && blockpos != null) {
Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), blockpos, flag);
if (optional.isPresent()) {
Vec3d vec3d = optional.get();
isBedSpawn = true;
location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
} else {
this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
}
}
if (location == null) {
cworld = (CraftWorld) Bukkit.getWorlds().get(0);
blockpos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
location = new Location(cworld, blockpos.getX() + 0.5f, blockpos.getY() + 0.1f, blockpos.getZ() + 0.5f);
}
Player respawnPlayer = this.cserver.getPlayer(playerIn);
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
this.cserver.getPluginManager().callEvent(respawnEvent);
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
return playerIn;
}
location = respawnEvent.getRespawnLocation();
if (location.getWorld() == null) {
location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
}
dimension = ((CraftWorld) location.getWorld()).getHandle().dimension.getType();
if (!flag) {
((ServerPlayerEntityBridge) playerIn).bridge$reset();
}
} else {
location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
}
playerIn.dimension = dimension;
ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.server, this.server.getWorld(playerIn.dimension), playerIn.getGameProfile(), playerinteractionmanager);
// Forward to new player instance
((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity());
if ((Object) serverplayerentity instanceof MobEntity) {
((MobEntity) (Object) serverplayerentity).clearLeashed(true, false);
}
serverplayerentity.connection = playerIn.connection;
serverplayerentity.copyFrom(playerIn, conqueredEnd);
// Forge: clone event had a chance to see old data, now discard it
playerIn.remove(false);
serverplayerentity.dimension = dimension;
serverplayerentity.setEntityId(playerIn.getEntityId());
serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand());
for (String s : playerIn.getTags()) {
serverplayerentity.addTag(s);
}
ServerWorld serverworld = ((CraftWorld) location.getWorld()).getHandle();
serverplayerentity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
serverplayerentity.connection.captureCurrentPosition();
this.setPlayerGameTypeBasedOnOther(serverplayerentity, playerIn, serverworld);
while (avoidSuffocation && !this.bridge$worldNoCollision(serverworld, serverplayerentity) && serverplayerentity.posY < 256.0D) {
serverplayerentity.setPosition(serverplayerentity.posX, serverplayerentity.posY + 1.0D, serverplayerentity.posZ);
}
if (fromWorld.getEnvironment() == ((WorldBridge) serverworld).bridge$getWorld().getEnvironment()) {
serverplayerentity.connection.sendPacket(this.bridge$respawnPacket((((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverworld.getWorldInfo().getSeed(), serverworld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
}
WorldInfo worldinfo = serverplayerentity.world.getWorldInfo();
NetworkHooks.sendDimensionDataPacket(serverplayerentity.connection.netManager, serverplayerentity);
serverplayerentity.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType(), worldinfo.getSeed(), worldinfo.getGenerator(), serverplayerentity.interactionManager.getGameType()));
serverplayerentity.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverworld).bridge$spigotConfig().viewDistance));
BlockPos blockpos1 = serverworld.getSpawnPoint();
serverplayerentity.connection.setPlayerLocation(serverplayerentity.posX, serverplayerentity.posY, serverplayerentity.posZ, serverplayerentity.rotationYaw, serverplayerentity.rotationPitch);
serverplayerentity.connection.sendPacket(new SSpawnPositionPacket(blockpos1));
serverplayerentity.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
serverplayerentity.connection.sendPacket(new SSetExperiencePacket(serverplayerentity.experience, serverplayerentity.experienceTotal, serverplayerentity.experienceLevel));
this.sendWorldInfo(serverplayerentity, serverworld);
this.updatePermissionLevel(serverplayerentity);
if (!((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) {
serverworld.addRespawnedPlayer(serverplayerentity);
this.addPlayer(serverplayerentity);
this.uuidToPlayerMap.put(serverplayerentity.getUniqueID(), serverplayerentity);
}
serverplayerentity.addSelfToInternalCraftingInventory();
serverplayerentity.setHealth(serverplayerentity.getHealth());
this.sendInventory(serverplayerentity);
serverplayerentity.sendPlayerAbilities();
serverplayerentity.func_213846_b(((CraftWorld) fromWorld).getHandle());
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
Bukkit.getPluginManager().callEvent(event);
}
BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
System.out.println("pos " + serverplayerentity.getBedLocation());
return serverplayerentity;
}
Aggregations