Résolu Crash lors d'un give via la casse d'un bloc
-
Au pire, fais un packet qui give au joueur.
-
Heu si elle devrait fonctionner. C’est elle qui gère le drop et la destruction du bloc, donc …
Pour l’event, est-ce que tu as bien enregistré la classe dans laquelle il se trouve ? -
Par exemple avec cette classe :
package fr.altiscraft.altiscraft.common; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class BlockPomme extends Block { public Random rand = new Random(); public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int l) { world.setBlock(x, y, z, ModAltisCraft.blockPomme, 0, 2); } protected BlockPomme() { super(Material.leaves); } public boolean renderAsNormalBlock() { return false; } public boolean isOpaqueCube() { return false; } public int quantityDropped(Random rdm) { return 0; } public Item getItemDropped(int int1, Random rdm, int int2) { return Item.getItemFromBlock(this); } public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int metadata) { super.harvestBlock(world, player, x, y, z, metadata); player.inventory.addItemStackToInventory(new ItemStack(Items.apple, 1)); } }
Et si je lance le jeu en multi ou en solo, le block respawn mais je ne gagne pas dans mon inventaire la pomme…
Et pour les events j’ai cette classe je copie tout pour si y a une erreur enfin bon mon code est à la fin :
package diabolicatrix.project; import java.util.UUID; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import diabolicatrix.project.proxy.ClientProxy; import fr.altiscraft.altiscraft.common.GuiSpawn; import fr.altiscraft.altiscraft.common.ModAltisCraft; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.server.MinecraftServer; import net.minecraftforge.event.world.BlockEvent.BreakEvent; public class T4EventHandler { private MinecraftServer mcs = MinecraftServer.getServer(); private Item checkArmor = GameRegistry.findItem("flansmod", "Archeo"); // private Minecraft mc = Minecraft.getMinecraft(); private UUID uuid; private String boardTitle; private String scoreString; private boolean shift = false; @SubscribeEvent @SideOnly(Side.CLIENT) public void onKeyInput(KeyInputEvent event) { if (ClientProxy.overMouse.isPressed()) { if (Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityPlayer) { Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard(); String name = Minecraft.getMinecraft().thePlayer.getDisplayName(); ScoreObjective scoreobjective = scoreboard.getObjective("Policier"); if (scoreobjective != null) { Score test = scoreboard.func_96529_a(name, scoreobjective); System.out.println(test.getScorePoints()); if (test.getScorePoints() > 0) { if (Minecraft.getMinecraft().objectMouseOver.entityHit != null && Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityPlayer) { UUID uuid = Minecraft.getMinecraft().objectMouseOver.entityHit.getUniqueID(); Base.instance.network.sendToServer(new PacketOp(uuid)); } // } // } // Minecraft.getMinecraft().displayGuiScreen(new // GuiMouseOver()); } } } } if (ClientProxy.gang.isPressed()) { Minecraft.getMinecraft().displayGuiScreen(new GuiGangMenu()); } if (ClientProxy.restrain.isPressed()) { if (Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityPlayer) { Scoreboard scoreboard2 = Minecraft.getMinecraft().theWorld.getScoreboard(); String name2 = Minecraft.getMinecraft().thePlayer.getDisplayName(); ScoreObjective scoreobjective2 = scoreboard2.getObjective("Policier"); EntityPlayer player = (EntityPlayer) Minecraft.getMinecraft().objectMouseOver.entityHit; EEPRestrained props = EEPRestrained.get(player); if (Minecraft.getMinecraft().thePlayer.worldObj.isRemote) { if (scoreobjective2 != null) { Score test2 = scoreboard2.func_96529_a(name2, scoreobjective2); System.out.println(test2.getScorePoints()); if (test2.getScorePoints() > 0) { UUID uuid = Minecraft.getMinecraft().objectMouseOver.entityHit.getUniqueID(); UUID restrainer = Minecraft.getMinecraft().thePlayer.getUniqueID(); Base.instance.network.sendToServer(new PacketRestrain(uuid, restrainer)); // ChatComponentText component = new // ChatComponentText(EnumChatFormatting.GRAY + // I18n.format("t4.restraining") + // player.getDisplayName()); } } } } } if (ClientProxy.unescort.isPressed()) { Minecraft.getMinecraft().displayGuiScreen(new GuiSpawn()); // if (Minecraft.getMinecraft().thePlayer.riddenByEntity != null) { // EntityPlayer player = (EntityPlayer) // Minecraft.getMinecraft().thePlayer.riddenByEntity; // EntityPlayer lol = Minecraft.getMinecraft().thePlayer; // System.out.println(player.getDisplayName()); // System.out.println(lol.getDisplayName()); // lol.dismountEntity(lol); // Base.instance.network.sendToServer(new PacketUnescort(uuid3, // uuid2)); // System.out.println("packet sent"); // } } /* * if(Minecraft.getMinecraft().gameSettings.keyBindForward.isPressed()){ * EntityPlayer player = Minecraft.getMinecraft().thePlayer; * EEPRestrained props = EEPRestrained.get(player); * if(props.isRestrained()) { event.setCanceled(true); } } * if(Minecraft.getMinecraft().gameSettings.keyBindBack.isPressed()){ * EntityPlayer player = Minecraft.getMinecraft().thePlayer; * EEPRestrained props = EEPRestrained.get(player); * if(props.isRestrained()) { event.setCanceled(true); } } * if(Minecraft.getMinecraft().gameSettings.keyBindLeft.isPressed()){ * EntityPlayer player = Minecraft.getMinecraft().thePlayer; * EEPRestrained props = EEPRestrained.get(player); * if(props.isRestrained()) { event.setCanceled(true); } } * if(Minecraft.getMinecraft().gameSettings.keyBindRight.isPressed()){ * EntityPlayer player = Minecraft.getMinecraft().thePlayer; * EEPRestrained props = EEPRestrained.get(player); * if(props.isRestrained()) { event.setCanceled(true); } } */ } /* * @SubscribeEvent * * @SideOnly(Side.CLIENT) public void onTickEvent(PlayerTickEvent event) { * if (Minecraft.getMinecraft().theWorld != null) { EntityPlayer player = * Minecraft.getMinecraft().thePlayer; EEPRestrained props = * EEPRestrained.get(player); * * if (player != null && props != null) { if (props.isRestrained()) { * //IAttributeInstance attribute = * player.getEntityAttribute(SharedMonsterAttributes.movementSpeed); * //attribute.applyModifier(new AttributeModifier("Slow", -100D, * 50).setSaved(false)); player.motionX = 0.0D; player.motionY = 0.0D; * player.motionZ = 0.0D; player.setJumping(false); } } } * * } */ /* * @SubscribeEvent * * @SideOnly(Side.CLIENT) public void onTickEvent(PlayerTickEvent event) { * if(event.player.inventory.armorInventory[3] != null){ * if(event.player.inventory.armorInventory[3].getItem() == checkArmor) { * event.player.addPotionEffect(new * PotionEffect(Potion.waterBreathing.getId(), 0, 3)); } } } */ @SubscribeEvent @SideOnly(Side.CLIENT) public void onPlayerTickEvent(PlayerTickEvent event) { /* * if(GuiSpawn.getSelected() == "dassadsasdasadasd" && * Minecraft.getMinecraft().currentScreen == null) { * Minecraft.getMinecraft().displayGuiScreen(new GuiSpawnMenu()); } */ // System.out.println("Test 1"); if (event.player.inventory.armorInventory[3] != null) { // System.out.println("Test 2"); // Minecraft.getMinecraft().displayGuiScreen(new GuiSpawnMenu()); } } @SubscribeEvent public void onBlockDestroyed(BreakEvent event) { if (event.block == ModAltisCraft.blockPomme) { event.getPlayer().inventory.addItemStackToInventory(new ItemStack(Items.apple, 1)); } } }
Et ça fonctionne puisque les fonctions dedans marchent et dans la classe principale j’ai dans le init:
FMLCommonHandler.instance().bus().register(new T4EventHandler()); MinecraftForge.EVENT_BUS.register(new ForgeT4EventHandler());
-
En se référant à cette liste : http://www.minecraftforgefrance.fr/forge-events.php , il semblerait que l’event soit un event Forge et non FML, mais tu le met dans la classe qui gèrent les events FML.
L’event devrait se trouver dans ForgeT4EventHandler -
Ca a marché merci impec’ j’étais sûr que ça venait de la merci beaucoup !!!