Started by
Kane
on
Topic category: Help with Minecraft modding (Java Edition)
"Schematic you try to import is bigger than 1600 blocks...[]. If you can code, you can fix this by splitting method in smaller ones...[]"
Ok, How can I do it?
@#2.2.1.1.1.1.1.1.1 Nice to know, thx again
Useless to say that I'd need to know how to get chests with Items that I want in them, but it will require more time and efforts from you and I'd have a guilty conscience
(if you have some time for this I will leave you alone for a while :D )
I read about how to do it in MCreator by another user, but he showed a quite strange way to do it (filling every slot of the chest with an item, then add a "randomization" to have different probability to find more of an object and less of other ones, but still filling every slot of the chest.
While searching on internet I found other way to do it, more similar to what I need, but all outdated and not really helpfull with my low knowledge
@#2.2.1.1.1.1.1.1.1.1 I am using this one and it fills +- 3 slots:
TileEntityChest chest = (TileEntityChest) world.getTileEntity(new BlockPos(i, j, k));
for (int containerSlot = 0; containerSlot < ((TileEntityChest) chest).getSizeInventory(); containerSlot++) {
int chance = (int)(Math.random()*100);
int quantity = ((int)(Math.random()*10) / 2);
if(quantity >= 1){
if (chance == 90) {
//ITEM 1
chest.setInventorySlotContents(containerSlot, new ItemStack(mcreator_pistolBullet.block, quantity));
}
else if (chance == 48) {
//ITEM 2
chest.setInventorySlotContents(containerSlot, new ItemStack(mcreator_scrapIron.block, quantity));
}
else if (chance < 8) {
//ITEM 3
chest.setInventorySlotContents(containerSlot, new ItemStack(Items.rotten_flesh, quantity + 2));
}
else if (chance < 20 && chance > 15) {
//ITEM 4
chest.setInventorySlotContents(containerSlot, new ItemStack(Items.paper, quantity + 1));
}
}
}
@#2.2.1.1.1.1.1.1.1.1.1 Really nice
What does this mean: *10) / 2 in int quantity?
And I knew there's a way to get enchanted tools.
With this way, it's easy to do or it requires some other string?
@#2.2.1.1.1.1.1.1.1.1.1.1
((int)(Math.random()*10) generates a random number from 0 to 10
/2 it devides by 2 , so for example from number 10 is 5.
For enchanted item you need first make a new variable of type ItemStack.
ItemStack stack = new ItemStack(Items.wooden_hoe)
And then you need this method:
stack.addEnchantment(Enchantment.sharpness, 4);
Last thing is asign this variable to the loot spawn code.
chest.setInventorySlotContents(containerSlot, stack);
@#2.2.1.1.1.1.1.1.1.1.1.1.1 So it should look like this:
TileEntityChest chest = (TileEntityChest) world.getTileEntity(new BlockPos(i, j, k));
for (int containerSlot = 0; containerSlot < ((TileEntityChest) chest).getSizeInventory(); containerSlot++) {
int chance = (int)(Math.random()*100);
int quantity = ((int)(Math.random()*10) / 2);
if(quantity >= 1){
if (chance == 50) {
//ITEM 1
ItemStack stack = new ItemStack(Items.iron_pickaxe);
stack.addEnchantment(Enchantment.unbreaking, 3);
chest.setInventorySlotContents(containerSlot, stack, quantity);
}
}
}
???
And the quantity of the item I can get is max 5 and min 1 if chance is 50, right?
@#2.2.1.1.1.1.1.1.1.1.1.1.1 I get cannot find symbol: variable Items (even for non-enchanted items)
and cannot find symbol: variable Enchantment that I fixed with this import:
import net.minecraft.enchantment.Enchantment;
But now I get cannot find symbol: variable sharpness
I've took a look a bit everywhere and this code seems to be perfect but I get them :/
Try import:
import net.minecraft.item.*;
import net.minecraft.enchantment.*;
@#4 just done that, and still get same errors (cannot find variable items and sharpness)
I tried to change to iron_sword with sharpness or other enchantments and items, but still get the same errors (for every enchantments it seems)
It should work. The problem is that new MCreator uses only imports that are needed for the basic funtion of the element. In the older ones there was almost all possible imports. (But this imports users did not use very much + they caused slowing performance so they were removed). Hm... try import net.minecraft.*;
If it will not work , send me the code.
@#5 I see, they should implement the "ctrl + shift + O" of Eclypse :P
But still get error... I can't figure out where is the trick here, it seems good and I haven't mistyped (I think) anything.
here it is: chest code
Sorry for abusing your knowledge D:
@#5.1 Hmm .. you are using MCreator for 1.9+? If so , it is because 1.9 changed paths and some names. I will download the 1.9 classes at evening (of Central European Time)
@#5.1.1 Yeah, I guessed it and tried to find something helpful, but I didn't. ty
@#5.1.1.1 Try:
These imports:
import net.minecraft.item.ItemStack;
import net.minecraft.init.Items;
import net.minecraft.enchantment.Enchantment;
And the code should be something like this:
ItemStack stack = new ItemStack(Items.DIAMOND_SWORD);
stack.addEnchantment(Enchantment.getEnchantmentByLocation("sharpness"), 3);
chest.setInventorySlotContents(containerSlot, stack);
@#5.1.1.1.1 I have really no words...
It works perfectly now! I really should build you a statue!
When my mod will be finished there will be tons of credits about you and thanks, if you want to "appear" in my mod, as mob, weapon, armor, statue, just tell me ;)
Another thing, just curiosity, to find this infos, did you decompile something or "simply" wrote this code in eclypse (with forge for 1.9) and saw what was wrong?
Lastly, do you grant me the "permission" to spread these infos around, for example with video tutorial (obviously giving you all the credits and if you have a site/youtube channel/socialmedia page/etc. I can add it/them), or you prefer that this thing remains "confidential" in this forum?