use of net.minecraft.entity.projectile.EntityArrow in project MorePlanets by SteveKunG.
the class BehaviorProjectileDispenseMP method getProjectileEntity.
@Override
protected IProjectile getProjectileEntity(World world, IPosition pos, ItemStack itemStack) {
if (this.isArrow) {
try {
EntityArrow arrow = (EntityArrow) this.projectile.getConstructor(World.class, double.class, double.class, double.class).newInstance(world, pos.getX(), pos.getY(), pos.getZ());
arrow.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
return arrow;
} catch (Exception e) {
}
} else {
try {
return this.projectile.getConstructor(World.class, double.class, double.class, double.class).newInstance(world, pos.getX(), pos.getY(), pos.getZ());
} catch (Exception e) {
}
}
return null;
}
use of net.minecraft.entity.projectile.EntityArrow in project MorePlanets by SteveKunG.
the class TileEntityJuicerEgg method update.
@Override
public void update() {
super.update();
if (!this.world.isRemote) {
double radius = 1.05D;
double radiusPlayer = 5.0D;
List<Entity> list = this.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(this.pos.getX() - radius, this.pos.getY() - radius, this.pos.getZ() - radius, this.pos.getX() + radius, this.pos.getY() + radius, this.pos.getZ() + radius));
List<EntityPlayer> playerList = this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - radiusPlayer, this.pos.getY() - radiusPlayer, this.pos.getZ() - radiusPlayer, this.pos.getX() + radiusPlayer, this.pos.getY() + radiusPlayer, this.pos.getZ() + radiusPlayer));
if (!list.isEmpty()) {
for (Entity entity : list) {
if (entity instanceof EntityArrow) {
EntityArrow arrow = (EntityArrow) entity;
if (arrow.inTile == NibiruBlocks.JUICER_EGG) {
arrow.setDead();
this.world.destroyBlock(this.pos, false);
if (this.world.rand.nextInt(5) == 0) {
EntityJuicer juicer = new EntityJuicer(this.world);
juicer.setLocationAndAngles(this.pos.getX() + 0.5D, this.pos.getY() + 1.0D, this.pos.getZ() + 0.5D, 0.0F, 0.0F);
this.world.spawnEntity(juicer);
}
if (this.world.rand.nextInt(10) == 0) {
if (!playerList.isEmpty()) {
for (EntityPlayer player : playerList) {
EntityJuicer juicer = new EntityJuicer(this.world);
juicer.setLocationAndAngles(this.pos.getX() + 0.5D, this.pos.getY() + 1.0D, this.pos.getZ() + 0.5D, 0.0F, 0.0F);
this.world.spawnEntity(juicer);
juicer.startRiding(player);
}
}
}
}
}
}
}
}
}
use of net.minecraft.entity.projectile.EntityArrow in project SpongeCommon by SpongePowered.
the class MixinNetHandlerPlayServer method processUseEntity.
/**
* @author blood - April 5th, 2016
*
* @reason Due to all the changes we now do for this packet, it is much easier
* to read it all with an overwrite. Information detailing on why each change
* was made can be found in comments below.
*
* @param packetIn The entity use packet
*/
@Overwrite
public void processUseEntity(CPacketUseEntity packetIn) {
// All packets received by server are handled first on the Netty Thread
if (!SpongeImpl.getServer().isCallingFromMinecraftThread()) {
if (packetIn.getAction() == CPacketUseEntity.Action.INTERACT) {
// when INTERACT_AT does not return a successful result.
return;
} else {
// queue packet for main thread
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayServer) (Object) this, this.player.getServerWorld());
return;
}
}
// Sponge end
WorldServer worldserver = this.serverController.getWorld(this.player.dimension);
Entity entity = packetIn.getEntityFromWorld(worldserver);
this.player.markPlayerActive();
if (entity != null) {
boolean flag = this.player.canEntityBeSeen(entity);
// 6 blocks
double d0 = 36.0D;
if (!flag) {
// 1.5 blocks
d0 = 9.0D;
}
if (this.player.getDistanceSq(entity) < d0) {
if (packetIn.getAction() == CPacketUseEntity.Action.INTERACT_AT) {
// Sponge start - Fire interact events
EnumHand hand = packetIn.getHand();
ItemStack itemstack = hand != null ? this.player.getHeldItem(hand) : ItemStack.EMPTY;
Sponge.getCauseStackManager().addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(itemstack));
SpongeCommonEventFactory.lastSecondaryPacketTick = this.serverController.getTickCounter();
// Is interaction allowed with item in hand
if (SpongeCommonEventFactory.callInteractItemEventSecondary(this.player, itemstack, hand, VecHelper.toVector3d(packetIn.getHitVec()), entity).isCancelled() || SpongeCommonEventFactory.callInteractEntityEventSecondary(this.player, entity, hand, VecHelper.toVector3d(entity.getPositionVector().add(packetIn.getHitVec()))).isCancelled()) {
// Restore held item in hand
int index = ((IMixinInventoryPlayer) this.player.inventory).getHeldItemIndex(hand);
Slot slot = this.player.openContainer.getSlotFromInventory(this.player.inventory, index);
sendPacket(new SPacketSetSlot(this.player.openContainer.windowId, slot.slotNumber, itemstack));
// which means that we need to force an update
if (itemstack.getItem() == Items.LEAD) {
// Detach entity again
sendPacket(new SPacketEntityAttach(entity, null));
} else {
// Other cases may involve a specific DataParameter of the entity
// We fix the client state by marking it as dirty so it will be updated on the client the next tick
DataParameter<?> parameter = findModifiedEntityInteractDataParameter(itemstack, entity);
if (parameter != null) {
entity.getDataManager().setDirty(parameter);
}
}
return;
}
// If INTERACT_AT is not successful, run the INTERACT logic
if (entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand) != EnumActionResult.SUCCESS) {
this.player.interactOn(entity, hand);
}
// Sponge end
} else if (packetIn.getAction() == CPacketUseEntity.Action.ATTACK) {
// Sponge start - Call interact event
// Will be null in the packet during ATTACK
EnumHand hand = EnumHand.MAIN_HAND;
ItemStack itemstack = this.player.getHeldItem(hand);
SpongeCommonEventFactory.lastPrimaryPacketTick = this.serverController.getTickCounter();
Vector3d hitVec = null;
if (packetIn.getHitVec() == null) {
final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player));
hitVec = result == null ? null : VecHelper.toVector3d(result.hitVec);
}
if (SpongeCommonEventFactory.callInteractItemEventPrimary(this.player, itemstack, hand, hitVec, entity).isCancelled()) {
((IMixinEntityPlayerMP) this.player).restorePacketItem(hand);
return;
}
if (entity instanceof EntityItem || entity instanceof EntityXPOrb || entity instanceof EntityArrow || entity == this.player) {
this.disconnect(new TextComponentTranslation("multiplayer.disconnect.invalid_entity_attacked"));
this.serverController.logWarning("Player " + this.player.getName() + " tried to attack an invalid entity");
return;
}
// Sponge start
if (entity instanceof Player && !((World) this.player.world).getProperties().isPVPEnabled()) {
// PVP is disabled, ignore
return;
}
if (SpongeCommonEventFactory.callInteractEntityEventPrimary(this.player, entity, hand, hitVec).isCancelled()) {
((IMixinEntityPlayerMP) this.player).restorePacketItem(hand);
return;
}
// Sponge end
this.player.attackTargetEntityWithCurrentItem(entity);
}
}
}
}
use of net.minecraft.entity.projectile.EntityArrow in project SilentGems by SilentChaos512.
the class ItemQuiver method createArrow.
@Override
public EntityArrow createArrow(World worldIn, ItemStack quiverStack, EntityLivingBase shooter) {
IItemHandler itemHandler = getInventory(quiverStack);
for (int i = 0; i < itemHandler.getSlots(); ++i) {
ItemStack arrowStack = itemHandler.getStackInSlot(i);
if (!StackHelper.isEmpty(arrowStack) && arrowStack.getItem() instanceof ItemArrow) {
// Found arrow stack in quiver
boolean playerIsCreativeMode = shooter instanceof EntityPlayer && ((EntityPlayer) shooter).capabilities.isCreativeMode;
if (!playerIsCreativeMode) {
// Remove arrow from quiver
itemHandler.extractItem(i, 1, false);
updateQuiver(quiverStack, itemHandler, (EntityPlayer) shooter);
}
// Create arrow entity
ItemArrow itemArrow = (ItemArrow) arrowStack.getItem();
EntityArrow entity = itemArrow.createArrow(worldIn, arrowStack, shooter);
if (!playerIsCreativeMode) {
QuiverHelper.instance.addFiredArrow(entity);
}
return entity;
}
}
// Something went wrong?
SilentGems.logHelper.warning("Quiver could not find arrow! Player: " + shooter.getName());
return new EntityTippedArrow(worldIn, shooter);
}
use of net.minecraft.entity.projectile.EntityArrow in project Skree by Skelril.
the class ICustomBow method onPlayerStoppedUsing.
/**
* Called when the player stops using an Item (stops holding the right mouse button).
*
* @param timeLeft The amount of ticks left before the using would have been complete
*/
default void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i, itemstack != null || flag);
if (i < 0) {
return;
}
if (itemstack != null || flag) {
if (itemstack == null) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double) f >= 0.1D) {
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
if (!worldIn.isRemote) {
ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
if (flag1) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
worldIn.spawnEntity(entityarrow);
}
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (__getItemRand().nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1) {
itemstack.setCount(itemstack.getCount() - 1);
if (itemstack.getCount() == 0) {
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(__getBowItem()));
}
}
}
}
Aggregations