Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • SubItems with Damage
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
pro-mole

SubItems with Damage

By pro-mole, February 26, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

pro-mole    2

pro-mole

pro-mole    2

  • Stone Miner
  • pro-mole
  • Members
  • 2
  • 84 posts
Posted February 26, 2013

Ok, so as far as I understand, we can use item damage to set up sub items with the same item id. That is why we use "setMaxDamage(0)". But is it possible to create sub items that still have a damage component?

  • Quote

Share this post


Link to post
Share on other sites

mnn    76

mnn

mnn    76

  • Diamond Finder
  • mnn
  • Members
  • 76
  • 298 posts
Posted February 26, 2013

It still has "damage" component, but it's used for identifying sub-items [field itemDamage in ItemStack].

 

I think you'd have to save your custom damage to NBT and rewrite item rendering to show this special damage. Or from the other side - you'd have to write your own implementation of sub-items using NBT (so rewrite stuff like getting item name shown to a player, icon).

  • Quote

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Share this post


Link to post
Share on other sites

pro-mole    2

pro-mole

pro-mole    2

  • Stone Miner
  • pro-mole
  • Members
  • 2
  • 84 posts
Posted February 26, 2013

I think I have an idea about that, but I also realize maybe I should just use multiple one-use items instead of one item with damage.

 

Thanks anyway.

  • Quote

Share this post


Link to post
Share on other sites

Moritz    15

Moritz

Moritz    15

  • Dragon Slayer
  • Moritz
  • Forge Modder
  • 15
  • 512 posts
Posted February 28, 2013

I found a way to add meta tools. But the repair recipes in vanilla minecraft does not work.

and this is the way how i add it.

 

public class ItemMetaTool extends Item

{

  private int damage = 0;

  private int maxDamage1;

 

 

  public ItemMetaTool(int id, int max)

  {

      super(id);

      setHasSubtypes(true);

      setMaxDamage(0);

      maxDamage = max;

  }

 

 

  public boolean onDistroyBlock(......)

  {

      damage++;

      return true;

  }

 

 

  public boolean onHitEntity(......)

  {

      damage += 2;

      return true;

  }

 

 

  public void onUpdate(ItemStack par1, World par2, Entity par3, int par4, boolean par5)

  {

        if(par5) //Holding in the hand

        {

            if(damage > maxDamage)

            {

                --par1.stackSize;

            }

        }

        else //Not holding in the hand

        {

          if(damage > maxDamage)

          {

              --par1.stackSize;

          }

        }

    }

}

 

 

with that you can have meta items. but they have to be the same damge. but this is an idea.

  • Quote

Share this post


Link to post
Share on other sites

N1xx1    5

N1xx1

N1xx1    5

  • Tree Puncher
  • N1xx1
  • Members
  • 5
  • 41 posts
Posted February 28, 2013

Item and Block classes aren't instantiated for every item in the game or every block in the game. That's why we have ItemStacks and chunks containg an array of block ids, and that's why we have NBTTags in ItemStacks and TileEntities.

 

If you make a variable in your Item and do something with that, you won't be able to save it and it will conflict with all other Items of the same type.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Thorius
      I don't know how forge works

      By Thorius · Posted 9 minutes ago

      Did you run your server?  
    • Wintersky20
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By Wintersky20 · Posted 11 minutes ago

      Ok guys .. So , I'm trying to replace a vanilla block in 1.16.4 but no luck! First I created a Workspace like I always do .. I created a block class for my replaced block: public class ExempleBlock extends CactusBlock /*just an ex.*/ { public ExempleBlock() { super(AbstractBlock.Properties.from(Blocks.CACTUS)); } } Then I tried to register it : First method( copied from an old 1.12 mod by rwTema ) @Mod.EventHandler/* not in 1.16*/ public void preinit(FMLPreInitializationEvent event) {/* not in 1.16 , I think*/ Block blockDietHopper = new BlockDietHopper(); ForgeRegistries.BLOCKS.register(blockDietHopper); } Then I tried to do this with a new registry event //from the exemple mod private void setup(final FMLCommonSetupEvent event){ Block ex = new ExempleBlock(); ForgeRegistries.BLOCKS.register(ex); } no luck Then I tried this : @Mod(ExempleMain.MOD_ID) public class ExempleMain { public static final String MOD_ID = "id"; private static final Logger LOGGER = LogManager.getLogger(); public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft"); public static final RegistryObject<Block> BETTER_EXEMPLE = BLOCKS.register("exemple_block", () -> new ExempleBlock()); public ExempleMain() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ExempleMain.BLOCKS.register(bus); } private void setup(final FMLCommonSetupEvent event){} } No luck   The idea is , I want to modify the TileEntity or the TESR for the vanilla blocks (ex: tools hovering on enchanting table , Nethar anchor GUI, Composter GUI, etc)   Note: I use IntelliJ and mdk-1.16.4-35.1.37   And Thanks for every topic
    • Mark74
      I don't know how forge works

      By Mark74 · Posted 15 minutes ago

      I dont have that folder, should i create it?
    • poopoodice
      [1.16.4] How i can open a container by clicking on my mob

      By poopoodice · Posted 24 minutes ago

      Well, since  public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity <--------) { return new MyModContainer(id,playerInventory, world,extraDataWriter); } you already have the player, why don't you just pass the player in? Also getEntityByID is using entityID not UUID, use ServerWorld#getEntityByUuid/getPlayerByUuid although it is not necessary because you've got the player already.  
    • MKR0902
      1.12.2 Forge Server Not starting with command arguements

      By MKR0902 · Posted 34 minutes ago

      trying to start the forge server with more memory using the command  java -Xmx1G -Xms1G -jar minecraftforge-universal-1.6.2-9.10.0.804.jar nogui but keep getting the error: launcher.lang.reflect.InvocationTargetException also happens if I use the megabyte version, so like 1024M.
  • Topics

    • Mark74
      4
      I don't know how forge works

      By Mark74
      Started 1 hour ago

    • Wintersky20
      0
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By Wintersky20
      Started 11 minutes ago

    • Klarks
      39
      [1.16.4] How i can open a container by clicking on my mob

      By Klarks
      Started Saturday at 09:56 PM

    • MKR0902
      0
      1.12.2 Forge Server Not starting with command arguements

      By MKR0902
      Started 34 minutes ago

    • Amazinwave
      0
      Amazinwave

      By Amazinwave
      Started 1 hour ago

  • Who's Online (See full list)

    • Thorius
    • MKR0902
    • Montyfat
    • Microcellule
    • babyfarkmcgeezax
    • Wintersky20
    • AurenX
    • st4s1k
    • Mark74
    • CookieLukas
    • Joshthehoneskid
    • vemerion
    • Amazinwave
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • SubItems with Damage
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community