Jump to content

Search the Community

Showing results for 'onUsingTick' in topics.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Minecraft Forge
    • Releases
    • Support & Bug Reports
    • Suggestions
    • General Discussion
  • Mod Developer Central
    • Modder Support
    • User Submitted Tutorials
  • Non-Forge
    • Site News (non-forge)
    • Minecraft General
    • Off-topic
  • Forge Mods
    • Mods

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


XMPP/GTalk


Gender


URL


Location


ICQ


AIM


Yahoo IM


MSN Messenger


Personal Text

  1. Is `onUsingTick` available in the version of forge you’re using? If so, that’s the easy way to go about it.
  2. I'm trying make gun which shoot when player holds RMB. @Override public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) { context.getPlayer().sendMessage(new TranslationTextComponent("item.overpixel.tracer.test"), context.getPlayer().getUniqueID()); } How to fix it? Should I try another way instead? How can I detect if player holds any key or press it?
  3. I want to perform an action each tick the player is holding right click with a custom item in their hand. I tried to use the even "onUsingTick" like this: @Override public void onUsingTick(ItemStack BasicWandItem, LivingEntity player, int count) { player.teleportTo((player.position().x+1),(player.position().y+1),(player.position().z+1)); super.onUsingTick(BasicWandItem, player, count); } but it doesn´t work, any suggestions? thx
  4. I wanted to make a mod to play a violin while right clicking and stop when not, with the code i have until now i can play it. But now i need to use another function so it stops when you don't right click anymore. The function that i encounter most useful was "onUsingTick", but as i understand know its deprecated and i don't find the replacement. At the same time, i think something to stop the sound in a function like "useOnRelease" or "finishUsingItem" would be more helpful, but that is equally complicated without sound events management as i understand. (sorry if my english is a little broken, i am from Argentina). @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { if(!level.isClientSide() && hand == InteractionHand.MAIN_HAND) { level.playSound(null, player.getX(), player.getY(), player.getZ(), ModSounds.VIOLIN.get(), SoundSource.PLAYERS, 1F, 1.F); } return super.use(level, player, hand); }
  5. @Override public void onUsingTick(ItemStack itemstack, EntityLivingBase entity, int count) { EntityPlayer player = (EntityPlayer) entity; if(fireAble(itemstack)) { fire(player.world, player, itemstack); } if (reloadAble((EntityPlayer) player, itemstack) && !(this.loading)) { reload(this.ammoType, (EntityPlayer) player, itemstack); } } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack itemstack = playerIn.getHeldItem(handIn); if(!worldIn.isRemote) { if(!playerIn.isHandActive()) { if (fireAble(itemstack)) { fire(worldIn, playerIn, itemstack); } if (reloadAble(playerIn, itemstack) && !(this.loading)) { reload(this.ammoType, playerIn, itemstack); } playerIn.setActiveHand(handIn); return new ActionResult<>(EnumActionResult.SUCCESS, itemstack); } } return new ActionResult<>(EnumActionResult.FAIL, itemstack); } I've written these codes. They work fine in the creative mode, the gun stopped fire when the right mouse button was released, but in survival mode, sometimes it just doesn't stop, the gun keeps fire although the player has released the mouse. What might cause this problem and how do I solve it?
  6. The idea is, each tick the item is being use it should do something (Im printing number to test before i can do something better), When the player is no longer using the item it should do other thing just once. Basically *Right click holded with item in hand* *Each tick the chat should print 1* *The player stop holding right click* *the chat should print 2 just once* if the player hold click for 5 ticks the chat should like this: 1 1 1 1 1 2 This is the item class public class BasicWandItem extends Item { public BasicWandItem(Properties pProperties) { super(pProperties); } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { pPlayer.startUsingItem(pUsedHand); return super.use(pLevel, pPlayer, pUsedHand); } @Override public void onUsingTick(ItemStack BasicWandItem, LivingEntity player, int count) { player.sendMessage(new TranslatableComponent("1"),player.getUUID()); super.onUsingTick(BasicWandItem, player, count); } @Override public void releaseUsing(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity, int pTimeCharged) { pLivingEntity.stopUsingItem(); pLivingEntity.sendMessage(new TranslatableComponent("2"),pLivingEntity.getUUID()); super.releaseUsing(pStack, pLevel, pLivingEntity, pTimeCharged); } } } thx ❤️
  7. Im sorry to waste your time, but im able to make it works how i want. What i want is, while the player holds right click do something (for example writin 1 in the chat), and when he relese the button do something else once (for example writing 2 in the chat). I tried with this code: @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { pPlayer.startUsingItem(pUsedHand); return super.use(pLevel, pPlayer, pUsedHand); } @Override public void onUsingTick(ItemStack BasicWandItem, LivingEntity player, int count) { player.sendMessage(new TranslatableComponent("1"),player.getUUID()); super.onUsingTick(BasicWandItem, player, count); } @Override public void releaseUsing(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity, int pTimeCharged) { pLivingEntity.stopUsingItem(); pLivingEntity.sendMessage(new TranslatableComponent("2"),pLivingEntity.getUUID()); super.releaseUsing(pStack, pLevel, pLivingEntity, pTimeCharged); }
  8. I've got the same problem as Daniel336Cobra in this thread I've got an Item (a gun) with a capability storing a list of ItemStacks (attachments - scopes, circuits, etc.). My circuit in that capability is an ItemStack that has another (different) capability that controls how often the gun should fire. Every time the gun is shot (in onUsingTick) a counter in my circuit's capability is incremented. This counter is reset in onPlayerStoppedUsing. Both capabilities are stored in the Gun's NBT and it seems that because of this when I'm using the gun the item stack is constantly updating and animations don't get applied successfully. ALSO when I stop using the gun on the client usually the server isn't made aware of this and keeps shooting. My problem is that the server keeps shooting when the client has stopped. I believe it's the capability because when I comment out line 149 the animations & server/client shooting work fine (except obviously without the control provided by the capability). This makes it seem like the solution is not to sync (write NBT to the item stack) the capability & just hope they remain the same client/server. My code - https://github.com/Cadiboo/WIPTechAlpha/blob/9304a1745aec48891841a0d9d8703a01cda72ca3/src/main/java/cadiboo/wiptech/item/ItemHandheldGun.java#L74-L192 and a couple videos to illustrate https://streamable.com/rv9c0 https://streamable.com/o4dq6 The relevant part of my debug log - https://gist.github.com/Cadiboo/1db00e79ccd6e6a644b9670990e93cec
  9. I'm trying to create an item where if the player holds right-click on a specific block for a certain amount of time, the block spawns an item. After some searching, I figured I could use onUsingTick to achieve this. However, onUsingTick never gets called. I have a PlayerInteractEvent set up that does get called every time I right click. Is it perhaps interrupting or preventing onUsingTick? Or am I doing something else wrong? @Override public void onUsingTick(ItemStack stack, EntityPlayer player, int tick) { System.out.println("onUsingTick started!"); MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(player.worldObj, player, true); if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) { World world = player.worldObj; BlockPos pos = mop.getBlockPos(); if (world.getBlockState(pos) != null) { if (!world.isRemote && tick ==1) { System.out.println("onUsingTick successful!"); } } } } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { System.out.println("onItemRightClick started!"); player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack)); return itemStack; } @Override public int getMaxItemUseDuration(ItemStack itemStack) { return 20; }
  10. perhaps I didnt word this correctly, I know how LivingHurtEvent works and how to check if player was damaged by lightning. Thats not what I am trying to achieve. You know how AxeItem has event-like methods such as onLeftClickEntity and onUsingTick? I want to create my own class named AxeItemEx that extends AxeItem so that I may create my own custom event-like methods such as the one listed above (onHurtByLightning). Thing is I have no idea how the event-like methods from AxeItem class work since they are from the interface IForgeItem and there is no proper documentation on either of them and I haven't seen anybody else on this forum trying to achieve what I am trying to do. So long story short I am trying to create an event-like method that can be overriden by any custom item Ex. public class ThunderAxe extends AxeItemEx{ @Override public void onHurtByLightning(Player p, int amnt){ //do whatever I want here when this event is triggered } }
  11. Greetings everyone, I've been trying to code an automatic shooting weapon recently, and encountered a problem. My weapon uses an NBT integer tag to store the current magazine contents, and should fire as long as the RMB is held and there is ammo in the magazine. I use this code: public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {//Every 3rd tick... if (count % 3 == 0) {//...get the world we are in... World world = player.world; //...get magazine contents... int magCount = stack.getTagCompound().getInteger("magazine"); //...if the magazine has ammo... if (magCount > 0) { if (!world.isRemote) { //decrease the ammo... stack.getTagCompound().setInteger("magazine", magCount - 1); //...create and spawn the bullet, play shot sound. EntityGenericBullet bullet = new EntityGenericBullet(world, player, 6.0D, 0.5D, false); bullet.shoot(player, player.rotationPitch, player.rotationYaw, 5.0F, 1.0F); world.spawnEntity(bullet); world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.submachinegunfire, SoundCategory.PLAYERS, 6.0F, 1.0F / (itemRand.nextFloat() * 0.2F + 0.8F)); } //Small recoil player.setLocationAndAngles(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch - (itemRand.nextFloat() + 1.0F)); } } } And for some reason, it gives a weird bug: sometimes upon a short RMB press, instead of a short burst, the weapon empties the entire magazine. That does not always happen though. What am I doing wrong? Thanks in advance, Dan
  12. OK, So I added console outputs for onItemRightClick(), onUsingTick() and onPlayerStoppedUsing() and caught a very strange bug: The onPlayerStoppedUsing is never called. public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) { if (entityLiving instanceof EntityPlayer) { System.out.println("Stopped using"); } } I never saw it in the console. Also it looks like it is... unsynchronized? I can't understand why else I could get this kind of messages where it starts firing several times. [22:11:55] [main/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 72000, 25 ammo left [22:11:55] [main/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71997, 24 ammo left [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71994, 23 ammo left [22:11:55] [main/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onItemRightClick:126]: Starting firing [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71991, 22 ammo left [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71988, 21 ammo left [22:11:55] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71985, 20 ammo left [22:11:56] [Server thread/INFO] [STDOUT]: [items.ItemSubmachineGun:onUsingTick:163]: Shooting @ tick count 71982, 19 ammo left ...Firing, firing, firing, although I already let go of the RMB... ...No "Stopped Using" message... I am sorry for being bothersome, but I just can't understand why onPlayerStoppedUsing() is never called.
  13. good days im triying to make an animated item swiching json files but i been notice when in my code try to write an nbt in the onUsingTick() method i just break and causes the playerIn.setItemInUse(pistola, this.getMaxItemUseDuration(pistola)); to stop and execute onPlayerStoppedUsing() for example @Override public int getMaxItemUseDuration(ItemStack pistola) { return 1000; } @Override public EnumAction getItemUseAction(ItemStack pistola) { return EnumAction.NONE; } //######################################################################################3 @Override public ItemStack onItemRightClick(ItemStack pistola, World worldIn, EntityPlayer playerIn) { playerIn.setItemInUse(pistola, this.getMaxItemUseDuration(pistola)); return pistola; } //######################################################################################3 @Override public void onUsingTick(ItemStack pistola, EntityPlayer playerIn, int count) { setInttag(pistola,"munition", 0 ); } //#########################################################################3 public static void setInttag(ItemStack its, String tag, int value){ try{ NBTTagCompound nsInt= its.getTagCompound(); nsInt.setInteger(tag, value); its.setTagCompound(nsInt); }catch(Throwable any) { NBTTagCompound nsInt = new NBTTagCompound(); nsInt.setInteger(tag, value); its.setTagCompound(nsInt); }} //#########################################################################3 @Override public void onPlayerStoppedUsing(ItemStack pistola, World worldIn, EntityPlayer playerIn, int timeLeft) { System.out.println(" timeLeft"+ timeLeft); } when i release rigth click it get stuck and dont reach onPlayerStoppedUsing , it continues until it counts to 1000, but if i comment //setInttag(pistola,"munition", 0 ); in onUsingTick() [22:13:17] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft999 [22:13:17] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft999 [22:13:18] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft996 [22:13:18] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft996 [22:13:20] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft988 [22:13:20] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft988 [22:13:21] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft984 [22:13:21] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft984 [22:13:23] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft987 [22:13:23] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]: timeLeft987 it begins to work like it must jummmm ¿is there a work aroun thath alow my to writte nbts from onUsingTick() ?
  14. Item#onUsingTick is only called if the Item is in use, therefore you need to call LivingEntity#startUsingItem in Item#use. and the return value of Item#getUseDuration is larger than 0. In addition teleport the Player is a server side operation and you should use Entity#teleportToWithTicket.
  15. Is this a bug or is there some reason that writing NBT data changes how right mouse up is handled, or am I doing something different wrong? Also by adding some simple logging and using @SubscribeEvent that the PlayerUseItemEvent.Stop event isn't always triggered when the use button is released if NBT data is written. Example code snippet: public class ItemRFBlaster { //some methods ommited for brevity @Override public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityPlayer, int itemInUseCount) { super.onPlayerStoppedUsing(itemstack,world,entityPlayer,itemInUseCount); logger.info("Stopped using"); if(getFiremode(itemstack) == Firemode.Single) { tryFire(itemstack, world, entityPlayer, itemInUseCount); } setCoolingdown(itemstack); setPartialTicks(itemstack, 0); } @Override public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { super.onUsingTick(stack, player, count); logger.info("count: {}",count); if(player.getEntityWorld().isRemote) return; assert(player.isUsingItem()); if(!canFire(stack)) { setCoolingdown(stack); return; } if(getFiremode(stack) == Firemode.Auto){ tryFire(stack,player.getEntityWorld(),player,count); }else if(getFiremode(stack) == Firemode.Burst){ if(tryFire(stack,player.getEntityWorld(),player,count)) { incrBurst(stack); } } } @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityPlayer) { if(entityPlayer.isSneaking()) { if(!world.isRemote) { cycleFiremode(itemstack, entityPlayer); } } else if (entityPlayer.capabilities.isCreativeMode || getEnergyStored(itemstack) >= 5) { entityPlayer.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack)); } return itemstack; } } Where tryFire, incrBurst, and canFire read and write NBT data. If the NBT data writing is commented out then onPlayerStoppedUsing is always called when I expect it.
  16. public class ItemRayGun extends Item { public ItemRayGun(String name) { this.setUnlocalizedName(name); this.setMaxStackSize(1); this.setMaxDamage(1000); this.setRegistryName(new ResourceLocation(Reference.MODID, name)); } @Override public int getMaxItemUseDuration(ItemStack stack) { return 1; } @Override public void onUsingTick(ItemStack stack, EntityLivingBase entityliving, int count) { EntityPlayer player = (EntityPlayer) entityliving; DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player); if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET)) { if (!player.isCreative()) { dinoEntity.consumeAmmo(DinocraftItems.RAY_BULLET, 1); stack.damageItem(1, player); } if (!player.world.isRemote) { EntityRayBullet ball = new EntityRayBullet(player, 0.001F); ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 15.0F, 0.0F); ball.setRotationYawHead(player.rotationYawHead); Vec3d vector = player.getLookVec(); double x = vector.x; double y = vector.y; double z = vector.z; ball.motionX = x * 3.33D; ball.motionZ = z * 3.33D; ball.motionY = y * 3.33D; ball.setPositionAndUpdate(player.posX - (x * 0.75D), player.posY + player.eyeHeight, player.posZ - (z * 0.75D)); player.world.spawnEntity(ball); player.world.playSound(null, player.getPosition(), DinocraftSoundEvents.RAY_GUN_SHOT, SoundCategory.NEUTRAL, 3.0F, player.world.rand.nextFloat() + 0.5F); } DinocraftEntity.getEntity(player).recoil(0.1F, 1.25F, true); } super.onUsingTick(stack, player, count); } @Override public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { if (isSelected) { EntityPlayer player = (EntityPlayer) entity; DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player); if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET)) { Item mainhand = player.getHeldItemMainhand().getItem(); if (mainhand != null && mainhand == this) { player.setActiveHand(EnumHand.MAIN_HAND); } else { player.setActiveHand(EnumHand.OFF_HAND); } } else if (!world.isRemote) { dinoEntity.sendActionbarMessage(TextFormatting.RED + "Out of ammo!"); world.playSound(null, player.getPosition(), SoundEvents.BLOCK_DISPENSER_DISPENSE, SoundCategory.NEUTRAL, 0.5F, 5.0F); } super.onUpdate(stack, world, entity, itemSlot, isSelected); } } } I noticed that onUsingTick only fires every tick if I explicitly call setActiveHand in onUpdate every tick... onUsingTick doesn't have anything to do with me right-clicking or using the item. That's what is so confusing to me.
  17. In my code of Item , method onUsingTick is never called. Its overriding method from Item, adding @Override doesn't changes anything. But the goal is: while Item is in hand, will shoot every tick a fireball. Method with fireball if added to onItemRightClick, works. Adding System.out.printIn("tick"); in onUsingTick isn't doing anything. If method onUsingTick is used for something else, what method should i use? Thank you for any help.
  18. Ok I am having some trouble here. I need to implement my own version of onUsingTick so that it can be called only when my entity is using the item. (But when the player uses theitem I need it to continue to use the vanilla onUsing tick) but I am unsure how to do this. in my onLivingUpdate method inside my entity class I am trying to implement all of the player logic that causes a player to use an item so that my custom entity can use the item instead. Basically the following @Override public void onLivingUpdate(){ super.onLivingUpdate(); if (this.attackInUse != null) { ItemStack itemstack = this.getCurrentAttack(); if (itemstack == this.attackInUse) { if (attackInUseCount <= 0) { this.onAttackUseFinish(); } else { attackInUse.getItem().onUsingTick(attackInUse, this, attackInUseCount); if (--this.attackInUseCount == 0 && !this.worldObj.isRemote) { this.onAttackUseFinish(); } } } else { this.clearAttackInUse(); } } } I think I did everything correctly so far with a few minor modifications it should work ok but im stuck on the onUsingTick method. I need to be able to have the new onUsingTick available so that I can do attackInUse.getItem().onUsingTick(attackInUse,(EntityCustom) this, attackInUseCount); where currently vanilla doesnt allow this since the second parameter needs to be a EntityPlayer. I have a CustomItem class which extends the vanilla Item class. My CustomItem class is then extended by my attack item class. The attack items are the items that I want my entity to be able to use. But in order for this to work I need to be able to have the entity call the onItemRightClick and onItemUse methods. Inside this class is where I put my custom onUsingTick that I need to be able to call to set my item in use, but I am unsure how to do that. Im not sure how to implement the onUsingTick method that is in my generic CustomItem class rather than the one that is inside the vanilla Item class. I cant use the vanilla one since it requires the player as a parameter and obviously I cannot make my custom mob a player entity. Basically to make my item useable by both the player and the entity I am trying to implement a second onItemRightClick method that replaces the player parameter with the custom entity parameter so that it can be called by my entity from its AI Any ideas how to implement the onUsingTick method from inside my customItem class rather than the regular vanilla onUsingTick method?? Or any ideas on how to implement what I am trying to achieve in a simpler way??
  19. Okay so this is what I have. public class ItemRayGun extends Item { public ItemRayGun(String name) { this.setUnlocalizedName(name); this.setMaxStackSize(1); this.setMaxDamage(1000); this.setRegistryName(new ResourceLocation(Reference.MODID, name)); } @Override public int getMaxItemUseDuration(ItemStack stack) { return 72000; } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; } @Override public void onUsingTick(ItemStack stack, EntityLivingBase entityliving, int count) { if (entityliving.ticksExisted % 2 == 0) { EntityPlayer player = (EntityPlayer) entityliving; World world = player.world; DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player); DinocraftServer.getSide(world); if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET)) { if (!player.isCreative()) { dinoEntity.consumeAmmo(DinocraftItems.RAY_BULLET, 1); stack.damageItem(1, player); } if (!world.isRemote) { EntityRayBullet ball = new EntityRayBullet(player, 0.001F); Vec3d vector = player.getLookVec(); double x = vector.x; double y = vector.y; double z = vector.z; ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 3.33F, 0.0F); ball.setRotationYawHead(player.rotationYawHead); ball.setPositionAndUpdate(player.posX - (x * 0.75D), player.posY + player.eyeHeight, player.posZ - (z * 0.75D)); world.spawnEntity(ball); world.playSound(null, player.getPosition(), DinocraftSoundEvents.RAY_GUN_SHOT, SoundCategory.NEUTRAL, 3.0F, world.rand.nextFloat() + 0.5F); } DinocraftEntity.getEntity(player).recoil(0.1F, 1.25F, true); } else if (!world.isRemote) { dinoEntity.sendActionbarMessage(TextFormatting.RED + "Out of ammo!"); world.playSound(null, player.getPosition(), SoundEvents.BLOCK_DISPENSER_DISPENSE, SoundCategory.NEUTRAL, 0.5F, 5.0F); } super.onUsingTick(stack, player, count); } } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { playerIn.setActiveHand(EnumHand.MAIN_HAND); return super.onItemRightClick(worldIn, playerIn, handIn); } } All goes well, but when I stop right-clicking, sometimes, the server thread doesn't get notified and it keeps running onUsingTick even though I'm not right clicking. The client side doesn't have this bug. Also, when this fires, I get the following errors continuously. Not sure what they mean. [22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error in class 'ChannelLWJGL OpenAL' [22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Invalid enumerated parameter value. [22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error in class 'ChannelLWJGL OpenAL' [22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error creating buffers in method 'preLoadBuffers'
  20. package dinocraft.item; import dinocraft.Reference; import dinocraft.capabilities.entity.DinocraftEntity; import dinocraft.entity.EntityRayBullet; import dinocraft.init.DinocraftItems; import dinocraft.init.DinocraftSoundEvents; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; public class ItemRayGun extends Item { public ItemRayGun(String name) { this.setUnlocalizedName(name); this.setMaxStackSize(1); this.setMaxDamage(1000); this.setRegistryName(new ResourceLocation(Reference.MODID, name)); } @Override public void onUsingTick(ItemStack stack, EntityLivingBase entityliving, int count) { EntityPlayer player = (EntityPlayer) entityliving; DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player); if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET)) { if (!player.isCreative()) { dinoEntity.consumeAmmo(DinocraftItems.RAY_BULLET, 1); stack.damageItem(1, player); } if (!player.world.isRemote) { EntityRayBullet ball = new EntityRayBullet(player, 0.001F); ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 15.0F, 0.0F); ball.setRotationYawHead(player.rotationYawHead); Vec3d vector = player.getLookVec(); double x = vector.x; double y = vector.y; double z = vector.z; ball.motionX = x * 3.33D; ball.motionZ = z * 3.33D; ball.motionY = y * 3.33D; ball.setPositionAndUpdate(player.posX - (x * 0.75D), player.posY + player.eyeHeight, player.posZ - (z * 0.75D)); player.world.spawnEntity(ball); player.world.playSound(null, player.getPosition(), DinocraftSoundEvents.RAY_GUN_SHOT, SoundCategory.NEUTRAL, 3.0F, player.world.rand.nextFloat() + 0.5F); } DinocraftEntity.getEntity(player).recoil(0.1F, 1.25F, true); } super.onUsingTick(stack, player, count); } @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player); if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET)) { player.setActiveHand(hand); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } else if (!world.isRemote) { dinoEntity.sendActionbarMessage(TextFormatting.RED + "Out of ammo!"); world.playSound(null, player.getPosition(), SoundEvents.BLOCK_DISPENSER_DISPENSE, SoundCategory.NEUTRAL, 0.5F, 5.0F); return ActionResult.newResult(EnumActionResult.FAIL, stack); } return ActionResult.newResult(EnumActionResult.FAIL, stack); } } The onUsingTick method doesn't call at all when I right-click.
  21. Well, the problem of onUsingTick is the item can't be damaged when holding right-click. Otherwise, it just returns a new itemstacks which interrupts the player's action (onUsingTick still being called when the player has already released the right mouse button).
  22. To spawn arrows, something like this would work: @Override public void onUsingTick(ItemStack stack, LivingEntity player, int count) { if (!(player instanceof PlayerEntity)) { return; } PlayerEntity playerEntity = (PlayerEntity)player; World worldIn = player.world; if (!worldIn.isRemote) { AbstractArrowEntity abstractarrowentity = new ArrowEntity(worldIn, playerEntity); abstractarrowentity.shoot(playerEntity, playerEntity.rotationPitch, playerEntity.rotationYaw, 0.0F, 10.0F, 1.0F); abstractarrowentity.setIsCritical(true); abstractarrowentity.setDamage(10.D); abstractarrowentity.setKnockbackStrength(1); abstractarrowentity.setFire(100); stack.damageItem(1, playerEntity, (p_220009_1_) -> { p_220009_1_.sendBreakAnimation(playerEntity.getActiveHand()); }); abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY; worldIn.addEntity(abstractarrowentity); } You dont even need your own arrow class for this. But creating a custom bullet would also have its benefits and would look better with less unused functionality.
  23. oh I thought i just needed onUsingTick. also I looked over your code and I don't want my Gun/Bow shooting bullets like a snowball I want it to actually shoot like a real ak47 as i said before
  24. It could look like this: package com.thoriuslight.professionsmod.item; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.SnowballEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.world.World; public class BOWTEST extends Item{ public BOWTEST(Properties builder) { super(builder); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { playerIn.setActiveHand(handIn); return ActionResult.resultPass(playerIn.getHeldItem(handIn)); } @Override public int getUseDuration(ItemStack stack) { return 20; } @Override public void onUsingTick(ItemStack stack, LivingEntity player, int count) { if (!(player instanceof PlayerEntity)) { return; } World worldIn = player.world; worldIn.playSound((PlayerEntity)null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); if (!worldIn.isRemote) { SnowballEntity snowballentity = new SnowballEntity(worldIn, player); snowballentity.setItem(new ItemStack(Items.DIAMOND)); snowballentity.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.F, 1.0F); worldIn.addEntity(snowballentity); } } } After getUseDuration ticks there will be a small pause but it's not that noticeable. You have to set the active hand to be the item.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.