Jump to content

NBT stacktagcompound


ashtonr12

Recommended Posts

firstly i though id start a new topic because my old thread has gone off on a rather large tangent.

second, i know absolutely nothing about NBT's i only started looking at them about 30 mins ago so please be patient and forgive stupid errors xD

 

what i am trying to do is make a sword which when it hits a zombie, recognises this and +1 to dmg of the sword to zombies. i tried to do this with

 

package CriticalStrike.common;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EntityDamageSource;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class MobDrops {

int Zombie = 0;
   
    @ForgeSubscribe
    public void onEntityAttacked(LivingHurtEvent event) {
    	
    	if (!(event.source instanceof EntityDamageSource))
	{return;}
    	
    	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{return;}

    	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();



            if (event.source.getDamageType().equals("player")) {
            if (!(weapon == null)){
            if (weapon.getItem() instanceof ImmortalAdaptingBlade){
            if (event.entityLiving instanceof EntityZombie) {
            	 Zombie =+ 1;
            	 event.ammount =+ Zombie;
            	
            }}}}
            
            }
    }

 

The result was that the sword only did 1 dmg. i wanted it to do 1 + 1 + 1 + 1 + 1 ...etc

They suggested NBTTagCompound, so here is my effort at that, the problem is that it still seems to do only one dmg not matter how many times i hit a zombie,

 

SwordCode

package CriticalStrike.common;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.world.World;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.nbt.*;

public class ImmortalAdaptingBlade extends ItemSword{


public ImmortalAdaptingBlade(int ItemID, EnumToolMaterial Steel){
	super(ItemID, Steel);
}

public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
        if( par1ItemStack.stackTagCompound == null )
                par1ItemStack.setTagCompound( new NBTTagCompound( ) );

        int i = 0;
        par1ItemStack.stackTagCompound.setInteger( "Zombie", i );
}

  @Override
  public void registerIcons(IconRegister reg){
          this.itemIcon = reg.registerIcon("criticalstrike:MythicalEmpoweringSword");
  }} 

 

eventClass

 

package CriticalStrike.common;

import java.awt.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EntityDamageSource;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class AdaptingBladeEvent {

private int zz;

public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
        if( par1ItemStack.stackTagCompound == null )
                par1ItemStack.setTagCompound( new NBTTagCompound( ) );

      
        zz = par1ItemStack.stackTagCompound.getInteger( "Zombie" );
}

    @ForgeSubscribe
    public void onEntityAttacked(LivingHurtEvent event) {
    	
    	if (!(event.source instanceof EntityDamageSource))
	{return;}
    	
    	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{return;}

    	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

            if (event.source.getDamageType().equals("player")) {
            if (!(weapon == null)){
            if (weapon.getItem() instanceof ImmortalAdaptingBlade){
            if (event.entityLiving instanceof EntityZombie) {
            	 zz =+ 1;
            	 event.ammount =+ zz;
            	
            }}}}
            
            }
    }

 

i summery, i want a sword that stacks +1 dmg every time i hit a zombie, only a zombie mind.

 

All help/suggestions/constructive criticism is great, Thanks :)

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

How are you going to use that addInformation method ?  ???

 

Anyway, here is how I would do it:

 

