Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • Author
Just now, diesieben07 said:

You have already been told that that doesn't make any sense. You need to not create a new ItemStack.

Please learn basic Java and programming concepts before making a mod.

I havent made a new itemstack, or i am assuming you are pointing out ItemToolTipEvent? Listen I know very little java, I have 1 year experience of javascript (Which is not the same ik), Also this is my first mod so I dont know what the methods do that are with forge. Please have some patience with me.

  • Author
3 minutes ago, diesieben07 said:

This creates a new ItemStack. And a useless one at that.

That isnt in my code anymore, Luis helped me so. Please read the history of messages before trying to help, That I have gotten ridden of. I know that doesnt do shit.

Spoiler
package com.pizzacat.soulmod.enchantment;

import com.pizzacat.soulmod.soulmod;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.Style;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

@Mod.EventBusSubscriber
public class SoulStealEnchantment extends Enchantment {
    protected SoulStealEnchantment(Rarity pRarity, EnchantmentCategory pCategory, EquipmentSlot... pSlots) {
        super(pRarity, pCategory, pSlots);
    }

    static float soulpower;
    static float sp;
    static ItemStack soulStealWeapon = SoulStealEvent.soulStealWeapon;
    static int level = SoulStealEvent.level;


    public static CompoundTag soulStealCompoundTag(){
        soulStealWeapon.getOrCreateTagElement(soulmod.MODID);
        soulpower += sp;
        CompoundTag tag = new CompoundTag();
        tag.putFloat(soulmod.MODID, soulpower);
        return tag;
    }

    @SubscribeEvent
    public static ItemTooltipEvent tooltip(){
        if (soulStealWeapon.getTagElement(soulmod.MODID) != null) {
            soulStealCompoundTag().getFloat(soulmod.MODID);
             Component component = new Component() {
                 @Override
                 public Style getStyle() {
                     return null;
                 }

                 @Override
                 public ComponentContents getContents() {
                     return null;
                 }

                 @Override
                 public List<Component> getSiblings() {
                     return null;
                 }

                 @Override
                 public FormattedCharSequence getVisualOrderText() {
                     return null;
                 }
             };
        }
        return null;
    }

    @SubscribeEvent
    public static void onPlayerKill(LivingDeathEvent entity){
        entity.getEntity().getLevel();
        if(entity.getEntity().level.isClientSide()){
            boolean playerKill = SoulStealEvent.playerKill;
            if(level == 1 && playerKill == true) {
                sp = entity.getEntity().getMaxHealth();
                soulStealCompoundTag();
                sp = 0;
            }
        }
    }

    @Override
    public int getMaxLevel() {
        return 1;
    }

}
Spoiler
package com.pizzacat.soulmod.enchantment;

import com.pizzacat.soulmod.soulmod;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class SoulStealEvent {

    static boolean playerKill;
    static int level;
    static ItemStack soulStealWeapon;



    @SubscribeEvent
    public static void onLivingDeath(LivingDeathEvent entity){
        entity.getEntity().getLevel();
        DamageSource source = entity.getSource();
        if(source.getEntity() instanceof Player) {
            playerKill = true;
        }
    }

    @SubscribeEvent
    public static void onEquipChange(LivingEquipmentChangeEvent equipment){
        ItemStack mainHandItem = equipment.getEntity().getMainHandItem();
        level = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.SOUL_STEAL.get(), mainHandItem);
        if(level == 1){
            soulStealWeapon = mainHandItem;
        }
    }

}

 

This is an updated version of my code

Edited by JoachimTa

  • Author
2 minutes ago, diesieben07 said:

It is a quote from the "soulStealCompoundTag" method that you just posted here

You have already been told that this does not work. Please learn what static means. However even changing these fields to not be static means there will only ever be one instance of them, as your Enchantment class is a registry entry and thus has singleton-like properties.

Additionally, you should keep event handlers separate from your registry entry class, just to avoid confusion.

Again, you cannot do this. See above.

Okay thank you, now I understand. Well I think I know the problem and I no longer need help thank you!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.