use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class ServerPlayerEntityMixin method arclight$handleBy.
@Inject(method = "teleport", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/player/ServerPlayerEntity;stopRiding()V"))
private void arclight$handleBy(ServerWorld world, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) {
PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause;
arclight$cause = null;
this.getBukkitEntity().teleport(new Location(((WorldBridge) world).bridge$getWorld(), x, y, z, yaw, pitch), cause);
ci.cancel();
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class PotionEntityMixin method func_213888_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private void func_213888_a(List<EffectInstance> list, @Nullable Entity entity) {
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0, 2.0, 4.0);
List<LivingEntity> list2 = this.world.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb);
Map<org.bukkit.entity.LivingEntity, Double> affected = new HashMap<>();
if (!list2.isEmpty()) {
for (LivingEntity entityliving : list2) {
if (entityliving.canBeHitWithPotion()) {
double d0 = this.getDistanceSq(entityliving);
if (d0 >= 16.0) {
continue;
}
double d2 = 1.0 - Math.sqrt(d0) / 4.0;
if (entityliving == entity) {
d2 = 1.0;
}
affected.put(((LivingEntityBridge) entityliving).bridge$getBukkitEntity(), d2);
}
}
}
PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((PotionEntity) (Object) this, affected);
if (!event.isCancelled() && list != null && !list.isEmpty()) {
for (org.bukkit.entity.LivingEntity victim : event.getAffectedEntities()) {
if (!(victim instanceof CraftLivingEntity)) {
continue;
}
LivingEntity entityliving2 = ((CraftLivingEntity) victim).getHandle();
double d2 = event.getIntensity(victim);
for (EffectInstance mobeffect : list) {
Effect mobeffectlist = mobeffect.getPotion();
if (!((WorldBridge) this.world).bridge$isPvpMode() && this.getThrower() instanceof ServerPlayerEntity && entityliving2 instanceof ServerPlayerEntity && entityliving2 != this.getThrower()) {
int i = Effect.getId(mobeffectlist);
if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18) {
continue;
}
if (i == 19) {
continue;
}
}
if (mobeffectlist.isInstant()) {
mobeffectlist.affectEntity((PotionEntity) (Object) this, this.getThrower(), entityliving2, mobeffect.getAmplifier(), d2);
} else {
int i = (int) (d2 * mobeffect.getDuration() + 0.5);
if (i <= 20) {
continue;
}
((LivingEntityBridge) entityliving2).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.POTION_SPLASH);
entityliving2.addPotionEffect(new EffectInstance(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.doesShowParticles()));
}
}
}
}
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class AbstractMinecartEntityMixin method tick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
double prevX = this.posX;
double prevY = this.posY;
double prevZ = this.posZ;
float prevYaw = this.rotationYaw;
float prevPitch = this.rotationPitch;
if (this.getRollingAmplitude() > 0) {
this.setRollingAmplitude(this.getRollingAmplitude() - 1);
}
if (this.getDamage() > 0.0f) {
this.setDamage(this.getDamage() - 1.0f);
}
if (this.posY < -64.0) {
this.outOfWorld();
}
if (this.world.isRemote) {
if (this.turnProgress > 0) {
double d0 = this.posX + (this.minecartX - this.posX) / this.turnProgress;
double d2 = this.posY + (this.minecartY - this.posY) / this.turnProgress;
double d3 = this.posZ + (this.minecartZ - this.posZ) / this.turnProgress;
double d4 = MathHelper.wrapDegrees(this.minecartYaw - this.rotationYaw);
this.rotationYaw += (float) (d4 / this.turnProgress);
this.rotationPitch += (float) ((this.minecartPitch - this.rotationPitch) / this.turnProgress);
--this.turnProgress;
this.setPosition(d0, d2, d3);
this.setRotation(this.rotationYaw, this.rotationPitch);
} else {
this.setPosition(this.posX, this.posY, this.posZ);
this.setRotation(this.rotationYaw, this.rotationPitch);
}
} else {
/*
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
*/
if (!this.hasNoGravity()) {
this.setMotion(this.getMotion().add(0.0, -0.04, 0.0));
}
int i = MathHelper.floor(this.posX);
int j = MathHelper.floor(this.posY);
int k = MathHelper.floor(this.posZ);
if (this.world.getBlockState(new BlockPos(i, j - 1, k)).isIn(BlockTags.RAILS)) {
--j;
}
BlockPos blockposition = new BlockPos(i, j, k);
BlockState iblockdata = this.world.getBlockState(blockposition);
if (iblockdata.isIn(BlockTags.RAILS)) {
this.moveAlongTrack(blockposition, iblockdata);
if (iblockdata.getBlock() == Blocks.ACTIVATOR_RAIL) {
this.onActivatorRailPass(i, j, k, iblockdata.get(PoweredRailBlock.POWERED));
}
} else {
this.moveDerailedMinecart();
}
this.doBlockCollisions();
this.rotationPitch = 0.0f;
double d5 = this.prevPosX - this.posX;
double d6 = this.prevPosZ - this.posZ;
if (d5 * d5 + d6 * d6 > 0.001) {
this.rotationYaw = (float) (MathHelper.atan2(d6, d5) * 180.0 / 3.141592653589793);
if (this.isInReverse) {
this.rotationYaw += 180.0f;
}
}
double d7 = MathHelper.wrapDegrees(this.rotationYaw - this.prevRotationYaw);
if (d7 < -170.0 || d7 >= 170.0) {
this.rotationYaw += 180.0f;
this.isInReverse = !this.isInReverse;
}
this.setRotation(this.rotationYaw, this.rotationPitch);
org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
Location to = new Location(bworld, this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
if (!from.equals(to)) {
Bukkit.getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to));
}
if (this.getMinecartType() == AbstractMinecartEntity.Type.RIDEABLE && Entity.horizontalMag(this.getMotion()) > 0.01) {
List<Entity> list = this.world.getEntitiesInAABBexcluding((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224), EntityPredicates.pushableBy((AbstractMinecartEntity) (Object) this));
if (!list.isEmpty()) {
for (Entity entity : list) {
if (!(entity instanceof PlayerEntity) && !(entity instanceof IronGolemEntity) && !(entity instanceof AbstractMinecartEntity) && !this.isBeingRidden() && !entity.isPassenger()) {
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent);
if (!collisionEvent.isCancelled()) {
entity.startRiding((AbstractMinecartEntity) (Object) this);
}
} else {
if (!isRidingSameEntity(entity)) {
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent);
if (collisionEvent.isCancelled()) {
continue;
}
}
entity.applyEntityCollision((AbstractMinecartEntity) (Object) this);
}
}
}
} else {
for (Entity entity2 : this.world.getEntitiesWithinAABBExcludingEntity((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224))) {
if (!this.isPassenger(entity2) && entity2.canBePushed() && entity2 instanceof AbstractMinecartEntity) {
VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity2).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent2);
if (collisionEvent2.isCancelled()) {
continue;
}
entity2.applyEntityCollision((AbstractMinecartEntity) (Object) this);
}
}
}
this.handleWaterMovement();
}
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class FoxEntity_MateGoalMixin method spawnBaby.
/**
* @author IzzekAkuz
* @reason
*/
@Overwrite
protected void spawnBaby() {
FoxEntity foxentity = (FoxEntity) this.animal.createChild(this.targetMate);
if (foxentity != null) {
ServerPlayerEntity serverplayerentity = this.animal.getLoveCause();
ServerPlayerEntity serverplayerentity1 = this.targetMate.getLoveCause();
ServerPlayerEntity serverplayerentity2 = serverplayerentity;
if (serverplayerentity != null) {
((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUniqueID());
} else {
serverplayerentity2 = serverplayerentity1;
}
if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) {
((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUniqueID());
}
int experience = this.animal.getRNG().nextInt(7) + 1;
final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.targetMate, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience);
if (entityBreedEvent.isCancelled()) {
return;
}
experience = entityBreedEvent.getExperience();
if (serverplayerentity2 != null) {
serverplayerentity2.addStat(Stats.ANIMALS_BRED);
CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.targetMate, foxentity);
}
int i = 6000;
this.animal.setGrowingAge(6000);
this.targetMate.setGrowingAge(6000);
this.animal.resetInLove();
this.targetMate.resetInLove();
foxentity.setGrowingAge(-24000);
foxentity.setLocationAndAngles(this.animal.posX, this.animal.posY, this.animal.posZ, 0.0F, 0.0F);
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING);
this.world.addEntity(foxentity);
this.world.setEntityState(this.animal, (byte) 18);
if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
if (experience > 0) {
this.world.addEntity(new ExperienceOrbEntity(this.world, this.animal.posX, this.animal.posY, this.animal.posZ, experience));
}
}
}
}
use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.
the class PlayerListMixin method moveToWorld.
public ServerPlayerEntity moveToWorld(ServerPlayerEntity playerIn, DimensionType type, boolean flag, Location location, boolean avoidSuffocation) {
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(playerIn, type))
return playerIn;
playerIn.stopRiding();
this.players.remove(playerIn);
// this.playersByName.remove(playerIn.getScoreboardName().toLowerCase(Locale.ROOT));
playerIn.getServerWorld().removePlayer(playerIn, true);
BlockPos pos = playerIn.getBedLocation(type);
boolean flag2 = playerIn.isSpawnForced(type);
org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
playerIn.queuedEndExit = false;
playerIn.copyFrom(playerIn, flag);
playerIn.setEntityId(playerIn.getEntityId());
playerIn.setPrimaryHand(playerIn.getPrimaryHand());
for (String s : playerIn.getTags()) {
playerIn.addTag(s);
}
if (location == null) {
boolean isBedSpawn = false;
CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(((ServerPlayerEntityBridge) playerIn).bridge$getSpawnWorld());
if (cworld != null && pos != null) {
Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), pos, flag2);
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.getServer().getWorlds().get(0);
pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
location = new Location(cworld, pos.getX() + 0.5f, pos.getY() + 0.1f, pos.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 (!flag) {
((ServerPlayerEntityBridge) playerIn).bridge$reset();
}
} else {
location.setWorld(((WorldBridge) this.server.getWorld(type)).bridge$getWorld());
}
ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle();
playerIn.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
playerIn.connection.captureCurrentPosition();
while (avoidSuffocation && !serverWorld.hasNoCollisions(playerIn) && playerIn.getPosY() < 256.0) {
playerIn.setPosition(playerIn.getPosX(), playerIn.getPosY() + 1.0, playerIn.getPosZ());
}
if (fromWorld.getEnvironment() == ((WorldBridge) serverWorld).bridge$getWorld().getEnvironment()) {
playerIn.connection.sendPacket(this.bridge$respawnPacket((serverWorld.dimension.getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
}
WorldInfo worldInfo = serverWorld.getWorldInfo();
net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(playerIn.connection.netManager, playerIn);
playerIn.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType(), serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
playerIn.connection.sendPacket(new SUpdateViewDistancePacket(((ServerWorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
playerIn.setWorld(serverWorld);
playerIn.interactionManager.setWorld(serverWorld);
playerIn.revive();
((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), playerIn.rotationYaw, playerIn.rotationPitch));
playerIn.setSneaking(false);
BlockPos pos1 = serverWorld.getSpawnPoint();
playerIn.connection.sendPacket(new SSpawnPositionPacket(pos1));
playerIn.connection.sendPacket(new SServerDifficultyPacket(worldInfo.getDifficulty(), worldInfo.isDifficultyLocked()));
playerIn.connection.sendPacket(new SSetExperiencePacket(playerIn.experience, playerIn.experienceTotal, playerIn.experienceLevel));
this.sendWorldInfo(playerIn, serverWorld);
this.updatePermissionLevel(playerIn);
if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
serverWorld.addRespawnedPlayer(playerIn);
this.players.add(playerIn);
// this.playersByName.put(entityplayer2.getScoreboardName().toLowerCase(Locale.ROOT), entityplayer2);
this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
}
playerIn.setHealth(playerIn.getHealth());
this.sendInventory(playerIn);
playerIn.sendPlayerAbilities();
for (Object o1 : playerIn.getActivePotionEffects()) {
EffectInstance mobEffect = (EffectInstance) o1;
playerIn.connection.sendPacket(new SPlayEntityEffectPacket(playerIn.getEntityId(), mobEffect));
}
playerIn.func_213846_b(((CraftWorld) fromWorld).getHandle());
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
Bukkit.getPluginManager().callEvent(event);
}
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
this.writePlayerData(playerIn);
}
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(playerIn, flag);
return playerIn;
}
Aggregations