Jump to content

Differentiation

Members
  • Posts

    606
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Differentiation

  1. Maybe I should be using onPlayerStoppedUsing or something?
  2. 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.
  3. It fires but... once every 4 ticks again. I call setActiveHand in onItemRightClick. I tried calling it in onUpdate but that only runs on the client thread. Now it's kind of confusing. Where should I call setActiveHand?
  4. I tested it again using 0 and the onUsingTick method still doesn't happen. I don't think I have to call it anywhere for it to work, right? This method shoul call when I use the item... but it just doesn't...
  5. 0, and it slows me down but the onUsingTick method doesn't fire.
  6. I tried overriding Item::getMaxUseDuration and it still didn't call, I'm not sure if this is the one you're talking about.
  7. 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.
  8. In school. I'll get back with the code once I get back home.
  9. Well, I tested and world.isRemote returns false Do I have to return a success for action result on both sides or something or is this method independent of onItemRightClick()?
  10. Yes, but would I have to send a packet to the client every two ticks to recoil the player??
  11. I'll send it when I get home. I'm making a gun that fires rapidly (maybe every two ticks) so I need a method that runs on the server and client. The reason for the client is bc I'm making the player recoil every time they fire.
  12. Is there a reason why onUsingTick() is never calling? Also, is there a method for both server and client threads that runs every tick when the player right clicks without having to send packets? Thanks!
  13. Don't send a packet every tick if you're gonna do that...
  14. Thanks for the response. Unfortunately, since only the server thread runs on onUsingTick() method (and since this method never even fires every tick I right-click for some reason), I'll do just fine with the onItemRightClick().
  15. Hey, I'm trying to make the method onItemRightClick(...) in Item run every tick for a certain item of mine instead of every 4 ticks. Is there any way (or alternative way) I could do this? Any help is appreciated. Thanks!
  16. Show the code, initialization events, etc. Waraxe would just be an axe with a different texture and different attack speed (if you want) by adding an attribute modifier.
  17. Set ignoreRange to true in World::spawnParticle(...).
  18. Subscribe to BreakEvent.Then check if the block is the block you want to get the item out of. Lastly, use World::spawnEntity(...) to spawn an item.
  19. You can attach them to both by subscribing to AttachCapabilitiesEvent<Entity> and attaching to PlayerEntity. You'll need to send a packet for when the player clones to save and load the capability data on Clone event since this event is only called on server thread.
  20. @Animefan8888 I figured out the problem: readSavedFile() is @SideOnly(Side.SERVER), and all my testing was on the clients with an Integrated Server thread, so readSavedFile() wasn't actually being called. Gonna make this list (and command) Dedicated Server thread-friendly only since it makes more sense that way anyways. Thanks for all the help!
  21. I mean, I don't know much about this File writing/reading.
  22. It inevitably creates a new instance of UserListMutes every time the mod is loaded. That's my issue. I could make the class abstract, but then I can't really instantiate it. I have no idea how to resolve this.
  23. File::createNewfile(); only creates the file if it does not already exist, I thought. I'll have to double check
  24. https://github.com/TheWoodenWizard/DC-mod/tree/master/src/main/java/dinocraft/handlers
×
×
  • Create New...

Important Information

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