use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class LivingEntityMixin method arclight$setScaled.
@Inject(method = "setHealth", cancellable = true, at = @At("HEAD"))
public void arclight$setScaled(float health, CallbackInfo ci) {
if (this instanceof ServerPlayerEntityBridge) {
CraftPlayer player = ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity();
player.setRealHealth(MathHelper.clamp(health, 0.0F, player.getMaxHealth()));
player.updateScaledHealth(false);
ci.cancel();
}
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ItemEntityMixin method onCollideWithPlayer.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entity) {
if (!this.world.isRemote) {
final ItemStack itemstack = this.getItem();
final net.minecraft.item.Item item = itemstack.getItem();
final int i = itemstack.getCount();
int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup((ItemEntity) (Object) this, entity);
if (hook < 0)
return;
ItemStack copy = itemstack.copy();
final int canHold = ((PlayerInventoryBridge) entity.inventory).bridge$canHold(itemstack);
final int remaining = i - canHold;
if (this.pickupDelay <= 0 && (hook == 1 || canHold > 0)) {
copy.setCount(canHold);
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerItemPickupEvent(entity, (ItemEntity) (Object) this, copy);
itemstack.setCount(canHold);
final PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
playerEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
Bukkit.getPluginManager().callEvent(playerEvent);
if (playerEvent.isCancelled()) {
itemstack.setCount(i);
return;
}
final EntityPickupItemEvent entityEvent = new EntityPickupItemEvent(((LivingEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
entityEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
Bukkit.getPluginManager().callEvent(entityEvent);
if (entityEvent.isCancelled()) {
itemstack.setCount(i);
return;
}
itemstack.setCount(canHold + remaining);
this.pickupDelay = 0;
} else if (this.pickupDelay == 0) {
this.pickupDelay = -1;
}
if (this.pickupDelay == 0 && (this.owner == null || /*|| 6000 - this.age <= 200*/
this.owner.equals(entity.getUniqueID())) && entity.inventory.addItemStackToInventory(itemstack)) {
entity.onItemPickup((ItemEntity) (Object) this, i);
if (itemstack.isEmpty()) {
this.remove();
itemstack.setCount(i);
}
entity.addStat(Stats.ITEM_PICKED_UP.get(item), i);
}
}
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class PlayerEntityMixin method attackTargetEntityWithCurrentItem.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void attackTargetEntityWithCurrentItem(final Entity entity) {
if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity))
return;
if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) {
float f = (float) this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getValue();
float f2;
if (entity instanceof LivingEntity) {
f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute());
} else {
f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED);
}
final float f3 = this.getCooledAttackStrength(0.5f);
f *= 0.2f + f3 * f3 * 0.8f;
f2 *= f3;
this.resetCooldown();
if (f > 0.0f || f2 > 0.0f) {
final boolean flag = f3 > 0.9f;
boolean flag2 = false;
final byte b0 = 0;
int i = b0 + EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this);
if (this.isSprinting() && flag) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f);
++i;
flag2 = true;
}
boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity;
net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F);
flag3 = hitResult != null;
if (flag3) {
f *= hitResult.getDamageModifier();
}
f += f2;
boolean flag4 = false;
final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified;
if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) {
final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND);
if (itemstack.getItem() instanceof SwordItem) {
flag4 = true;
}
}
float f4 = 0.0f;
boolean flag5 = false;
final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this);
if (entity instanceof LivingEntity) {
f4 = ((LivingEntity) entity).getHealth();
if (j > 0 && !entity.isBurning()) {
final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1);
Bukkit.getPluginManager().callEvent(combustEvent);
if (!combustEvent.isCancelled()) {
flag5 = true;
((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
}
}
}
final Vec3d vec3d = entity.getMotion();
final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f);
if (flag6) {
if (i > 0) {
if (entity instanceof LivingEntity) {
((LivingEntity) entity).knockBack((PlayerEntity) (Object) this, i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
} else {
entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f);
}
this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6));
this.setSprinting(false);
}
if (flag4) {
final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f;
final List<LivingEntity> list = this.world.getEntitiesWithinAABB((Class<? extends LivingEntity>) LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0));
for (final LivingEntity entityliving : list) {
if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) {
entityliving.knockBack((PlayerEntity) (Object) this, 0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
}
}
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f);
this.spawnSweepParticles();
}
if (entity instanceof ServerPlayerEntity && entity.velocityChanged) {
boolean cancelled = false;
final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
final Vector velocity = CraftVector.toBukkit(vec3d);
final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cancelled = true;
} else if (!velocity.equals(event.getVelocity())) {
player.setVelocity(event.getVelocity());
}
if (!cancelled) {
((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity));
entity.velocityChanged = false;
entity.setMotion(vec3d);
}
}
if (flag3) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f);
this.onCriticalHit(entity);
}
if (!flag3 && !flag4) {
if (flag) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f);
} else {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f);
}
}
if (f2 > 0.0f) {
this.onEnchantmentCritical(entity);
}
this.setLastAttackedEntity(entity);
if (entity instanceof LivingEntity) {
EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this);
}
EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity);
final ItemStack itemstack2 = this.getHeldItemMainhand();
Object object = entity;
if (entity instanceof EnderDragonPartEntity) {
object = ((EnderDragonPartEntity) entity).dragon;
}
if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) {
ItemStack copy = itemstack2.copy();
itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this);
if (itemstack2.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND);
this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
}
}
if (entity instanceof LivingEntity) {
final float f6 = f4 - ((LivingEntity) entity).getHealth();
this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f));
if (j > 0) {
final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4);
Bukkit.getPluginManager().callEvent(combustEvent2);
if (!combustEvent2.isCancelled()) {
((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false);
}
}
if (this.world instanceof ServerWorld && f6 > 2.0f) {
final int k = (int) (f6 * 0.5);
((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.posX, entity.posY + entity.getHeight() * 0.5f, entity.posZ, k, 0.1, 0.0, 0.1, 0.2);
}
}
this.addExhaustion(0.1f);
} else {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f);
if (flag5) {
entity.extinguish();
}
if (this instanceof ServerPlayerEntityBridge) {
((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory();
}
}
}
}
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class PlayerInteractionManagerMixin_1_15 method func_219441_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
BlockPos blockpos = blockRaytraceResultIn.getPos();
BlockState blockstate = worldIn.getBlockState(blockpos);
ActionResultType resultType = ActionResultType.PASS;
boolean cancelledBlock = false;
if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
cancelledBlock = !(provider instanceof INamedContainerProvider);
}
if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
cancelledBlock = true;
}
PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
bridge$setFiredInteract(true);
bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
if (blockstate.getBlock() instanceof DoorBlock) {
boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
} else if (blockstate.getBlock() instanceof CakeBlock) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
}
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
} else if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
if (inamedcontainerprovider != null) {
playerIn.openContainer(inamedcontainerprovider);
return ActionResultType.SUCCESS;
} else {
return ActionResultType.PASS;
}
} else {
net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
if (event.isCanceled())
return event.getCancellationResult();
ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
if (result != ActionResultType.PASS)
return result;
}
boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1) {
resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
if (resultType.isSuccessOrConsume()) {
return resultType;
}
}
if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
return ActionResultType.PASS;
}
if (this.isCreative()) {
int i = stackIn.getCount();
resultType = stackIn.onItemUse(itemusecontext);
stackIn.setCount(i);
return resultType;
} else {
return stackIn.onItemUse(itemusecontext);
}
} else {
return resultType;
}
}
return resultType;
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ChorusFruitItemMixin method onItemUseFinish.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);
if (!worldIn.isRemote) {
double d0 = entityLiving.posX;
double d1 = entityLiving.posY;
double d2 = entityLiving.posZ;
for (int i = 0; i < 16; ++i) {
double d3 = entityLiving.posX + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
double d4 = MathHelper.clamp(entityLiving.posY + (double) (entityLiving.getRNG().nextInt(16) - 8), 0.0D, (double) (worldIn.getActualHeight() - 1));
double d5 = entityLiving.posZ + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
if (entityLiving instanceof ServerPlayerEntity) {
Player player = ((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity();
PlayerTeleportEvent event = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), d3, d4, d5), PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
break;
}
d3 = event.getTo().getX();
d4 = event.getTo().getY();
d5 = event.getTo().getZ();
}
if (entityLiving.isPassenger()) {
entityLiving.stopRiding();
}
if (entityLiving.attemptTeleport(d3, d4, d5, true)) {
worldIn.playSound((PlayerEntity) null, d0, d1, d2, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
entityLiving.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
break;
}
}
if (entityLiving instanceof PlayerEntity) {
((PlayerEntity) entityLiving).getCooldownTracker().setCooldown(this, 20);
}
}
return itemstack;
}
Aggregations