use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class SmallFireballEntityMixin method onImpact.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
protected void onImpact(RayTraceResult result) {
if (ArclightVersion.atLeast(ArclightVersion.v1_15)) {
super.onImpact(result);
}
if (!this.world.isRemote) {
if (result.getType() == RayTraceResult.Type.ENTITY) {
Entity entity = ((EntityRayTraceResult) result).getEntity();
if (!entity.isImmuneToFire()) {
int i = entity.getFireTimer();
if (isIncendiary) {
EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 5);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false);
}
}
boolean flag = entity.attackEntityFrom(DamageSource.causeFireballDamage((SmallFireballEntity) (Object) this, this.shootingEntity), 5.0F);
if (flag) {
this.applyEnchantments(this.shootingEntity, entity);
} else {
entity.setFireTimer(i);
}
}
} else if (isIncendiary && this.shootingEntity == null || !(this.shootingEntity instanceof MobEntity) || ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity)) {
BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) result;
BlockPos blockpos = blockraytraceresult.getPos().offset(blockraytraceresult.getFace());
if (this.world.isAirBlock(blockpos) && !CraftEventFactory.callBlockIgniteEvent(this.world, blockpos, (SmallFireballEntity) (Object) this).isCancelled()) {
this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
}
}
this.remove();
}
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge 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.EntityBridge in project Arclight by IzzelAliz.
the class TeleportCommandMixin_1_14 method func_201127_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private static void func_201127_a(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable TeleportCommand.Facing facing) {
if (entityIn instanceof ServerPlayerEntity) {
ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
worldIn.getChunkProvider().func_217228_a(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
entityIn.stopRiding();
if (((ServerPlayerEntity) entityIn).isSleeping()) {
((ServerPlayerEntity) entityIn).wakeUpPlayer(true, true, false);
}
((ServerPlayNetHandlerBridge) ((ServerPlayerEntity) entityIn).connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.COMMAND);
if (worldIn == entityIn.world) {
((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
} else {
((ServerPlayerEntity) entityIn).func_200619_a(worldIn, x, y, z, yaw, pitch);
}
entityIn.setRotationYawHead(yaw);
} else {
float f1 = MathHelper.wrapDegrees(yaw);
float f = MathHelper.wrapDegrees(pitch);
f = MathHelper.clamp(f, -90.0F, 90.0F);
Location to = new Location(((ServerWorldBridge) worldIn).bridge$getWorld(), x, y, z, f1, f);
EntityTeleportEvent event = new EntityTeleportEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity().getLocation(), to);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
to = event.getTo();
x = to.getX();
y = to.getY();
z = to.getZ();
f1 = to.getYaw();
f = to.getPitch();
worldIn = ((CraftWorld) to.getWorld()).getHandle();
if (worldIn == entityIn.world) {
entityIn.setLocationAndAngles(x, y, z, f1, f);
entityIn.setRotationYawHead(f1);
} else {
entityIn.detach();
entityIn.dimension = worldIn.dimension.getType();
Entity entity = entityIn;
entityIn = entityIn.getType().create(worldIn);
if (entityIn == null) {
return;
}
entityIn.copyDataFromOld(entity);
entityIn.setLocationAndAngles(x, y, z, f1, f);
entityIn.setRotationYawHead(f1);
worldIn.func_217460_e(entityIn);
entity.removed = true;
}
}
if (facing != null) {
facing.updateLook(source, entityIn);
}
if (!(entityIn instanceof LivingEntity) || !((LivingEntity) entityIn).isElytraFlying()) {
entityIn.setMotion(entityIn.getMotion().mul(1.0D, 0.0D, 1.0D));
entityIn.onGround = true;
}
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class CauldronBlockMixin_1_14 method changeLevel.
private boolean changeLevel(World world, BlockPos pos, BlockState state, int i, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) {
int newLevel = MathHelper.clamp(i, 0, 3);
CauldronLevelChangeEvent event = new CauldronLevelChangeEvent(CraftBlock.at(world, pos), (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), reason, state.get(CauldronBlock.LEVEL), newLevel);
Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled();
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class AbstractArrowEntityMixin method arclight$fireShot.
@Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V"))
private void arclight$fireShot(Entity entity, int seconds, EntityRayTraceResult result) {
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds);
Bukkit.getPluginManager().callEvent(combustEvent);
if (!combustEvent.isCancelled()) {
((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
}
}
Aggregations