Des problème pour concevoir un arbre moddé
-
Bonjour à tous,
Tous d’abord, je tien a vous dire que je débute la programmation sous forge, soyez donc indulgent avec moi.
Si je viens ici, c’est pour demander votre aide, puisque je rencontre des problèmes dans la création de mon arbre. Je souhaiterais creer un Sakura dans mon mod.J’ai donc creer les Item principaux qui en découle, à savoir: Les buches de Sakura
Les Feuilles de Sakura
Les pousses de Sakura
et les planches de Sakura, ici inutile dans la création de l’arbreVoilà la partie de ma classe ModedBlock ou j’ai créé ces block:
public class modedBlock { public static Block SakuraLeaves; public static Block planks_Sakura; public static Block log_Sakura; public static Block sapling_Sakura; public static void init() { SakuraLeaves = new BlockMod(Material.leaves).setUnlocalizedName("SakuraLeaves").setCreativeTab(CreativeTabs.tabDecorations); planks_Sakura = new BlockMod(Material.wood).setUnlocalizedName("planks_Sakura").setCreativeTab(CreativeTabs.tabBlock).setHardness(5.0F); log_Sakura = new BlockMod(Material.wood).setUnlocalizedName("log_Sakura").setCreativeTab(CreativeTabs.tabBlock).setHardness(5.0F); sapling_Sakura = new BlockMod(Material.plants).setUnlocalizedName("sapling_Sakura").setCreativeTab(CreativeTabs.tabDecorations); } public static void register () { GameRegistry.registerBlock(SakuraLeaves, SakuraLeaves.getUnlocalizedName().substring(5)); GameRegistry.registerBlock(planks_Sakura, planks_Sakura.getUnlocalizedName().substring(5)); GameRegistry.registerBlock(log_Sakura, log_Sakura.getUnlocalizedName().substring(5)); GameRegistry.registerBlock(sapling_Sakura, sapling_Sakura.getUnlocalizedName().substring(5)); /**Craft & recipe */ GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", " # ", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", "# ", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", " #", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" # ", " ", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {"# ", " ", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" #", " ", " ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", " ", " # ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", " ", "# ", '#', modedBlock.log_Sakura}); GameRegistry.addRecipe(new ItemStack(modedBlock.planks_Sakura, 4), new Object[] {" ", " ", " #", '#', modedBlock.log_Sakura}); } public static void registerRenders() { registerRender(SakuraLeaves); registerRender(planks_Sakura); registerRender(log_Sakura); registerRender(sapling_Sakura); } public static void registerRender(Block block) { Item item = Item.getItemFromBlock(block); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(AstralliaMod.MODID + ":" + item.getUnlocalizedName().substring(5), "Inventory")); }
Pour la suite, j’ai vu dans des tutoriels 1.7.10 qu’il fallais creer une classe pour chaque blocks et une classe de génération de l’arbre, mais c’est ici que je bloque.
Premièrement, je ne sais trop quoi mettre dans la classe des mes blocks, et le tutoriel étant en 1.7.10, je craint que le code que j’ai tenté d’utiliser ne soit invalide.
Ensuite pour la classe de génération que j’ai nommé AstralliaWorldGenTrees, je me suis basé sur la classe WorldGenTrees présente.
Voilà ce à quoi elle correspond actuellement:package com.itsskylow.astralliamod.world; import java.util.Random; import com.itsskylow.astralliamod.init.modedBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockVine; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenAbstractTree; public class AstralliaWorldGenTrees extends WorldGenAbstractTree { /** The minimum height of a generated tree. */ private final int minTreeHeight; /** True if this tree should grow Vines. */ private final boolean vinesGrow; /** The metadata value of the wood to use in tree generation. */ private final int metaWood; /** The metadata value of the leaves to use in tree generation. */ private final int metaLeaves; private static final String __OBFID = "CL_00000438"; public AstralliaWorldGenTrees(boolean p_i2027_1_) { this(p_i2027_1_, 4, 0, 0, false); } public AstralliaWorldGenTrees(boolean p_i2028_1_, int p_i2028_2_, int p_i2028_3_, int p_i2028_4_, boolean p_i2028_5_) { super(p_i2028_1_); this.minTreeHeight = p_i2028_2_; this.metaWood = p_i2028_3_; this.metaLeaves = p_i2028_4_; this.vinesGrow = p_i2028_5_; } public boolean generate(World worldIn, Random p_180709_2_, BlockPos p_180709_3_) { int i = p_180709_2_.nextInt(3) + this.minTreeHeight; boolean flag = true; if (p_180709_3_.getY() >= 1 && p_180709_3_.getY() + i + 1 <= 256) { byte b0; int l; for (int j = p_180709_3_.getY(); j <= p_180709_3_.getY() + 1 + i; ++j) { b0 = 1; if (j == p_180709_3_.getY()) { b0 = 0; } if (j >= p_180709_3_.getY() + 1 + i - 2) { b0 = 2; } for (int k = p_180709_3_.getX() - b0; k <= p_180709_3_.getX() + b0 && flag; ++k) { for (l = p_180709_3_.getZ() - b0; l <= p_180709_3_.getZ() + b0 && flag; ++l) { if (j >= 0 && j < 256) { if (!this.isReplaceable(worldIn, new BlockPos(k, j, l))) { flag = false; } } else { flag = false; } } } } if (!flag) { return false; } else { BlockPos down = p_180709_3_.down(); Block block1 = worldIn.getBlockState(down).getBlock(); boolean isSoil = block1.canSustainPlant(worldIn, down, net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling)modedBlock.sapling_Sakura); if (isSoil && p_180709_3_.getY() < 256 - i - 1) { block1.onPlantGrow(worldIn, down, p_180709_3_); b0 = 3; byte b1 = 0; int i1; int j1; int k1; int l1; BlockPos blockpos1; for (l = p_180709_3_.getY() - b0 + i; l <= p_180709_3_.getY() + i; ++l) { i1 = l - (p_180709_3_.getY() + i); j1 = b1 + 1 - i1 / 2; for (k1 = p_180709_3_.getX() - j1; k1 <= p_180709_3_.getX() + j1; ++k1) { l1 = k1 - p_180709_3_.getX(); for (int i2 = p_180709_3_.getZ() - j1; i2 <= p_180709_3_.getZ() + j1; ++i2) { int j2 = i2 - p_180709_3_.getZ(); if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || p_180709_2_.nextInt(2) != 0 && i1 != 0) { blockpos1 = new BlockPos(k1, l, i2); Block block = worldIn.getBlockState(blockpos1).getBlock(); if (block.isAir(worldIn, blockpos1) || block.isLeaves(worldIn, blockpos1) || block.getMaterial() == Material.vine) { this.func_175905_a(worldIn, blockpos1, modedBlock.SakuraLeaves, this.metaLeaves); } } } } } for (l = 0; l < i; ++l) { BlockPos upN = p_180709_3_.up(l); Block block2 = worldIn.getBlockState(upN).getBlock(); if (block2.isAir(worldIn, upN) || block2.isLeaves(worldIn, upN) || block2.getMaterial() == Material.vine) { this.func_175905_a(worldIn, p_180709_3_.up(l), modedBlock.log_Sakura, this.metaWood); if (this.vinesGrow && l > 0) { if (p_180709_2_.nextInt(3) > 0 && worldIn.isAirBlock(p_180709_3_.add(-1, l, 0))) { this.func_175905_a(worldIn, p_180709_3_.add(-1, l, 0), Blocks.vine, BlockVine.EAST_FLAG); } if (p_180709_2_.nextInt(3) > 0 && worldIn.isAirBlock(p_180709_3_.add(1, l, 0))) { this.func_175905_a(worldIn, p_180709_3_.add(1, l, 0), Blocks.vine, BlockVine.WEST_FLAG); } if (p_180709_2_.nextInt(3) > 0 && worldIn.isAirBlock(p_180709_3_.add(0, l, -1))) { this.func_175905_a(worldIn, p_180709_3_.add(0, l, -1), Blocks.vine, BlockVine.SOUTH_FLAG); } if (p_180709_2_.nextInt(3) > 0 && worldIn.isAirBlock(p_180709_3_.add(0, l, 1))) { this.func_175905_a(worldIn, p_180709_3_.add(0, l, 1), Blocks.vine, BlockVine.NORTH_FLAG); } } } } if (this.vinesGrow) { for (l = p_180709_3_.getY() - 3 + i; l <= p_180709_3_.getY() + i; ++l) { i1 = l - (p_180709_3_.getY() + i); j1 = 2 - i1 / 2; for (k1 = p_180709_3_.getX() - j1; k1 <= p_180709_3_.getX() + j1; ++k1) { for (l1 = p_180709_3_.getZ() - j1; l1 <= p_180709_3_.getZ() + j1; ++l1) { BlockPos blockpos3 = new BlockPos(k1, l, l1); if (worldIn.getBlockState(blockpos3).getBlock().isLeaves(worldIn, blockpos3)) { BlockPos blockpos4 = blockpos3.west(); blockpos1 = blockpos3.east(); BlockPos blockpos5 = blockpos3.north(); BlockPos blockpos2 = blockpos3.south(); if (p_180709_2_.nextInt(4) == 0 && worldIn.getBlockState(blockpos4).getBlock().isAir(worldIn, blockpos4)) { this.func_175923_a(worldIn, blockpos4, BlockVine.EAST_FLAG); } if (p_180709_2_.nextInt(4) == 0 && worldIn.getBlockState(blockpos1).getBlock().isAir(worldIn, blockpos1)) { this.func_175923_a(worldIn, blockpos1, BlockVine.WEST_FLAG); } if (p_180709_2_.nextInt(4) == 0 && worldIn.getBlockState(blockpos5).getBlock().isAir(worldIn, blockpos5)) { this.func_175923_a(worldIn, blockpos5, BlockVine.SOUTH_FLAG); } if (p_180709_2_.nextInt(4) == 0 && worldIn.getBlockState(blockpos2).getBlock().isAir(worldIn, blockpos2)) { this.func_175923_a(worldIn, blockpos2, BlockVine.NORTH_FLAG); } } } } } if (p_180709_2_.nextInt(5) == 0 && i > 5) { for (l = 0; l < 2; ++l) { for (i1 = 0; i1 < 4; ++i1) { if (p_180709_2_.nextInt(4 - l) == 0) { j1 = p_180709_2_.nextInt(3); EnumFacing enumfacing = EnumFacing.getHorizontal(i1).getOpposite(); this.func_175905_a(worldIn, p_180709_3_.add(enumfacing.getFrontOffsetX(), i - 5 + l, enumfacing.getFrontOffsetZ()), Blocks.cocoa, j1 << 2 | EnumFacing.getHorizontal(i1).getHorizontalIndex()); } } } } } return true; } else { return false; } } } else { return false; } } private void func_175923_a(World worldIn, BlockPos p_175923_2_, int p_175923_3_) { this.func_175905_a(worldIn, p_175923_2_, Blocks.vine, p_175923_3_); int j = 4; for (p_175923_2_ = p_175923_2_.down(); worldIn.getBlockState(p_175923_2_).getBlock().isAir(worldIn, p_175923_2_) && j > 0; –j) { this.func_175905_a(worldIn, p_175923_2_, Blocks.vine, p_175923_3_); p_175923_2_ = p_175923_2_.down(); } } }
Pourriez vous me venir en aide et m’orienter dans la démarche à suivre ?
Cordialement,
Un novice qui attend votre aide,
itsSkylow -
Bonjour (et bienvenue), pour mettre les bonnes fonctions dans tes blocks, regarde les classes des blocks vanilla et recopie leurs fonction en les modifiants pour ce que tu souhaites faire, si tu bloques à quelque chose ou tu ne comprends pas quelque chose, n’hésite pas à demander.
-
d’accord, merci, je vais m’attacher à faire ce que tu m’a conseillé pour les blocks. Je te tiens au courant de ma progression.