Jump to content

[1.19.2] what happends to the onEntitySwing() method ?


perromercenary00

Recommended Posts

good nights 
i made a custome lance item and need to make it has a longer reach soo it can hurt zombies at 6 or 7 meters  the SwordItem only has 4 maybe 5 meters reach 

 

Spoiler
package merctool.item;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.Vanishable;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;

public class LanceItem extends SwordItem implements Vanishable {
   private final float attackDamage;
   private final Multimap<Attribute, AttributeModifier> defaultModifiers;

   public LanceItem(Tier p_43269_, int p_43270_, float p_43271_, Item.Properties p_43272_) {
      super(p_43269_, p_43270_, p_43271_, p_43272_);
      this.attackDamage = (float)p_43270_ + p_43269_.getAttackDamageBonus();
      ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
      builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", (double)this.attackDamage, AttributeModifier.Operation.ADDITION));
      builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", (double)p_43271_, AttributeModifier.Operation.ADDITION));
      this.defaultModifiers = builder.build();
   }

   public float getDamage() {
      return this.attackDamage;
   }

   public boolean canAttackBlock(BlockState p_43291_, Level p_43292_, BlockPos p_43293_, Player p_43294_) {
	   System.out.println("canAttackBlock");
	   
	   
      return !p_43294_.isCreative();
   }

   public float getDestroySpeed(ItemStack p_43288_, BlockState p_43289_) {
      if (p_43289_.is(Blocks.COBWEB)) {
         return 15.0F;
      } else {
         Material material = p_43289_.getMaterial();
         return material != Material.PLANT && material != Material.REPLACEABLE_PLANT && !p_43289_.is(BlockTags.LEAVES) && material != Material.VEGETABLE ? 1.0F : 1.5F;
      }
   }

   public boolean hurtEnemy(ItemStack p_43278_, LivingEntity p_43279_, LivingEntity p_43280_) {
	   System.out.println("hurtEnemy");
	   
      p_43278_.hurtAndBreak(1, p_43280_, (p_43296_) -> {
         p_43296_.broadcastBreakEvent(EquipmentSlot.MAINHAND);
      });
      return true;
   }

   public boolean mineBlock(ItemStack p_43282_, Level p_43283_, BlockState p_43284_, BlockPos p_43285_, LivingEntity p_43286_) {
	   System.out.println("mineBlock");
	   
      if (p_43284_.getDestroySpeed(p_43283_, p_43285_) != 0.0F) {
         p_43282_.hurtAndBreak(2, p_43286_, (p_43276_) -> {
            p_43276_.broadcastBreakEvent(EquipmentSlot.MAINHAND);
         });
      }

      return true;
   }

   public boolean isCorrectToolForDrops(BlockState p_43298_) {
      return p_43298_.is(Blocks.COBWEB);
   }

   public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot p_43274_) {
      return p_43274_ == EquipmentSlot.MAINHAND ? this.defaultModifiers : super.getDefaultAttributeModifiers(p_43274_);
   }

   @Override
   public boolean canPerformAction(ItemStack stack, net.minecraftforge.common.ToolAction toolAction) {
	   System.out.println("canPerformAction");
      return net.minecraftforge.common.ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction);
   }
   
   @Override
   public InteractionResult useOn(UseOnContext p_41427_) {
	   System.out.println("useOn");
	      return InteractionResult.PASS;
	   }
   
   @Override
   public InteractionResultHolder<ItemStack> use(Level p_41432_, Player p_41433_, InteractionHand p_41434_) {
	   System.out.println("use");
	      ItemStack itemstack = p_41433_.getItemInHand(p_41434_);
	      if (itemstack.isEdible()) {
	         if (p_41433_.canEat(itemstack.getFoodProperties(p_41433_).canAlwaysEat())) {
	            p_41433_.startUsingItem(p_41434_);
	            return InteractionResultHolder.consume(itemstack);
	         } else {
	            return InteractionResultHolder.fail(itemstack);
	         }
	      } else {
	         return InteractionResultHolder.pass(p_41433_.getItemInHand(p_41434_));
	      }
	   }
   
   
   @Override
   public net.minecraft.world.InteractionResult interactLivingEntity(ItemStack stack, net.minecraft.world.entity.player.Player playerIn, LivingEntity entity, net.minecraft.world.InteractionHand hand) {
	   System.out.println("interactLivingEntity");

	   return net.minecraft.world.InteractionResult.SUCCESS;
   }
	   
}

 

 

lokking into mi old code the function name was 

    public boolean onEntitySwing(EntityLivingBase shootingEntity, ItemStack pistola) 

 

soo what function is trigered on left click ?

 


 

 

 

 

Link to comment
Share on other sites

Maybe this?

https://github.com/MinecraftForge/MinecraftForge/blob/d176bab28e265263908b0bb509a23734d0d53516/src/main/java/net/minecraftforge/common/ForgeMod.java#L158

i.e. use LivingEquipmentChangeEvent to add/remove AttributeModifiers to the player when it is your lance.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

thanks for asking 
i was looking to the forge class code and see the attributes  and seems complicated to get them change them and apply to player also the original value needs to be stored somehow soo it can be restored when player deselect the lance 

 

