Bloc Orientable (TileEntity)
-
Je n’en n’est pas besoin, le tuto ( http://www.minecraftforgefrance.fr/showthread.php?tid=1304 ) utilise, en gros , la rotation d’une TileEntity, or, je n’utilise pas une TileEntity, mais un .json
-
Ah oui, j’avais oublié le titre… Il faut regarder les classes de minecraft avant de demander de l’aide :
- Mets ton block extend BlockDirectional
- Dans le constructeur, ajoutes ceci :
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); - Ré-écris la fonction onBlockPlaced et rajoutes ceci dedans :
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); - Ré-écris la fonction getStateFromMeta si tu veux utiliser les metadatas pour orienter ton block
return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); - Ré-écris la fonction createBlockState
return new BlockState(this, new IProperty[] {FACING});
-
Euh… Je ne vois aps du tout de quoi tu veut parler par :
[size=x-smallRé-écris la fonction onBlockPlaced et rajoutes ceci dedans :]
~~[size=x-smallRé-écris la fonction getStateFromMeta si tu veux utiliser les metadatas pour orienter ton block]
~~[size=x-smallRé-écris la fonction createBlockState]
[size=small~~J’ai peut-etre , dans ma puissance naturelle, mal codé mon bloc donc , voici ma classe ~~ C’EST BON J’AI COMPRIS]package eryah.usefulthings.blocks; import javax.swing.Icon; import net.minecraft.block.Block; import net.minecraft.block.BlockDirectional; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class PlateCrafter extends BlockDirectional { public static Block platecrafter; { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public static void init() { platecrafter = new ResinLog(Material.wood).setUnlocalizedName("platecrafter").setCreativeTab(UsefulthingsMod.UTTab); } protected PlateCrafter(Material materialIn) { super(materialIn); // TODO Auto-generated constructor stub } public static void register() { GameRegistry.registerBlock(platecrafter, platecrafter.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(platecrafter); } public static void registerRender(Block block) { Item item = Item.getItemFromBlock(block); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } } ```~~~~ -
Quel est ce morceau de code tout seul au milieu de nulle part ?
public static Block platecrafter; { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); }Il faut le mettre dans le constructeur et il te manque toutes les méthodes que j’ai cité précédemment.
-
Une erreur sur
@Override public IBlockState getStateFromMeta(int meta) { return ((EnumFacing)blockState.getValue(FACING)).getHorizontalIndex(); }((EnumFacing)blockState.getValue(FACING)).getHorizontalIndex();
*Multiple markers at this line
*-
- Type mismatch: cannot convert from int to *
IBlockState
Il me propose de ajouter ‘int’ et après, y’a un erreur sur int, enfin… plein d’erreurs qui forment un boucle
- Type mismatch: cannot convert from int to *
-
-
@‘SCAREX’:
Quel est ce morceau de code tout seul au milieu de nulle part ?
public static Block platecrafter; { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); }Il faut le mettre dans le constructeur et il te manque toutes les méthodes que j’ai cité précédemment.
Dès que je l’enlève, il y a des erreurs partout, je dirait 1 toutes les 4 lignes
Et je n’avais pas compris comment ajouter les méthodes quand j’ai posté le message
-
Regarde la classe de la pumpkin, car là j’en peux plus…
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));CECI VA DANS LE CONSTRUCTEUR ! Si tu ne sait pas ce qu’est un constructeur : OpenClassrooms
Pour les autres lignes de code, voici le code à rajouter :
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING}); } -
Implicit super constructor BlockDirectional() is undefined. Must explicitly invoke another constructor
quand je mets le curseur surpublic static PlateCrafter() { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); }PlateCrafter()
Ce que j’avais avant était un constructeur, mais il avait (je ne sais aps pourquoi, mauvais copier coller de ma part ( oui je fais les blocs comme ça )) ‘Block’ en trop
-
le constructeur ne devrait pas être statique. Quel est ton code en ce moment ?
-
package eryah.usefulthings.blocks; import net.minecraft.block.Block; import net.minecraft.block.BlockDirectional; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class PlateCrafter extends BlockDirectional { public static Block platecrafter; { } public PlateCrafter() { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING}); } public static void init() { platecrafter = new ResinLog(Material.wood).setUnlocalizedName("platecrafter").setCreativeTab(UsefulthingsMod.UTTab); } protected PlateCrafter(Material materialIn) { super(materialIn); // TODO Auto-generated constructor stub } public static void register() { GameRegistry.registerBlock(platecrafter, platecrafter.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(platecrafter); } public static void registerRender(Block block) { Item item = Item.getItemFromBlock(block); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } }C’était un mauvais copier coller, dans mon tout premier bloc, le constructeur est présent ( y’a rien dedans, mais il est la )
-
Ces crochets ne servent à rien :
public static Block platecrafter; { }Ton sujet est résolu ?
-
Y’a toujours la même erreur
Multiple markers at this line- Illegal modifier for the constructor in type PlateCrafter; only public, protected & private are
permitted ( Pourtant c’est bien public PlateCrafter() ) - Implicit super constructor BlockDirectional() is undefined. Must explicitly invoke another
constructor
Sur Platecrafter()
- Illegal modifier for the constructor in type PlateCrafter; only public, protected & private are
-
Tu as 2 constructeurs
-
Si j’en est 2, je ne voit aps le 2e
package eryah.usefulthings.blocks; import net.minecraft.block.Block; import net.minecraft.block.BlockDirectional; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class PlateCrafter extends BlockDirectional { public static Block platecrafter; public PlateCrafter() { this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING}); } public static void init() { platecrafter = new ResinLog(Material.wood).setUnlocalizedName("platecrafter").setCreativeTab(UsefulthingsMod.UTTab); } public static void register() { GameRegistry.registerBlock(platecrafter, platecrafter.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(platecrafter); } public static void registerRender(Block block) { Item item = Item.getItemFromBlock(block); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } } -
Tu as supprimé le 2ème dans ce dernier code.
-
Oui, mais j’ai toujours le problème
( Mais pas tout à fait le même… Je l’avais au tout debut *Implicit super constructor BlockDirectional() is undefined. Must explicitly invoke another constructor *) -
Car ça devrait être :
public PlateCrafter(Material material) { super(material); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); }Sérieusement apprend le java sinon tu vas mouliner encore longtemps ….
-
J apprend… J apprend. Ce mod me sert à apprendre. Je touche un peu à tout grâce à ce mod. Quand je voudrait faire un truc précis dans un sujet précis, je saurais déjà le faire. Maintenant, si j’ai cette erreur plus tard je saurais que ceci est l’à solution
Envoyé de mon SM-G357FZ en utilisant Tapatalk
-
Erreur, le model de mon bloc disparait
dans les logs il y a marqué :
[09:31:35] [Client thread/ERROR] [FML]: Model definition for location ut:platecrafter#facing=east not found
[09:31:35] [Client thread/ERROR] [FML]: Model definition for location ut:platecrafter#facing=south not found
[09:31:35] [Client thread/ERROR] [FML]: Model definition for location ut:platecrafter#facing=north not found
[09:31:35] [Client thread/ERROR] [FML]: Model definition for location ut:platecrafter#facing=west not found -
Dans ton .json, il faut que tu rajoutes un model pour chaque orientation.