Jump to content

[Solved]1.2.5 some differend metadata questions


Speiger

Recommended Posts

hi i have some questions about metadata. Can i add metadata tools? like this pickaxe (id 500:1) have 10 uses and the other pickaxe (500:2) have 1000 uses? how can i do it. because i have to do it (if it work) to this id (item... 500:10000). seems really oversized or? but this is the need of my mod Idea. i hope i explained not to confused and say thanks to anyone who can help me. between this is not a mod like infinitcraft because i do not add new tools i make the vanilla a little bit differend.

Crazy Brain...

Link to comment
Share on other sites

Unfortunately, metadata and damage values are internally intertwined, so if you were to try to make metadata tools, your sword would become a pickaxe after 1 use, then a shovel after a use, etc. until you hit whatever tool was coded in last.

 

Unless you know how to use bit manipulation. So you take one or two bits of the metadata as flag for your tool type and the rest of bits can be used to determine the damage. Useful would be a getDamage() method to return the shown damage in the inventory.

What I mean is, if you use bit manipulation, there will be always damage shown (except for one type). If you have this method, you can "cut off" the type bit(s) and the inventory will show you only the damage for that type of tool.

Note that the metadata of items have 16 bits = 2^16 - 1 (-1 because 65536 is broken) uses = max. 65535 uses. If you take 2 bits for the type (for 16 types, e. g. if you want multiple colored swords), you have 14 bits for the actual damage left, that means 14 bits = 2^14 - 1 uses = 16383 uses.

 

EDIT: Also you have to take one bit away, because the datatype for the damage value is, like every numeric datatype in java, signed, so it needs the bit to determine if it is positive or negative (negative damage would be more uses, taken damage wouldn't be shown in the inv. until it goes to 0)

That means:

available uses w/o 2 type bits: 15 bits = 2^15 - 1 = 32767 uses

available uses with 2 type bits: 13 bits = 2^13 - 1 = 8191 uses

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

First of all the second reply i didnt understand anything completly. but i know what you want to tell me. and to the first reply. This bring me to an idea. if i do the metadata as uses for a pick? i mean 1 full metadata with the same pick because this was my idea. make the minecraft tools realistic damage value. but would that work? i mean the item metadata as damage value? (if that work) how can i say this metadatas all picks and this all shovels? and thank you for the answer. between my knowledge of this language is not the best same in the modding but im learning and searching for informations so fast as i can. thats why i ask if my idea with metadata would work how can i make it. i mean to show the damage which left do i know a little. i have more questions but i wait with that when the next answer comes.

Crazy Brain...

Link to comment
Share on other sites

I think the hole night about this and see a few problems. the breaking point. the point there point breaks. like this (id 1500:45000 crafted id 1500:40000 break the tool) how can i do this? (nearby i look to build drops in. but this is confusing).

Crazy Brain...

Link to comment
Share on other sites

If you don't know exactly how to use and understand bit manipulation (bitwise and bit shift operators), look at this:

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

or ask google.

 

If you know how to use it, look at this code from me, carefully:

https://gist.github.com/09f4f1fc4a1918d78b79

 

Notes to this one:

- I use initially negative damage values (e.g. in the crafting recipe) to "hide" the damage bar on certain types.

- I use 5 bits for the type, so I can make max. 32 types (code with [bit operator] 0x1f and [bit operator] 5)

 

Explanation: You see in the constructor:

super(par1, par2EnumToolMaterial);
this.setMaxDamage((par2EnumToolMaterial.getMaxUses() + 1) << 5);

 

I use the EnumToolMaterial to get the max. uses.

With the 2nd line I shift the max uses to the left by 5, that means I increase the max. uses to get the first 5 bits for the type. I had to add 1 to the max. uses first because somehow that caused problems without.

 

To get the first 5 bits, there is code like this:

switch(par1 & 0x1f) {
    	case 2: return 224;
    	case 3: return 226;
    	default: return (par1 & 0x1f) + 236;
}

With value & 0x1F I get the value from the first 5 bits which I reserved in the constructor. 0x1F is by the way 31, so I could also write value & 31.

 

To set the actual damage for this type, you use this:

par1ItemStack.damageItem(1 << 5, par3EntityLiving);

in your onBlockDestroyed / onEntityHit method. 1 is the damage value, it will be shifted 5 bits to the left (like in the constructor) to affect the damage. If the item should be damaged by 2 (for my swords when you destroy a block) just use 2 instead of 1:

par1ItemStack.damageItem(2 << 5, par3EntityLiving);

 

The onUpdate method here is unneccessary, because I doubt that you want to repair the stuff automatically ^^

 

But there is something important: You can't use the vanilla repair recipe (you know, place 2 damaged tools together to get a repaired one), because it gives a shit about reserved bits. I didn't tried enchantments yet, do they repair items when enchanted? If yes, you can't use them either. If no then you can use them.

 

 

Okay, I hope I could help you. :)

 

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

