Résolu Cycle jour/nuit
-
Bonjour,
Je voulais savoir si il existait un moyen plus simple que de recréer un WorldProvider afin de modifier la durée d’un jour ou d’une nuit. De plus est-il possible de faire en sorte que cette durée change au cours du temps : je voudrais faire un cycle de saison été/hiver où la durée d’une journée serait un sinus de 5 d’amplitude (+ un base de 10) pour alterner la durée entre 15m en été et 5m en hiver avec la nuit qui comble le reste de temps jusqu’à 20m. Merci de votre aide !
-
Salut, ce que tu recherches est la méthode WorldProvider#calculateCelestialAngle, que tu pourras surcharger dans ta propre classe WorldProvider. Elle, comme l’indique partiellement les commentaires, désigne l’angle de l’astre visible, en radian.
-
Bien merci, j’ai recontacté une personne sur le serveur anglais qui avait utilisé cette fonction surchargée dans la classe WorldProviderSurface pour faire un système de variation de la durée des jours et nuits lors de différentes saisons. Si quelqu’un trouve ce sujet plus tard, qu’il me contacte. Merci
-
Bonjour, je reviens sur ce sujet car j’ai presque fini. J’aimerais savoir quel “tick event” utiliser, je m’explique : je ne sais pas trop quelle est la différence entre WorldTickEvent et ServerTickEvent pour actualiser mes saisons, par exemple si je veux que ça actualise que quand un joueur joue ? En gros je voudrais éviter que si le serveur tourne h24 les saisons défilent même sans les joueurs. Merci
-
Dans les deux cas ça va tourner sans joueur.
WorldTickEvent est appelé pour chaque monde (donc une fois par dimension) et ServerTickEvent une seule fois pour tout le serveur.Si tu veux faire l’action seulement quand un joueur est là, il suffit de faire une condition vérifiant que le nombre de joueur est supérieur à 0 (tu peux l’obtenir depuis la classe MinecraftServer).
-
D’accord, merci bien
-
Cette ligne est-elle correcte si je veux que les saisons ne passent que quand il y a un joueur dans le monde normal ?
if(Minecraft.getMinecraft().getIntegratedServer().worlds[0].playerEntities.size() > 0)
-
Minecraft.getMinecraft().getIntegratedServer() ne fonctionne que en solo.
Utilises plutôt FMLServerHandler.instance().getServer().getPlayerList().getPlayers().size()
-
Ok merci beaucoup
-
Bonjour, quand je lance le jeu (sur eclipse) et que je me connecte sur un des mondes, cela reste bloqué en affichant 0%. De plus si j’enleve le @EventBusSubcriber dans SeasonEvent le jeu se lance mais des que j’appuie sur echap il crash avec ce crash-report :
–-- Minecraft Crash Report ---- // Oh - I know what I did wrong! Time: 4/12/18 2:27 PM Description: Saving entity NBT java.lang.NullPointerException: Saving entity NBT at net.minecraftforge.fml.server.FMLServerHandler.getDataFixer(FMLServerHandler.java:355) at net.minecraftforge.fml.common.FMLCommonHandler.getDataFixer(FMLCommonHandler.java:764) at net.minecraft.entity.player.EntityPlayer.writeEntityToNBT(EntityPlayer.java:1032) at net.minecraft.entity.player.EntityPlayerMP.writeEntityToNBT(EntityPlayerMP.java:275) at net.minecraft.entity.Entity.writeToNBT(Entity.java:1956) at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:30) at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:986) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:176) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace: at net.minecraftforge.fml.server.FMLServerHandler.getDataFixer(FMLServerHandler.java:355) at net.minecraftforge.fml.common.FMLCommonHandler.getDataFixer(FMLCommonHandler.java:764) at net.minecraft.entity.player.EntityPlayer.writeEntityToNBT(EntityPlayer.java:1032) at net.minecraft.entity.player.EntityPlayerMP.writeEntityToNBT(EntityPlayerMP.java:275) -- Entity being saved -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 2626 Entity Name: Player684 Entity's Exact location: -127.55, 66.53, -251.49 Entity's Block location: World: (-128,66,-252), Chunk: (at 0,4,4 in -8,-16; contains blocks -128,0,-256 to -113,255,-241), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) Entity's Momentum: 0.00, 0.00, 0.00 Entity's Passengers: [] Entity's Vehicle: ~~ERROR~~ NullPointerException: null Stacktrace: at net.minecraft.entity.Entity.writeToNBT(Entity.java:1956) at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:30) at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:986) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:176) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) at java.lang.Thread.run(Unknown Source) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_161, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 532384320 bytes (507 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95 FML: MCP 9.42 Powered by Forge 14.23.2.2629 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:--------- |:--------- |:------------ |:-------------------------------- |:--------- | | UCHIJAAAA | minecraft | 1.12.2 | minecraft.jar | None | | UCHIJAAAA | mcp | 9.42 | minecraft.jar | None | | UCHIJAAAA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.2.2629.jar | None | | UCHIJAAAA | forge | 14.23.2.2629 | forgeSrc-1.12.2-14.23.2.2629.jar | None | | UCHIJAAAA | hm | 1.1 | bin | None | Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 1 / 8; [EntityPlayerMP['Player684'/2626, l='New World', x=-127.55, y=66.53, z=-251.49]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
Voici SeasonEvent :
package com.laurentoutang.hardmod.Seasons; import java.util.Collection; import com.laurentoutang.hardmod.Init.ModItems; import com.laurentoutang.hardmod.capabilities.IMentalTemperature; import com.laurentoutang.hardmod.capabilities.MentalTemperatureProvider; import net.minecraft.block.BlockBeetroot; import net.minecraft.block.BlockCarrot; import net.minecraft.block.BlockCocoa; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockMelon; import net.minecraft.block.BlockPotato; import net.minecraft.block.BlockPumpkin; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Biomes; import net.minecraft.server.MinecraftServer; import net.minecraft.world.biome.Biome; import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.server.FMLServerHandler; @EventBusSubscriber public class SeasonEvent { private static boolean transition = true; @SubscribeEvent public static void onWakeUp(PlayerWakeUpEvent event) { SeasonWorldProvider.season_manager.isDay = true; } @SubscribeEvent public static void onPlayerCommandTimeSet(CommandEvent event) { if(event.getCommand().getName() == "time" && "set".equals(event.getParameters()[0])) { event.setCanceled(true); } } @SubscribeEvent public static void onBlockDestroyed(BlockEvent.BreakEvent event) { if(SeasonWorldProvider.season_manager.getSeason() == SeasonManager.seasons.Winter && ( event.getState().getBlock() instanceof BlockBeetroot || event.getState().getBlock() instanceof BlockCarrot || event.getState().getBlock() instanceof BlockPotato || event.getState().getBlock() instanceof BlockCrops || event.getState().getBlock() instanceof BlockCocoa || event.getState().getBlock() instanceof BlockMelon || event.getState().getBlock() instanceof BlockPumpkin )) { event.setCanceled(true); } } @SubscribeEvent public static void onPlayerTick(PlayerTickEvent event) { EntityPlayer player = event.player; if (player.world.isRemote) return; else registerArmorTemperature(player); } @SubscribeEvent public static void onWorldTick(WorldTickEvent event) { MinecraftServer serverMulti = FMLServerHandler.instance().getServer(); MinecraftServer serverSolo = Minecraft.getMinecraft().getIntegratedServer(); if(serverMulti != null) { if(serverMulti.getOnlinePlayerNames().length > 0) { if(SeasonWorldProvider.season_manager.getSeason() == SeasonManager.seasons.Winter) loadWinterProperties(event); else loadSummerProperties(event); } } else { if(serverSolo != null) { if(serverSolo.getOnlinePlayerNames().length > 0) { if(SeasonWorldProvider.season_manager.getSeason() == SeasonManager.seasons.Winter) loadWinterProperties(event); else loadSummerProperties(event); } } } } private static void registerArmorTemperature(EntityPlayer player) { IMentalTemperature mt = player.getCapability(MentalTemperatureProvider.MentalTemperature_CAP, null); if(player.inventory.armorItemInSlot(0).getItem().equals(ModItems.WOOLEN_BOOTS)) { if(mt.getBootsTemperature() == 0) { mt.setBootsTemperature(10.f); } } else { mt.setBootsTemperature(0.f); } if(player.inventory.armorItemInSlot(1).getItem().equals(ModItems.WOOLEN_LEGGINS)) { if(mt.getLegginsTemperature() == 0) { mt.setLegginsTemperature(10.f); } } else { mt.setLegginsTemperature(0.f); } if(player.inventory.armorItemInSlot(2).getItem().equals(ModItems.WOOLEN_CHESTPLATE)) { if(mt.getChestplateTemperature() == 0) { mt.setChestplateTemperature(10.f); } } else { mt.setChestplateTemperature(0.f); } if(player.inventory.armorItemInSlot(3).getItem().equals(ModItems.WOOLEN_HELMET)) { if(mt.getHelmetTemperature() == 0) { mt.setHelmetTemperature(10.f); } } else { mt.setHelmetTemperature(0.f); } } private static void loadWinterProperties(WorldTickEvent event) { Collection <biome>allBiomes = ForgeRegistries.BIOMES.getValuesCollection(); for(Biome b : allBiomes) { if(b != Biomes.HELL && b != Biomes.SKY && b != Biomes.VOID) { ObfuscationReflectionHelper.setPrivateValue(Biome.class, b, true, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, b, 0.0F, "temperature"); } } if(transition) { event.world.getWorldInfo().setRainTime(288000); transition = false; } } private static void loadSummerProperties(WorldTickEvent event) { if( transition == false) transition = true; Collection <biome>allBiomes = ForgeRegistries.BIOMES.getValuesCollection(); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.OCEAN, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.OCEAN, 0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BEACH, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BEACH, 0.8F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BIRCH_FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BIRCH_FOREST, 0.6F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BIRCH_FOREST_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.BIRCH_FOREST_HILLS, 0.6F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.COLD_BEACH, 0.05F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.COLD_TAIGA, -0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.COLD_TAIGA_HILLS, -0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DEEP_OCEAN, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DEEP_OCEAN, 0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DESERT, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DESERT, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DESERT_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.DESERT_HILLS, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS, 0.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS_EDGE, false, "enaleSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS_EDGE, 0.2F, "temerature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS_WITH_TREES, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.EXTREME_HILLS_WITH_TREES, 0.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FOREST, 0.7F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FOREST_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FOREST_HILLS, 0.7F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FROZEN_OCEAN, 0.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.FROZEN_RIVER, 0.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.ICE_MOUNTAINS, 0.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.ICE_PLAINS, 0.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE, 0.95F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE_EDGE, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE_EDGE, 0.95F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.JUNGLE_HILLS, 0.95F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA_CLEAR_ROCK, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA_CLEAR_ROCK, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA_ROCK, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MESA_ROCK, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUSHROOM_ISLAND, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUSHROOM_ISLAND, 0.9F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUSHROOM_ISLAND_SHORE, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUSHROOM_ISLAND_SHORE, 0.9F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_BIRCH_FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_BIRCH_FOREST, 0.6F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_BIRCH_FOREST_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_BIRCH_FOREST_HILLS, 0.6F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_DESERT, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_DESERT, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_EXTREME_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_EXTREME_HILLS, 0.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES, 0.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_FOREST, 0.6F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_ICE_FLATS, 0.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_JUNGLE, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_JUNGLE, 0.95F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_JUNGLE_EDGE, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_JUNGLE_EDGE, 0.95F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA_CLEAR_ROCK, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA_CLEAR_ROCK, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA_ROCK, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_MESA_ROCK, 2.0F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_PLAINS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_PLAINS, 0.8F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_REDWOOD_TAIGA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_REDWOOD_TAIGA, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_REDWOOD_TAIGA_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_REDWOOD_TAIGA_HILLS, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_ROOFED_FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_ROOFED_FOREST, 0.7F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SAVANNA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SAVANNA, 1.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SAVANNA_ROCK, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SAVANNA_ROCK, 1.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SWAMPLAND, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_SWAMPLAND, 0.8F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_TAIGA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_TAIGA, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.MUTATED_TAIGA_COLD, -0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.PLAINS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.PLAINS, 0.8F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.REDWOOD_TAIGA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.REDWOOD_TAIGA, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.REDWOOD_TAIGA_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.REDWOOD_TAIGA_HILLS, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.RIVER, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.RIVER, 0.5F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.ROOFED_FOREST, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.ROOFED_FOREST, 0.7F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SAVANNA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SAVANNA, 1.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SAVANNA_PLATEAU, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SAVANNA_PLATEAU, 1.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.STONE_BEACH, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.STONE_BEACH, 0.2F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SWAMPLAND, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.SWAMPLAND, 0.8F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.TAIGA, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.TAIGA, 0.25F, "temperature"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.TAIGA_HILLS, false, "enableSnow"); ObfuscationReflectionHelper.setPrivateValue(Biome.class, Biomes.TAIGA_HILLS, 0.25F, "temperature"); } }
et le hud :
package com.laurentoutang.hardmod.HUD; import java.awt.Color; import java.util.Iterator; import java.util.List; import com.laurentoutang.hardmod.util.Reference; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.server.management.PlayerList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.biome.Biome; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.common.BiomeManager.BiomeType; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.server.FMLServerHandler; @EventBusSubscriber(modid = Reference.MOD_ID, value = {Side.CLIENT}) public class SidePannel { public static final Minecraft MC = Minecraft.getMinecraft(); public static final EntityPlayer entity_player = MC.player; @SubscribeEvent public static void renderGameOverlayPre(RenderGameOverlayEvent.Pre event) { } @SubscribeEvent public static void renderGameOverlayPost(RenderGameOverlayEvent.Post event) { if(event.getType().equals(ElementType.ALL)) { //faire une version solo et une version multi ScaledResolution res = event.getResolution(); int width = event.getResolution().getScaledWidth(); int height = event.getResolution().getScaledHeight(); MinecraftServer serverMulti = FMLServerHandler.instance().getServer(); if(serverMulti != null) { System.out.println("multi"); //Number of player String s = serverMulti.getOnlinePlayerNames().length + "/" + serverMulti.getMaxPlayers() + " joueurs"; Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(s), 2, width - 2, 4 + MC.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE); MC.fontRenderer.drawString(s, width - 3 - MC.fontRenderer.getStringWidth(s), 4, Color.WHITE.getRGB()); //Life of players PlayerList players = serverMulti.getPlayerList(); if(players != null) { for(int i = 0 ; i < players.getCurrentPlayerCount() ; i++) { String life = players.getPlayers().get(i).getDisplayNameString() + " : " + players.getPlayers().get(i).getHealth() + " / 20"; Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(life), 64+i*(2 + MC.fontRenderer.FONT_HEIGHT), width - 2, 64+(i+1)*(2 + MC.fontRenderer.FONT_HEIGHT), Integer.MIN_VALUE); MC.fontRenderer.drawString(life, width - 3 - MC.fontRenderer.getStringWidth(life), 66+i*(2 + MC.fontRenderer.FONT_HEIGHT), Color.YELLOW.getRGB()); } } } else { MinecraftServer serverSolo = Minecraft.getMinecraft().getIntegratedServer(); if(serverSolo != null) { //Number of player System.out.println("solo"); String s = serverSolo.getOnlinePlayerNames().length + "/" + serverSolo.getMaxPlayers() + " joueurs"; Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(s), 2, width - 2, 4 + MC.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE); MC.fontRenderer.drawString(s, width - 3 - MC.fontRenderer.getStringWidth(s), 4, Color.WHITE.getRGB()); //Life of players PlayerList players = serverSolo.getPlayerList(); if(players != null) { for(int i = 0 ; i < players.getCurrentPlayerCount() ; i++) { String life = players.getPlayers().get(i).getDisplayNameString() + " : " + players.getPlayers().get(i).getHealth() + " / 20"; Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(life), 64+i*(2 + MC.fontRenderer.FONT_HEIGHT), width - 2, 64+(i+1)*(2 + MC.fontRenderer.FONT_HEIGHT), Integer.MIN_VALUE); MC.fontRenderer.drawString(life, width - 3 - MC.fontRenderer.getStringWidth(life), 66+i*(2 + MC.fontRenderer.FONT_HEIGHT), Color.YELLOW.getRGB()); } } } } } } }
Ce sont les deux seules classes où j’utilise les serveurs, de plus je ne savais pas si il fallait gérer en deux temps : un serveur solo et un serveur multi pour que le mode soit compatible en solo et en multi. Merci</biome></biome>
-
Bon, tu vas avoir un crash avec cette ligne MinecraftServer serverMulti = FMLServerHandler.instance().getServer(); dans la classe SidePanel. Si tu enregistres un event côté client et que tu appelles une classe Serveur, tu vas crash.
-
D’accord, mais du coup je suppose qu’il n’existe pas de méthode qui permette d’avoir les joueurs connectés côté client. Du coup je suis obligé de faire avec des packets ?
-
Il existe déjà un packet du genre pour compléter le menu tab.
-
J’ai ca mais rien pour les hp
NetworkPlayerInfo element = it.next(); String life = MC.ingameGUI.getTabList().getPlayerName(element) + " : " + " / 20";
Ceci à l’air de marcher
PlayerList players = FMLClientHandler.instance().getServer().getPlayerList(); GameProfile[] playerProfiles = players.getOnlinePlayerProfiles(); if(playerProfiles != null) { int i = 0; for(GameProfile playerProfile : playerProfiles) { String life = playerProfile.getName() + " : " + players.getPlayerByUsername(playerProfile.getName()).getHealth() + " / 20"; Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(life), 64+i*(2 + MC.fontRenderer.FONT_HEIGHT), width - 2, 64+(i+1)*(2 + MC.fontRenderer.FONT_HEIGHT), Integer.MIN_VALUE); MC.fontRenderer.drawString(life, width - 3 - MC.fontRenderer.getStringWidth(life), 66+i*(2 + MC.fontRenderer.FONT_HEIGHT), Color.YELLOW.getRGB()); i++; } }