event its the easy part 

    @SubscribeEvent
    public static void on_using_lance(LivingEquipmentChangeEvent event) {

        ItemStack itemstack = event.getTo();
        Entity entity = event.getEntity();
        Level warudo = entity.level;
        if (entity instanceof Player) {

            // if (itemstack.getItem() == ItemInit.LANCE_STEEL.get() &&
            // !warudo.isClientSide) {
            if (itemstack.getItem() instanceof LanceItem && !warudo.isClientSide) {
                System.out.println("\nEs una lanza\n");
                 //IForgePlayer.getReachDistance();
            }

            else {

                     //set back the original values 

            }

        }

    }

 

 

i need help whi the forge class part 

but also really really theres no replace to detect when players leftclick whit an item ?

 

Link to comment
Share on other sites

You can see how to apply attribute modifiers in for example Horse.setArmourEquipment() it's not complicated at all.

It's also the correct way to do it.

 

The swing method still exists:

https://github.com/MinecraftForge/MinecraftForge/blob/d176bab28e265263908b0bb509a23734d0d53516/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java#L394

That's a policy hook to control animations, not for ad hoc processing.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ChemsXpress (https://chemsxpress.com): ChemsXpress is a platform specializing in the distribution of research chemicals and related products. It offers a wide range of substances for scientific and laboratory use, catering to researchers and professionals. BubatzLand (https://bubatzland.com): BubatzLand focuses on providing high-quality cannabis products. The site offers a variety of strains, edibles, and related accessories, aiming to serve the needs of cannabis enthusiasts and medicinal users. HalluShroom (https://hallushroom.com): HalluShroom specializes in the sale of psychedelic mushrooms and related products. It caters to individuals interested in exploring the benefits and experiences associated with psilocybin and other psychedelic substances. HighAsch (https://highasch.com): HighAsch offers a diverse range of cannabis products, including flowers, concentrates, and edibles. The site aims to provide premium-quality products to both recreational and medicinal users. KetaminHaus (https://ketaminhaus.com): KetaminHaus provides ketamine and related products for research and therapeutic use. The platform focuses on ensuring the availability of high-quality, safe, and effective ketamine for various applications. KokainLabor (https://kokainlabor.com): KokainLabor offers cocaine and other related substances. The site targets individuals seeking high-purity products for personal or research purposes, emphasizing quality and safety. MDPHPWelt (https://mdphpwelt.com): MDPHPWelt specializes in the distribution of MDPHP and other similar research chemicals. It aims to supply researchers with high-quality substances for scientific and experimental use. NembutaLabor (https://nembutalabor.com): NembutaLabor provides Nembutal (pentobarbital) and related products. The site focuses on supplying these substances for research and veterinary purposes, ensuring high standards of quality and safety. NembutalQuelle (https://nembutalquelle.com): NembutalQuelle is dedicated to offering Nembutal and similar barbiturates. It caters to researchers and professionals who require these substances for scientific, medical, or veterinary applications. JBSaves Ltda Brazil (https://jbsavesltdabrazil.com): JBSaves Ltda Brazil is involved in the food and agricultural industry, providing a variety of products and services related to food processing, distribution, and agricultural practices. Bello Alimentos Ltda (https://belloalimentosltda.com): Bello Alimentos Ltda offers a wide range of food products. The site focuses on high-quality, nutritious, and safe food items, catering to consumers and businesses in the food industry. São Salvador Alimentos (https://saosalvadoralimentoss.com): São Salvador Alimentos specializes in the production and distribution of food products. The site provides a variety of options aimed at meeting the dietary needs and preferences of diverse consumers. WietWereld (https://wietwereld.com): WietWereld is a platform dedicated to the cannabis community. It offers information, products, and resources related to cannabis cultivation, consumption, and culture. 14. BeuhParadise (https://beuhparadis.com): BeuhParadise offers a range of cannabis products, including flowers, edibles, and concentrates. The site aims to provide high-quality cannabis products to recreational and medicinal users, emphasizing purity and potency. 15. WietWereld (https://wietwereld.com): WietWereld is a comprehensive resource for cannabis enthusiasts. It provides products, cultivation guides, and community forums for those interested in cannabis culture and cultivation. GrasOase (https://grasoase.com): GrasOase specializes in cannabis products and accessories. The site offers a variety of strains, seeds, and related items for cannabis users, focusing on quality and customer satisfaction. https://chemsxpress.com/ https://bubatzland.com/ https://hallushroom.com/ https://highasch.com/ https://ketaminhaus.com/ https://kokainlabor.com/ https://mdphpwelt.com/ https://nembutalabor.com/ https://nembutalquelle.com/ https://jbsavesltdabrazil.com/ https://belloalimentosltda.com/ https://saosalvadoralimentoss.com/ https://wietwereld.com https://beuhparadis.com https://wietwereld.com https://grasoase.com/
    • For Example I have an Main Mod that adds new Content to Minecraft. But I'm using custom Classes etc. and I want it so that is an api integrated in the Main Mod but can be download seperately like an Module. Is this possible? If you need more Information just comment what you need to know ^^
    • Delete the config of this mod (config folder) and test it again   If there is no change, try other builds  
    • Add the full crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here
  • Topics

×
×
  • Create New...

Important Information

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