//Inside of the event
if (weapon.getItem() instanceof ImmortalAdaptingBlade){
            if (event.entityLiving instanceof EntityZombie) {
int dmg = 0;
            	 if(weapon.hasTagCompound && weapon.stackTagCompound.hasKey("Zombie")
{
dmg = weapon.getTagCompound.getShort("Zombie");
}
else
{
NBTTagCompound tag = new NBTTagCompound();
tag.setShort("Zombie", 0);
weapon.setTagCompoung(tag);
}
            	 event.ammount =+ dmg;
            	weapon.getTagCompound.setShort("Zombie",dmg+1);
            }}

Link to comment
Share on other sites

did you write this in eclipse? or free hand?

because when i put the code into the event i got a tonne of errors xD did i do somthing wrong?

anyway can you verify that the changes i made to get rid of errors still do the same things?

and there are two related errors i cant seem to get rid of under  tag.setShort("Zombie", 0); &  weapon.stackTagCompound.setShort("Zombie",dmg+1);

the error is "The method setShort(String, short) in the type NBTTagCompound is not applicable for the arguments (String, int)"

 

package CriticalStrike.common;

import java.awt.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EntityDamageSource;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class AdaptingBladeEvent {

    @ForgeSubscribe
    public void onEntityAttacked(LivingHurtEvent event) {
    	
    	if (!(event.source instanceof EntityDamageSource))
	{return;}
    	
    	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{return;}

    	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

            if (event.source.getDamageType().equals("player")) {
            if (!(weapon == null)){
            	if (weapon.getItem() instanceof ImmortalAdaptingBlade){
                    if (event.entityLiving instanceof EntityZombie) {
        int dmg = 0;
                    if(weapon.hasTagCompound() && weapon.stackTagCompound.hasKey("Zombie"))
        {
        dmg = weapon.stackTagCompound.getShort("Zombie");
        }
        else
        {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setShort("Zombie", 0);
        weapon.setTagCompound(tag);
        }
                    event.ammount =+ dmg;
                    weapon.stackTagCompound.setShort("Zombie",dmg+1);
            	
            }}}}
            
            }
    }

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

did you write this in eclipse? or free hand?

because when i put the code into the event i got a tonne of errors xD did i do somthing wrong?

anyway can you verify that the changes i made to get rid of errors still do the same things?

and there are two related errors i cant seem to get rid of under  tag.setShort("Zombie", 0); &  weapon.stackTagCompound.setShort("Zombie",dmg+1);

the error is "The method setShort(String, short) in the type NBTTagCompound is not applicable for the arguments (String, int)"

 

package CriticalStrike.common;

import java.awt.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EntityDamageSource;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class AdaptingBladeEvent {

    @ForgeSubscribe
    public void onEntityAttacked(LivingHurtEvent event) {
    	
    	if (!(event.source instanceof EntityDamageSource))
	{return;}
    	
    	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{return;}

    	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

            if (event.source.getDamageType().equals("player")) {
            if (!(weapon == null)){
            	if (weapon.getItem() instanceof ImmortalAdaptingBlade){
                    if (event.entityLiving instanceof EntityZombie) {
        int dmg = 0;
                    if(weapon.hasTagCompound() && weapon.stackTagCompound.hasKey("Zombie"))
        {
        dmg = weapon.stackTagCompound.getShort("Zombie");
        }
        else
        {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setShort("Zombie", 0);
        weapon.setTagCompound(tag);
        }
                    event.ammount =+ dmg;
                    weapon.stackTagCompound.setShort("Zombie",dmg+1);
            	
            }}}}
            
            }
    }

try to change setShort&getShort to setInt&getInt OR OR OR OR change type of dmg to short,but idk will that help or no

edit: that will help

Link to comment
Share on other sites

ok i have changed it to set int, i dont know if it will work, but it got rid of the errors. I always feel so dumb when i cant figure somthing out, come on here and you guys are like "oh right just..." and im like oh shit, ofc. xD

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

it does but im a pretty nooby coder so if you want to rewrite my code to make it better, go for it. Im pretty sure the more advaned guys on here look at at and cry somtimes :P

i was crying at all you code :D

if you want to rewrite all you code,then plz send it to me on skype,my skype is fhntv24.Beacos that will be a lot faster =) and i can teach you for somting,and i have very goon online so i can teach you amost all times

__________________________

              -Good fhntv24,that want to help noobs,beacos he was noob,and know,how is that,be a noob

 

Link to comment
Share on other sites

<3

 

can i upload it to dropbox and just mail you a link?

also i dont have skype do you have steam?

&& i have a lvls, so coursework to do, and as i am at school i am internet limited, i am using a mobile hotspot atm xD

but i love to do this in my spare time along with dooootaaaaaaa xD

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

<3

 

can i upload it to dropbox and just mail you a link?

also i dont have skype do you have steam?

&& i have a lvls, so coursework to do, and as i am at school i am internet limited, i am using a mobile hotspot atm xD

but i love to do this in my spare time along with dooootaaaaaaa xD

