Challenge - Pièce fermée
-
j’en sais rien mais moi j’ai fini la chose en partant du principe qu’une piece de 320 par je ne sais combien par 320 était un piece ouverte du coup pas besoin de charger les chunk
-
j’en sais rien mais moi j’ai fini contacter moi par mp

-
bon apres environ 1 mois d’attente je poste le code
:::
classe principlalepackage com.mathiasetampes.algorythme.common; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraftforge.common.MinecraftForge; import com.mathiasetampes.algorythme.proxy.CommonProxy; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "algorythme",name="Algorytme",version="1.0.0") public class algorythme { @Instance("algorythme") public static algorythme instance; public static final String MODID = "villagePNJ"; @SidedProxy(clientSide = "com.mathiasetampes.algorythme.proxy.ClientProxy", serverSide = "com.mathiasetampes.algorythme.proxy.CommonProxy") public static CommonProxy proxy; public static Block algo; @EventHandler public void preInit(FMLPreInitializationEvent event) { algo = new Algo(Material.rock).setBlockName("Algo").setBlockTextureName("modtutoriel:block_tutoriel"); GameRegistry.registerBlock(algo, "block_tutoriel"); GameRegistry.registerTileEntity(TileEntityAire.class, "algorythme:TileEntityAire"); } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); FMLCommonHandler.instance().bus().register(new AllEvent()); MinecraftForge.EVENT_BUS.register(new AllEvent()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }classe du block
package com.mathiasetampes.algorythme.common; import java.util.Random; import com.mojang.realmsclient.dto.PlayerInfo; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class Algo extends Block { public static int Intermediaire = 0; public String marqueur[][][] = new String[320][256][320]; public int xDepart,zDepart = 0 ; public boolean Interieur,Erreur = false; public EntityPlayer playerV; protected Algo(Material material) { super(material); this.setCreativeTab(CreativeTabs.tabBlock); this.setTickRandomly(true); for(int i = 0; i< 320; i++) { for(int j = 0; j< 256; j++) { for(int k = 0; k< 320; k++) { marqueur*[j][k] = ""; } } } } public void updateTick(World world, int x, int y, int z, Random random ) // { world.scheduleBlockUpdate(x, y, z, algorythme.algo, 120); if((Intermediaire==15 || Intermediaire==25)&& Erreur==true) { AlgorythmeVide(world ,x , y , z,x , y , z); Erreur = false; } else if(Interieur == true && marqueur[xDepart-playerV.getPlayerCoordinates().posX+160][playerV.getPlayerCoordinates().posY][zDepart-playerV.getPlayerCoordinates().posZ+160].contains(Ids(world,x,y,z))==false &&(Intermediaire!=15 && Intermediaire!=25))//Ids(world,x,y,z) { Interieur = false ; System.out.println(playerV.getPlayerCoordinates().posX); playerV.addChatMessage(new ChatComponentTranslation("tile.chat.1")); AlgorythmeVide(world , x , y , z ,x,y,z); } } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityAire(); } @Override public boolean hasTileEntity(int metadata) { return true; } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { xDepart = x; zDepart = z; Intermediaire = Algorythme(world ,x ,y ,z,x , y , z); playerV = player; if(Intermediaire==5){player.addChatMessage(new ChatComponentTranslation("tile.chat.2"));} else if(Intermediaire==25){player.addChatMessage(new ChatComponentTranslation("tile.chat.3"));} else if(Intermediaire==35){player.addChatMessage(new ChatComponentTranslation("tile.chat.4"));} else if(Intermediaire==15){player.addChatMessage(new ChatComponentTranslation("tile.chat.5"));} return true; } return false; } public int Algorythme(World world ,int x , int y , int z,int xSrc,int ySrc,int zSrc) { if(xDepart-x+160<320 && xDepart-x+160 > 0 && zDepart-z+160<320 && zDepart-z+160 > 0) { if((world.getBlock(x, y, z) == Blocks.air || world.getBlock(x, y, z) == algorythme.algo)&& marqueur[xDepart-x+160][y][zDepart-z+160].contains(Ids(world,xSrc,ySrc,zSrc))== false) { for(int i = y; i < 256 ; i++) { if(world.getBlock(x, i, z) != Blocks.air && world.getBlock(x, i, z) != algorythme.algo) { break; } if(i == 254) { Erreur = true ; System.out.println("extérieur"); return 25; } } marqueur[xDepart-x+160][y][zDepart-z+160]=marqueur[xDepart-x+160][y][zDepart-z+160]+Ids(world ,xSrc, ySrc , zSrc); System.out.println("x="+x+" y="+y+" z="+z ); if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y+1 , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x+1 , y , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x-1 , y , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y , z+1,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y , z-1,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} Interieur = true ; return 5; } Erreur = true ; return 35; } return 15; } public void AlgorythmeVide(World world ,int x , int y , int z,int xSrc,int ySrc,int zSrc) { if((world.getBlock(x, y, z) == Blocks.air || world.getBlock(x, y, z) == algorythme.algo)&& marqueur[xDepart-x+160][y][zDepart-z+160].contains(Ids(world,xSrc,ySrc,zSrc))== true) { marqueur[xDepart-x+160][y][zDepart-z+160] = marqueur[xDepart-x+160][y][zDepart-z+160].replace(Ids(world ,xSrc, ySrc , zSrc) ,""); //peut etre un bug à cause de Ids qui est un string et non un cahr sequence AlgorythmeVide(world , x , y-1 , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y+1 , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x+1 , y , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x-1 , y , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y , z+1,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y , z-1,xSrc , ySrc , zSrc); return; } return; } public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); world.scheduleBlockUpdate(x, y, z, algorythme.algo, 15); } public String Ids(World world , int x ,int y ,int z) { TileEntity te = world.getTileEntity(x, y, z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { TileEntityAire tileTuto = (TileEntityAire)te; return ","+tileTuto.getIdsString(); } return ""; } }classe de la tileEntity
package com.mathiasetampes.algorythme.common; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityAire extends TileEntity { public int ids; public String str = ""; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.ids = compound.getInteger("Ids"); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("Ids", this.ids); } public void UpIds(int i) { this.ids=i; return; } public int getIds() { return this.ids; } public String getIdsString() { str=""; str=str+ids; return this.str; } }classe des events
package com.mathiasetampes.algorythme.common; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.PlaceEvent; public class AllEvent { int TabIds[] = new int[50]; @SubscribeEvent public void PlaceEvent(PlaceEvent event) { TileEntity te = event.world.getTileEntity(event.x, event.y, event.z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { for(int i = 0;i<50;i++) { TileEntityAire tileTuto = (TileEntityAire)te; if(TabIds*!=1) { tileTuto.UpIds(i); TabIds* = 1; break; } } } } public void BreakEvent(BlockEvent.BreakEvent event) { TileEntity te = event.world.getTileEntity(event.x, event.y, event.z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { TileEntityAire tileTuto = (TileEntityAire)te; TabIds[tileTuto.getIds()] = 0; } } }:::
-
@‘Asmath’:
bon apres environ 1 mois d’attente je poste le code
:::
classe principlalepackage com.mathiasetampes.algorythme.common; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraftforge.common.MinecraftForge; import com.mathiasetampes.algorythme.proxy.CommonProxy; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "algorythme",name="Algorytme",version="1.0.0") public class algorythme { @Instance("algorythme") public static algorythme instance; public static final String MODID = "villagePNJ"; @SidedProxy(clientSide = "com.mathiasetampes.algorythme.proxy.ClientProxy", serverSide = "com.mathiasetampes.algorythme.proxy.CommonProxy") public static CommonProxy proxy; public static Block algo; @EventHandler public void preInit(FMLPreInitializationEvent event) { algo = new Algo(Material.rock).setBlockName("Algo").setBlockTextureName("modtutoriel:block_tutoriel"); GameRegistry.registerBlock(algo, "block_tutoriel"); GameRegistry.registerTileEntity(TileEntityAire.class, "algorythme:TileEntityAire"); } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); FMLCommonHandler.instance().bus().register(new AllEvent()); MinecraftForge.EVENT_BUS.register(new AllEvent()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }classe du block
package com.mathiasetampes.algorythme.common; import java.util.Random; import com.mojang.realmsclient.dto.PlayerInfo; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class Algo extends Block { public static int Intermediaire = 0; public String marqueur[][][] = new String[320][256][320]; public int xDepart,zDepart = 0 ; public boolean Interieur,Erreur = false; public EntityPlayer playerV; protected Algo(Material material) { super(material); this.setCreativeTab(CreativeTabs.tabBlock); this.setTickRandomly(true); for(int i = 0; i< 320; i++) { for(int j = 0; j< 256; j++) { for(int k = 0; k< 320; k++) { marqueur*[j][k] = ""; } } } } public void updateTick(World world, int x, int y, int z, Random random ) // { world.scheduleBlockUpdate(x, y, z, algorythme.algo, 120); if((Intermediaire==15 || Intermediaire==25)&& Erreur==true) { AlgorythmeVide(world ,x , y , z,x , y , z); Erreur = false; } else if(Interieur == true && marqueur[xDepart-playerV.getPlayerCoordinates().posX+160][playerV.getPlayerCoordinates().posY][zDepart-playerV.getPlayerCoordinates().posZ+160].contains(Ids(world,x,y,z))==false &&(Intermediaire!=15 && Intermediaire!=25))//Ids(world,x,y,z) { Interieur = false ; System.out.println(playerV.getPlayerCoordinates().posX); playerV.addChatMessage(new ChatComponentTranslation("tile.chat.1")); AlgorythmeVide(world , x , y , z ,x,y,z); } } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityAire(); } @Override public boolean hasTileEntity(int metadata) { return true; } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { xDepart = x; zDepart = z; Intermediaire = Algorythme(world ,x ,y ,z,x , y , z); playerV = player; if(Intermediaire==5){player.addChatMessage(new ChatComponentTranslation("tile.chat.2"));} else if(Intermediaire==25){player.addChatMessage(new ChatComponentTranslation("tile.chat.3"));} else if(Intermediaire==35){player.addChatMessage(new ChatComponentTranslation("tile.chat.4"));} else if(Intermediaire==15){player.addChatMessage(new ChatComponentTranslation("tile.chat.5"));} return true; } return false; } public int Algorythme(World world ,int x , int y , int z,int xSrc,int ySrc,int zSrc) { if(xDepart-x+160<320 && xDepart-x+160 > 0 && zDepart-z+160<320 && zDepart-z+160 > 0) { if((world.getBlock(x, y, z) == Blocks.air || world.getBlock(x, y, z) == algorythme.algo)&& marqueur[xDepart-x+160][y][zDepart-z+160].contains(Ids(world,xSrc,ySrc,zSrc))== false) { for(int i = y; i < 256 ; i++) { if(world.getBlock(x, i, z) != Blocks.air && world.getBlock(x, i, z) != algorythme.algo) { break; } if(i == 254) { Erreur = true ; System.out.println("extérieur"); return 25; } } marqueur[xDepart-x+160][y][zDepart-z+160]=marqueur[xDepart-x+160][y][zDepart-z+160]+Ids(world ,xSrc, ySrc , zSrc); System.out.println("x="+x+" y="+y+" z="+z ); if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y+1 , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x+1 , y , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x-1 , y , z,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y , z+1,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} if(Algorythme(world , x , y , z-1,xSrc , ySrc , zSrc)==25){return 25;} else if(Algorythme(world , x , y-1 , z,xSrc , ySrc , zSrc )==15){return 15;} Interieur = true ; return 5; } Erreur = true ; return 35; } return 15; } public void AlgorythmeVide(World world ,int x , int y , int z,int xSrc,int ySrc,int zSrc) { if((world.getBlock(x, y, z) == Blocks.air || world.getBlock(x, y, z) == algorythme.algo)&& marqueur[xDepart-x+160][y][zDepart-z+160].contains(Ids(world,xSrc,ySrc,zSrc))== true) { marqueur[xDepart-x+160][y][zDepart-z+160] = marqueur[xDepart-x+160][y][zDepart-z+160].replace(Ids(world ,xSrc, ySrc , zSrc) ,""); //peut etre un bug à cause de Ids qui est un string et non un cahr sequence AlgorythmeVide(world , x , y-1 , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y+1 , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x+1 , y , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x-1 , y , z,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y , z+1,xSrc , ySrc , zSrc); AlgorythmeVide(world , x , y , z-1,xSrc , ySrc , zSrc); return; } return; } public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); world.scheduleBlockUpdate(x, y, z, algorythme.algo, 15); } public String Ids(World world , int x ,int y ,int z) { TileEntity te = world.getTileEntity(x, y, z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { TileEntityAire tileTuto = (TileEntityAire)te; return ","+tileTuto.getIdsString(); } return ""; } }classe de la tileEntity
package com.mathiasetampes.algorythme.common; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityAire extends TileEntity { public int ids; public String str = ""; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.ids = compound.getInteger("Ids"); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("Ids", this.ids); } public void UpIds(int i) { this.ids=i; return; } public int getIds() { return this.ids; } public String getIdsString() { str=""; str=str+ids; return this.str; } }classe des events
package com.mathiasetampes.algorythme.common; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.PlaceEvent; public class AllEvent { int TabIds[] = new int[50]; @SubscribeEvent public void PlaceEvent(PlaceEvent event) { TileEntity te = event.world.getTileEntity(event.x, event.y, event.z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { for(int i = 0;i<50;i++) { TileEntityAire tileTuto = (TileEntityAire)te; if(TabIds*!=1) { tileTuto.UpIds(i); TabIds* = 1; break; } } } } public void BreakEvent(BlockEvent.BreakEvent event) { TileEntity te = event.world.getTileEntity(event.x, event.y, event.z); // Obtient le tile entité du bloc if(te instanceof TileEntityAire) { TileEntityAire tileTuto = (TileEntityAire)te; TabIds[tileTuto.getIds()] = 0; } } }:::
Désolé de dire çà mais c’est l’un des codes les moins propres que j’ai jamais vu ! (“on recherche la propreté du code”)
De plus je suis pas sûr que on code respecte les consignes : “Non aucune taille limite” or si j’ai bien compris ton code (ce qui n’est pas sûr), ton code est limité par ton array de string (new String[320][256][320]). -
oui la taille est limiter par l’array de mon string mais franchement une maison de 320 sur 320 c’est pas une maison apres on peut augmenter mais tu lagueras et pour la propreté je travaille dessus mais c’est pas ma spécialité la propreté :s
-
@‘Asmath’:
oui la taille est limiter par l’array de mon string mais franchement une maison de 320 sur 320 c’est pas une maison apres on peut augmenter mais tu lagueras et pour la propreté je travaille dessus mais c’est pas ma spécialité la propreté :s
D’après ce que j’ai vu, le plus gros problème étant que tu ne respectes pas la convention java, le second étant que if (boolean == true) est la même chose que if(boolean) et if (boolean == false) est égal à if (!boolean)
-
meric de cette aide precieuse
-
@‘Asmath’:
meric de cette aide precieuse
pour la convention java :
-les variables commencent par une minuscule;
-les fonctions commencent par une minuscule;
-les classe par une majuscule.
mais chez toi, des fois les variables commencent par une minuscule, des fois par une majuscule, même chose pour les méthodes.<<dois-je mettre=“” une=“” majuscule=“” ?<br=“”>-Random.nextBoolean()
-ah ok>></dois-je> -
sinon si tu veux le block pour un mod tu peut aller ici https://www.youtube.com/watch?v=23rTg1eRoYM
-
Dsl de cette réponse tardive, j’ai très peu de temps en ce moment

Comme l’a dit Scarex, il ne doit pas y avoir de limite. Ensuite rien qu’a première vu, ton code a quelques soucis.
Un bloc ne doit pas avoir d’attribut xDepart, vu qu’il n’y a qu’une seule instance de la classe Block chargé en mémoire.Concernant le bloc de départ, il peut se trouver n’importe ou.
Pour le mod settlement, c’était prévu a long long terme d’y incorporer un algo de la sorte. -
d’accord avec un amis qui programme je suis en train de faire un seconde version du mod plus propre et plus efficace pour les limites je suis encore en train de reflechir mais il me faut une confirmtion : droit ou non d’utiliser un fichier texte pour stoker l’information
-
Oui tu as le droit d’utiliser le disque dur, mais le fichier texte, a mon avis ce n’est pas le plus efficace.
-
oui effectivement mon ami vient de me parler des hashtable et c’est bien plus pratique
-
Voilà une V2 vient d’etre terminer la seule chose qui manque , si elle manque , est la sauvegarde des donnés faut-il en faire une ou non ?
-
désolé pour le double post mais bon cette conversation était déja la plus récente donc bon , vidéo de démonstration , pour me dire si c’est ce que tu attendais , https://www.youtube.com/watch?v=cPPDCeZbTGs .