use of net.minecraft.entity.projectile.AbstractArrowEntity in project bioplethora by AquexTheSeal.
the class ArbitraryBallistaItem method getArrow.
private static AbstractArrowEntity getArrow(World world, LivingEntity entity, ItemStack stack, ItemStack stack1) {
ArrowItem arrowitem = (ArrowItem) (stack1.getItem() instanceof ArrowItem ? stack1.getItem() : Items.ARROW);
AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(world, stack1, entity);
if (entity instanceof PlayerEntity) {
abstractarrowentity.setCritArrow(true);
}
abstractarrowentity.setSoundEvent(SoundEvents.CROSSBOW_HIT);
abstractarrowentity.setShotFromCrossbow(true);
abstractarrowentity.setNoGravity(true);
abstractarrowentity.setBaseDamage(abstractarrowentity.getBaseDamage() + 3);
int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PIERCING, stack);
if (i > 0) {
abstractarrowentity.setPierceLevel((byte) i);
}
return abstractarrowentity;
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project Arclight by IzzelAliz.
the class BowItemMixin method onPlayerStoppedUsing.
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
if (entityLiving instanceof PlayerEntity) {
PlayerEntity playerentity = (PlayerEntity) entityLiving;
boolean flag = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = playerentity.findAmmo(stack);
int i = this.getUseDuration(stack) - timeLeft;
i = ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag);
if (i < 0)
return;
if (!itemstack.isEmpty() || flag) {
if (itemstack.isEmpty()) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if (!((double) f < 0.1D)) {
boolean flag1 = playerentity.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
if (!worldIn.isRemote) {
ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity);
abstractarrowentity = customeArrow(abstractarrowentity);
abstractarrowentity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
abstractarrowentity.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
abstractarrowentity.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
abstractarrowentity.setFire(100);
}
EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(playerentity, itemstack, abstractarrowentity, f);
if (event.isCancelled()) {
event.getProjectile().remove();
return;
}
stack.damageItem(1, playerentity, (p_220009_1_) -> {
p_220009_1_.sendBreakAnimation(playerentity.getActiveHand());
});
if (flag1 || playerentity.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
}
if (event.getProjectile() == ((EntityBridge) abstractarrowentity).bridge$getBukkitEntity()) {
if (!worldIn.addEntity(abstractarrowentity)) {
if (playerentity instanceof ServerPlayerEntityBridge) {
((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity().updateInventory();
}
return;
}
}
}
worldIn.playSound((PlayerEntity) null, playerentity.posX, playerentity.posY, playerentity.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !playerentity.abilities.isCreativeMode) {
itemstack.shrink(1);
if (itemstack.isEmpty()) {
playerentity.inventory.deleteStack(itemstack);
}
}
playerentity.addStat(Stats.ITEM_USED.get(this));
}
}
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project Arclight by IzzelAliz.
the class AbstractArrowEntityMixin method onCollideWithPlayer.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entityhuman) {
if (!this.world.isRemote && (this.inGround || this.getNoClip()) && this.arrowShake <= 0) {
ItemStack itemstack = this.getArrowStack();
if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) entityhuman.inventory).bridge$canHold(itemstack) > 0) {
final ItemEntity item = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
final PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (AbstractArrowEntity) (Object) this, item), (AbstractArrow) this.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
itemstack = item.getItem();
}
boolean flag = this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED || (this.pickupStatus == AbstractArrowEntity.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.isCreativeMode) || (this.getNoClip() && this.getShooter().getUniqueID() == entityhuman.getUniqueID());
if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !entityhuman.inventory.addItemStackToInventory(itemstack)) {
flag = false;
}
if (flag) {
entityhuman.onItemPickup((AbstractArrowEntity) (Object) this, 1);
this.remove();
}
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project Arclight by IzzelAliz.
the class TrackedEntityMixin method tick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
List<Entity> list = this.trackedEntity.getPassengers();
if (!list.equals(this.passengers)) {
this.passengers = list;
this.sendPacket(new SSetPassengersPacket(this.trackedEntity));
}
if (this.trackedEntity instanceof ItemFrameEntity) {
ItemFrameEntity entityitemframe = (ItemFrameEntity) this.trackedEntity;
ItemStack itemstack = entityitemframe.getDisplayedItem();
if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof FilledMapItem) {
MapData worldmap = FilledMapItem.getMapData(itemstack, this.world);
for (ServerPlayerEntity entityplayer : this.trackedPlayers) {
worldmap.updateVisiblePlayers(entityplayer, itemstack);
IPacket<?> packet = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, entityplayer);
if (packet != null) {
entityplayer.connection.sendPacket(packet);
}
}
}
this.sendMetadata();
}
if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) {
if (this.trackedEntity.isPassenger()) {
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
boolean flag = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag) {
this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround));
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
}
this.updateEncodedPosition();
this.sendMetadata();
this.riding = true;
} else {
++this.ticksSinceAbsoluteTeleport;
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
Vec3d vec3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
boolean flag2 = vec3d.lengthSquared() >= 7.62939453125E-6;
IPacket<?> packet2 = null;
boolean flag3 = flag2 || this.updateCounter % 60 == 0;
boolean flag4 = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag3) {
this.updateEncodedPosition();
}
if (flag4) {
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
}
if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) {
long k = SEntityPacket.func_218743_a(vec3d.x);
long l = SEntityPacket.func_218743_a(vec3d.y);
long i2 = SEntityPacket.func_218743_a(vec3d.z);
boolean flag5 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i2 < -32768L || i2 > 32767L;
if (!flag5 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.onGround) {
if ((!flag3 || !flag4) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
if (flag3) {
packet2 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, this.trackedEntity.onGround);
} else if (flag4) {
packet2 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround);
}
} else {
packet2 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, (byte) i, (byte) j, this.trackedEntity.onGround);
}
} else {
this.onGround = this.trackedEntity.onGround;
this.ticksSinceAbsoluteTeleport = 0;
packet2 = new SEntityTeleportPacket(this.trackedEntity);
}
}
if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || (this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying())) && this.updateCounter > 0) {
Vec3d vec3d2 = this.trackedEntity.getMotion();
double d0 = vec3d2.squareDistanceTo(this.velocity);
if (d0 > 1.0E-7 || (d0 > 0.0 && vec3d2.lengthSquared() == 0.0)) {
this.velocity = vec3d2;
this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
}
}
if (packet2 != null) {
this.packetConsumer.accept(packet2);
}
this.sendMetadata();
this.riding = false;
}
int i = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
if (Math.abs(i - this.encodedRotationYawHead) >= 1) {
this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) i));
this.encodedRotationYawHead = i;
}
this.trackedEntity.isAirBorne = false;
}
++this.updateCounter;
if (this.trackedEntity.velocityChanged) {
boolean cancelled = false;
if (this.trackedEntity instanceof ServerPlayerEntity) {
Player player = ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity();
Vector velocity = player.getVelocity();
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) {
this.sendPacket(new SEntityVelocityPacket(this.trackedEntity));
}
this.trackedEntity.velocityChanged = false;
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processUseEntity.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processUseEntity(final CUseEntityPacket packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
final ServerWorld world = this.minecraftServer.getWorld(this.player.dimension);
final Entity entity = packetIn.getEntityFromWorld(world);
this.player.markPlayerActive();
if (entity != null) {
final boolean flag = this.player.canEntityBeSeen(entity);
double d0 = 36.0;
if (!flag) {
d0 = 9.0;
}
if (this.player.getDistanceSq(entity) < d0) {
final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand());
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity;
final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem();
PlayerInteractEntityEvent event;
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
} else {
final Vec3d target = packetIn.getHitVec();
event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
}
this.server.getPluginManager().callEvent(event);
if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SSpawnMobPacket((LivingEntity) entity));
this.player.sendContainerToPlayer(this.player.openContainer);
}
if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder()));
}
if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) {
this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true));
}
if (event.isCancelled()) {
return;
}
}
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
final Hand hand = packetIn.getHand();
this.player.interactOn(entity, hand);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final Hand hand = packetIn.getHand();
if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null)
return;
ActionResultType result = entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand);
if (result == ActionResultType.SUCCESS) {
this.player.swingArm(hand);
}
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) {
if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) {
this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked"));
this.minecraftServer.logWarning("Player " + this.player.getName().getString() + " tried to attack an invalid entity");
return;
}
this.player.attackTargetEntityWithCurrentItem(entity);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
}
}
}
}
Aggregations