heh then just send drop box link to me in PM.I have steam,but dont give it to anyone ;)

Link to comment
Share on other sites

I lied, if i had two tags, tow integers and i wanted to make sure the second was zero but i hadn't used it yet? because the code i have been graciously given courtesy of goto, checks the key then uses them. is there a way i can check all the tags i need earlier? then change them as i wish?

 

Or am i just being a dumbass and i don't even need to check them? as nbts are uniquely named can i just reference one and it will know what i am talking about?

Use examples, i have aspergers.

Examples make sense to me.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, the microphone mod is not working on my Mac. It says “launcher does not support MacOS microphone permissions” Thank you in advance for answering.
    • Make sure you have Optifine installed as a mod. Go into Options > Video Settings > Shaders > and then click the shader you want Make sure the shader.zip files are in the shaderpacks folder inside the minecraft folder
    • It sounds like you're probably registering the item in the wrong place, try looking at this tutorial for how to register items:  Forge Modding Tutorial - Minecraft 1.20: Custom Items & Creative Mode Tab | #2 This (free) tutorial series is excellent, by the way, and I'd highly recommend watching through some or all of the videos. There may also be an error in the code I showed above since I was in a hurry, but it should be enough for the general idea. I can't be more specific since I don't know exactly what you plan to do.
    • Realizing I was a victim of a scam was a devastating blow. My initial investment of $89,000, driven by dreams of financial success and the buzz surrounding a new cryptocurrency project, turned into a nightmare. The project promised high returns and rapid gains, attracting many eager investors like myself. However, as time passed and inconsistencies began to surface, it became evident that I had made a grave mistake by not thoroughly vetting the brokerage company handling the investment. Feeling anxious and betrayed, I desperately searched for a way to recover my funds. It was during this frantic search that I stumbled upon the Lee Ultimate Hacker tool through a Facebook post. With little left to lose, I decided to reach out to their team for help. To my relief, they were quick to respond and immediately started recovering my compromised email and regaining access to my cryptocurrency wallets. The team at Lee Ultimate Hacker was incredibly professional and transparent throughout the process. They meticulously traced the digital footprints left by the scammers, employing advanced technological methods to unravel the complex network that had ensnared my funds. Their expertise in cybersecurity and recovery strategies gradually began to turn the tide in my favor. Although the scammers had already siphoned off $30,000 worth of Bitcoin, Lee Ultimate Hacker was relentless in their pursuit. They managed to expose the fraudulent activities of the scam operators, revealing their identities and the mechanisms they used to lure investors. This exposure was crucial not only for my case but also as a warning to the wider community about the perils of unverified investment schemes. As we progressed, it became a race against time to retrieve the remaining $59,000 before the scammers could vanish completely. Each step forward was met with new challenges, as these criminals constantly shifted tactics and moved their digital assets to evade capture. Nonetheless, the determination and skill of the recovery team kept us hopeful. Throughout this ordeal, I learned the hard value of caution and due diligence in investment, especially within the volatile world of cryptocurrency. The experience has been incredibly taxing, both emotionally and financially, but the support and results provided by Lee Ultimate Hacker have been indispensable. The recovery process is ongoing, and while the final outcome remains uncertain, the progress made so far gives me hope. The battle to recover the full amount of my investment continues, and with the expertise of Lee Ultimate Hacker, I remain optimistic about the eventual recovery of my funds. Their commitment to their clients and proficiency in handling such complex cases truly sets them apart in the field of cyber recovery. LEEULTIMATEHACKER@ AOL. COM   Support @ leeultimatehacker . com.  telegram:LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248     
    • Hi everyone. I’m excited to share my experience with CrackerWizard Recovery Firm. They helped me recover a substantial amount of crypto after falling victim to online scams disguised as Bitcoin investments. CrackerWizard’s exceptional service enabled me to retrieve my lost funds, despite the complex circumstances surrounding the case. With their dedicated team and advanced technology, they swiftly traced and recovered my assets. CrackerWizard is a reliable partner in the crypto world, highly recommended for anyone facing similar challenges. Contact them.
  • Topics

×
×
  • Create New...

Important Information

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