use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class TeleportCommandMixin_1_15 method teleport.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private static void teleport(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().registerTicket(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
entityIn.stopRiding();
if (((ServerPlayerEntity) entityIn).isSleeping()) {
((ServerPlayerEntity) entityIn).stopSleepInBed(true, true);
}
((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).teleport(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.addFromAnotherDimension(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 HopperTileEntityMixin method arclight$pickupItem.
@Inject(method = "captureItem", cancellable = true, at = @At("HEAD"))
private static void arclight$pickupItem(IInventory inventory, ItemEntity itemEntity, CallbackInfoReturnable<Boolean> cir) {
InventoryPickupItemEvent event = new InventoryPickupItemEvent(((IInventoryBridge) inventory).getOwner().getInventory(), (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cir.setReturnValue(false);
}
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class ExplosionMixin method doExplosionA.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void doExplosionA() {
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.world.getBlockState(blockpos);
IFluidState ifluidstate = this.world.getFluidState(blockpos);
if (!blockstate.isAir(this.world, blockpos) || !ifluidstate.isEmpty()) {
float f2 = Math.max(blockstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this), ifluidstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this));
if (this.exploder != null) {
f2 = this.exploder.getExplosionResistance((Explosion) (Object) this, this.world, blockpos, blockstate, ifluidstate, f2);
}
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock((Explosion) (Object) this, this.world, blockpos, blockstate, f))) {
set.add(blockpos);
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
float f3 = this.size * 2.0F;
int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, (Explosion) (Object) this, list, f3);
Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
for (Entity entity : list) {
if (!entity.isImmuneToExplosions()) {
double d12 = MathHelper.sqrt(entity.getDistanceSq(vec3d)) / f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.x;
double d7 = ((EntityBridge) entity).bridge$getEyeHeight() - this.y;
double d9 = entity.posZ - this.z;
double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = Explosion.getBlockDensity(vec3d, entity);
double d10 = (1.0D - d12) * d14;
CraftEventFactory.entityDamage = this.exploder;
((EntityBridge) entity).bridge$setForceExplosionKnockback(false);
boolean wasDamaged = entity.attackEntityFrom(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
CraftEventFactory.entityDamage = null;
if (!wasDamaged && !(entity instanceof TNTEntity || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) {
continue;
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getBlastDamageReduction((LivingEntity) entity, d10);
}
entity.setMotion(entity.getMotion().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof PlayerEntity) {
PlayerEntity playerentity = (PlayerEntity) entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.isFlying)) {
this.playerKnockbackMap.put(playerentity, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class FishingRodItemMixin method onItemRightClick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (playerIn.fishingBobber != null) {
if (!worldIn.isRemote) {
int i = playerIn.fishingBobber.handleHookRetraction(itemstack);
itemstack.damageItem(i, playerIn, (p_220000_1_) -> {
p_220000_1_.sendBreakAnimation(handIn);
});
}
playerIn.swingArm(handIn);
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_FISHING_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
} else {
if (!worldIn.isRemote) {
int k = EnchantmentHelper.getFishingSpeedBonus(itemstack);
int j = EnchantmentHelper.getFishingLuckBonus(itemstack);
FishingBobberEntity hook = new FishingBobberEntity(playerIn, worldIn, j, k);
PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), null, (FishHook) ((EntityBridge) hook).bridge$getBukkitEntity(), PlayerFishEvent.State.FISHING);
Bukkit.getPluginManager().callEvent(playerFishEvent);
if (playerFishEvent.isCancelled()) {
playerIn.fishingBobber = null;
return new ActionResult<>(ActionResultType.PASS, itemstack);
}
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
worldIn.addEntity(new FishingBobberEntity(playerIn, worldIn, j, k));
}
// playerIn.swingArm(handIn);
playerIn.addStat(Stats.ITEM_USED.get(this));
}
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}
use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.
the class CrossbowItemMixin method arclight$entityShoot.
@Inject(method = "fireProjectile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damageItem(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
private static void arclight$entityShoot(World worldIn, LivingEntity shooter, Hand handIn, ItemStack crossbow, ItemStack projectile, float soundPitch, boolean isCreativeMode, float velocity, float inaccuracy, float projectileAngle, CallbackInfo ci, boolean flag, IProjectile proj) {
EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(shooter, crossbow, (Entity) proj, soundPitch);
if (event.isCancelled()) {
event.getProjectile().remove();
ci.cancel();
}
arclight$capturedBoolean = event.getProjectile() == ((EntityBridge) proj).bridge$getBukkitEntity();
}
Aggregations