first: thanks. second: i have my own repair recipe. third: i do not use swords. that comes later. forth: what the f..k  i need to extract the code. and you help me a lot. i do ask nearby a little things. thanks thanks thanks thanks.

Crazy Brain...

Link to comment
Share on other sites

Thanks it helpt a lot . but two things. this is at the moment a little over my skill. and i explain my mod now. this mod you build a stick which hold 1000 uses and a pickhead which hold 1500 uses. and when you build the pickaxe it will hold 1000 uses and when it breaks you get the stick back which is damaged and when you use it to craft it the tool will max hold 500 uses. this was my idea and i need the damaged crafting because if not i have to do thousend of thousend enumtools material datas.

Crazy Brain...

Link to comment
Share on other sites

Now i made a testing code. with all i have at the moment inside:

 

 

mod.data

 

package net.minecraft.src;

 

import java.util.Random;

import net.minecraft.client.Minecraft;

 

 

//Mod Made By Speiger

 

public class mod_DynamicTools extends BaseMod

{

 

//Blöcke

 

 

 

 

 

//Items

 

public static Item woodPick = new ItemWoodPick(5000).setItemName("woodPick");

 

 

@Override

public String getVersion()

{

  return "0.1";

}

 

 

 

//WoodenPick

 

public static int woodPick2 = ModLoader.addOverride("/gui/items.png", "/Spmod/Tools/WoodenPick.png");

public static int woodPick3 = ModLoader.addOverride("/gui/items.png", "/Spmod/Tools/WoodenPick.png");

public static int woodPick4 = ModLoader.addOverride("/gui/items.png", "/Spmod/Tools/WoodenPick.png");

 

 

 

 

 

@Override

public void load()

{

ModLoader.addName(new ItemStack(mod_DynamicTools.woodPick, 1, 0), "Wood Pick");

ModLoader.addName(new ItemStack(mod_DynamicTools.woodPick, 1, 1), "Wood Pick");

ModLoader.addName(new ItemStack(mod_DynamicTools.woodPick, 1, 2), "Wood Pick");

 

 

}

 

}

 

 

Item.data

 

package net.minecraft.src;

 

 

public class ItemWoodPick extends Item

{

 

public ItemWoodPick(int id)

{

super(id);

setHasSubtypes(true);

setMaxDamage(0);

}

 

private String[] names = new String[]{"use1", "use2", "use3"};

  //private String[] names = new String[]{"  0  ", "  1  ", "  2  "};

 

public String getItemNameIS(ItemStack itemstack)

{

return names[itemstack.getItemDamage()];

}

 

public int getIconFromDamage(int i)

{

if(i==0)

{

setMaxStackSize(10);

return mod_DynamicTools.woodPick1;

}

if(i==1)

{

setMaxStackSize(10);

return mod_DynamicTools.woodPick2;

}

if(i==2)

{

setMaxStackSize(10);

return mod_DynamicTools.woodPick3;

}

else

{

setMaxStackSize(10);

return mod_DynamicTools.woodPick4;

}

 

}

 

}

 

 

Error Code:

 

 

== MCP 6.2 (data: 6.2, client: 1.2.5, server: 1.2.5) ==

# found jad, jad patches, ff patches, osx patches, srgs, name csvs, doc csvs, pa

ram csvs, astyle, astyle config

== Recompiling client ==

> Cleaning bin

> Recompiling

'"C:\Programme\Java\jdk1.6.0_25\bin\javac" -Xlint:-options -deprecation -g -sour

ce 1.6 -target 1.6 -c...' failed : 1

 

== ERRORS FOUND ==

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:10: cannot find symbol

symbol  : method setHasSubtypes(boolean)

location: class net.minecraft.src.ItemWoodPick

                setHasSubtypes(true);

                ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:11: cannot find symbol

symbol  : method setMaxDamage(int)

location: class net.minecraft.src.ItemWoodPick

                setMaxDamage(0);

                ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:19: cannot find symbol

symbol  : method getItemDamage()

location: class net.minecraft.src.ItemStack

                return names[itemstack.getItemDamage()];

                                      ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:26: cannot find symbol

symbol  : method setMaxStackSize(int)

location: class net.minecraft.src.ItemWoodPick

                        setMaxStackSize(10);

                        ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:27: cannot find symbol

symbol  : variable woodPick1

location: class net.minecraft.src.mod_DynamicTools

                        return mod_DynamicTools.woodPick1;

                                              ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:31: cannot find symbol

symbol  : method setMaxStackSize(int)

location: class net.minecraft.src.ItemWoodPick

                        setMaxStackSize(10);

                        ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:36: cannot find symbol

symbol  : method setMaxStackSize(int)

location: class net.minecraft.src.ItemWoodPick

                        setMaxStackSize(10);

                        ^

 

src\minecraft\net\minecraft\src\ItemWoodPick.java:41: cannot find symbol

symbol  : method setMaxStackSize(int)

location: class net.minecraft.src.ItemWoodPick

                        setMaxStackSize(10);

                        ^

 

src\minecraft\net\minecraft\src\mod_DynamicTools.java:20: cannot find symbol

symbol  : method setItemName(java.lang.String)

location: class net.minecraft.src.ItemWoodPick

public static Item woodPick = new ItemWoodPick(5000).setItemName("woodPick");

                                                    ^

 

9 errors

==================

 

!! Can not find server sources, try decompiling !!

(german)Drücken Sie eine beliebige Taste . . .

Crazy Brain...

Link to comment
Share on other sites

item stone axe. (id 1500:50) distroy block (id 1500:49) hit entity (id 1500:48) this was showing prosses of this what i think. how can i make it to work like this? what do i have to add to this?  if(i==50)    {    }

Crazy Brain...

Link to comment
Share on other sites

Ah I must of read your old post and misunderstood.

Anyways, you have 32000 items, you dont really need to worry about things like this.

As was stated in the first reply, the metadata and damage values are the same thing to Minecraft.

It's either used for one, or the other, not both.

If you want a tool with different usages, you're gunna have to use different ids.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Retexted. ok lex at the second time i understand it. but if i make an tool what have 10000 uses than i would make 10000 tools. maybe you think im silly. im a little not normal but im not silly. the mod make it abel to use the real hardness of the tool. and there is an repair value in it (not like ee) you get the chance to get the item which is not full damaged back when the tool break . (stick have 200 uses pick have 300 uses. = chance to get the pick back) but if you get the pick back then i can't say then you get the 300 uses back that is cheating. thats why i want to make this. 300 uses equal 300 items. and if there is a way to simulate a pick then i use it because with an metadata pickaxe i can craft the pick at every damage. understand? and the things i need the item drop from metadata items and how to simulate tools with metadata. with tools i mean pick , shovel , axe, hoe. thanks for reading.

Crazy Brain...

Link to comment
Share on other sites

Just flat out, no, you can not specify a different tool class based on metadata.

Simple as that.

As for all the other rambling you're talking about, from what I can decipher from that wall of nonsense you want to:

 

1) Have multiple different 'classes' of a tool in a single Item ID, Such as shovel, pickaxe, axe: Answer: Not possible without re-writing a few core classes

2) Have multiple different 'types' have different durability such as iron, vs gold, vs diamond. Answer: Not possible without re-writing a few more core classes.

3) Get a tool back once a item breaks, Answer: Possible we have a event for when a tool breaks.

 

Anyways if you're making 10,000 unique tools, you're doing something wrong, and that's horrible gameplay mechanics, just throwing a shitload of something at the player does not make your mod interesting, or unique, or anything more then a passing novelty.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

ok thanks for an answer. and is there a way to if i do an enum tool material tool... (limit of my language knowledge) to craft damaged tool i do not metadata. because that would help to. p.s. there must be a way to make this. there is always a way to solve every problem. but i think that what i want to make is a lot to high for me, but i do not give up.

Crazy Brain...

Link to comment
Share on other sites

I try to explain my mod. i played a lot of minecraft. and there was a few things i didn't like. first where is the technic. and the other why does the tools break so fast, and why after the same uses. an my mod (if i get him work) make it like this: tools do not break to 100% Only if both sides are full damaged. the uses are now better defined and have a realistic. slimeball , strings , reed(bambus) have new functions. to hold the tool at lvl stone. if you would not use them you would have 10% Of the uses but you get the parts back. at the momend planned at the diamodpick. you get a chance if the pick break less 1000 to get diamod dust (and to get the parts back too) that can be used for repair other diamond tool a little(at the moment i think how much) and i say it directly the idea comes from EE but not so oversized. thats why the name Dynamic Tools. things i forgot. normal tools are no longer to craft (i do not forgot rp2 an bc2/3) i hope i can make an api to rp2 and buildcraft but recipes are finish. thx.

Crazy Brain...

Link to comment
Share on other sites

Wow, you're starting to give me a headake, anyways The final answer is no, without re-writing a crapload of base classes there is no way to do what you want when it comes to metatdata and tools.

Everything else you want to do is perfectly fine, unoriginal, and simple to do.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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