Jump to content

Bektor

Forge Modder
  • Posts

    852
  • Joined

  • Last visited

Everything posted by Bektor

  1. Ok and what do I have to do when I reload the world or restart the client? Just to note, I got this code for registering the capability, so NBT stuff is already there: CapabilityManager.INSTANCE.register(IStarpower.class, new Capability.IStorage<IStarpower>() { @Override public NBTBase writeNBT(Capability<IStarpower> capability, IStarpower instance, EnumFacing side) { return new NBTTagInt(instance.getStarpower()); } @Override public void readNBT(Capability<IStarpower> capability, IStarpower instance, EnumFacing side, NBTBase nbt) { instance.set(((NBTPrimitive) nbt).getInt()); } }, Starpower::new);
  2. Hi, I've got a player capability and I am wondering now how I can save the data so that when the player dies the capability still exists for the player, but also when the world is reloaded or the client restarts. Thx in advance. Bektor
  3. Ok, thx, but from where do I get width and height of the screen?
  4. Hi, I've got a little question: How can I render something like a progress bar or a text or what ever centered on the screen? Note: For rendering I'm using the RenderGameOverlayEvent.Post event. It would also be quite nice to know how to render stuff with this event centered on the block the player is looking at. Thx in advance. Bektor
  5. Anyone who knows how to center the text or other stuff on the screen or block?
  6. Ah, ok. So how am I able to create categories inside of these configs? Also, do I need to create a new class for a new config?
  7. Ah, ok. Thx. Hm.. I'm a bit stuck on rendering actually everything on the middle of the block (not y axis, thought)
  8. Hi, I'm wondering how I can create a folder for different config files and how to let each different config file have different categories. As a side note: I'm using the annotation based config system and I've got also an ingame-config which gets generated automatically: @Config(modid = Constants.MOD_ID) public class ModConfig { @Config.LangKey("config.test.general.energyname") @Config.Comment("The name of the Energy to be displayed.") public static String ENERGY_NAME = "FU"; @Config.LangKey("config.test.general.teslaname") @Config.Comment("The name of Tesla Energy to be displayed.") public static String TESLA_ENERGY_NAME = "T"; @Mod.EventBusSubscriber private static class ConfigHandler { /** * Inject the new values and save to the config file when the * config has been changed from the GUI. * * @param event the event */ @SubscribeEvent public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { if(event.getModID().equals(Constants.MOD_ID)) ConfigManager.load(Constants.MOD_ID, Config.Type.INSTANCE); } } } Thx in advance. Bektor
  9. If I am correct and the problem is caused by it that data was sent to the client for which the chunk events haven't run yet, how can I prevent this from occuring? EDIT: fixed. Just implemented an extra null check for IChunkPollution. I hope nothing else get's messed up because of this. Seems also that other code parts didn't had an npe because of instanceof checks which also check for null.
  10. Ah, ok thx. Also, I didn't meant that TESRs create a significant amount of "lag". I just meant that it most likely needs more resources on your system than what is really required to draw some simple overlay UI. Some more information about RenderGameOverlayEvent and it's sub-classes and how to use them properly would be nice. Like for what is this ElementType.ALL and event.getType() and what does the profiler do? [Note: I've got no clue about those events at all and little about how Minecraft handles the rendering internal]
  11. Hi, I'm wondering how I can render a progress bar for all my tile entities which store or generate energy which shows how much energy they have stored. My problem is now that I don't know how to only render this progress bar when the player looks directly at this block (so the bounding boxes are shown). I also do not know how I can render this in the most efficient way, as nearly all my tile entities should render such a progress bar. It is also to note that I don't have a tile entity yet which requires anything other than a simple json file or json model to be rendered. My ideas are currently using a TileEntitySpecialRenderer for this purpose (thought I don't like the idea as it might cost a lot more performance than really necessary) or go with the RenderGameOverlayEvent, thought I have no clue how this even works. I've only heard that Botania is using it Thx in advance. Bektor
  12. It should have been called. I registered the entire class as a event handler using MinecraftForge.EVENT_BUS.register(new CapabilityPollution()); in FMLInitializationEvent within the ServerProxy. And all events have the @SubscribeEvent annotation on them, so they should be recognized and called. Just change a bit of the code to get more information out of it: As I am no longer using System.err.println but instead System.out.println the order of the output matches now also the order of the code. final IChunkPollution chunkPollution = chunkPollutionHolder.getChunkPollution(new ChunkPos(message.chunkPosX, message.chunkPosZ)); System.out.println("chunkPollution: " + chunkPollution); System.out.println("Position: " + message.chunkPosX + " | " + message.chunkPosZ); System.out.println("Player Position: " + ((int)(Minecraft.getMinecraft().player.posX) >> 4) + " | " + ((int)(Minecraft.getMinecraft().player.posZ) >> 4)); chunkPollution.setPollution(message.pollution); So it seems like the error occurs inside of a chunk in which the player currently is not. Also this is the data from the map from my chunkPollutionHolder. As of the chunk which is causing the problem isn't in the list I guess it wasn't called at the point where the client player added it to it's watch list.
  13. Oh, ok. Thx. Console output: Code: final IChunkPollution chunkPollution = chunkPollutionHolder.getChunkPollution(new ChunkPos(message.chunkPosX, message.chunkPosZ)); System.err.println("t: " + chunkPollution + " tt: " + chunkPollution == null); System.err.println(message); chunkPollution.setPollution(message.pollution); Debug Window:
  14. Ok. Thougt now eclipse tells me always this: Source not found. Edit Source Lookup Path. There it just gives me the option to select default and then it works. I click on resume and the same thing happens again. EDIT: Ok, after literally pressing the Resume button like a 100 times I got to the point where my code starts... There it stopped on this line: chunkPollution.setPollution(message.pollution); The debug window shows me that chunkPollution is null while the console window showed me false just a few ms before for this statement: chunkPollution == null. Console output: .Code: final IChunkPollution chunkPollution = chunkPollutionHolder.getChunkPollution(new ChunkPos(message.chunkPosX, message.chunkPosZ)); System.err.println("t: " + chunkPollution + " tt: " + chunkPollution == null); System.err.println(message); chunkPollution.setPollution(message.pollution); Debug Window:
  15. Hm, seems like eclipse has something like that, too. Thought I can't set the line of an exception breakpoint nor the class and for normal conditional breakpoints I have to write normal null checks like I would inside of the code, just inside of the breakpoint.
  16. How can I create an exception breakpoint fpr NullPointerExceptions in eclipse? Also the NPE still happens. I just removed the breakpoint, pressed resume and got it directly while I could click on resume before like a thousand times without anything happening. I'm also not entirely sure under which situations it occurs, I just now it happens always when the world loads.
  17. Hm... It doesn't really bring me anywhere.. Setting the breakpoint at line 80 will just result into it that eclipse shows me that neither the world, nor the chunkPollutionHolder or the chunkPollution values are null. Putting in this line of code results into this: System.err.println(message.pollution); //output :0.0 System.err.println(message); // output: MessageChunkPollution@3fbdd7c8 Opening the chunkPollutionHolder shows me that the keySet and the values from the HashMap are null while the entrySet contains values.
  18. Yes. @SubscribeEvent public void chunkLoad(ChunkEvent.Load event) { final World world = event.getWorld(); final ChunkPos pos = event.getChunk().getChunkCoordIntPair(); if(world == null || !world.hasCapability(CHUNK_POLLUTION_CAPABILITY, DEFAULT_FACING)) return; final IChunkPollutionHolder chunkPollutionHolder = world.getCapability(CHUNK_POLLUTION_CAPABILITY, DEFAULT_FACING); if(chunkPollutionHolder == null) return; // don't create a IChunkPollution twice for a chunk if(chunkPollutionHolder.getChunkPollution(pos) != null) return; final IChunkPollution chunkPollution = new ChunkPollution(world, pos); chunkPollutionHolder.setChunkPollution(pos, chunkPollution); }
  19. Ok, thx. I've got just a little problem: I'm sending a message to the player via ChunkWatchEvent.Watch to test if the code, but now I'm getting the following error inside of the message handler: [22:59:21] [Client thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:29) [Util.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1108) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:406) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.lang.NullPointerException at minecraftplaye.justanotherenergy.common.network.msg.MessageChunkPollution$MessageChunkPollutionHandler.lambda$0(MessageChunkPollution.java:80) ~[MessageChunkPollution$MessageChunkPollutionHandler.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:28) ~[Util.class:?] ... 15 more Here is the code: public static class MessageChunkPollutionHandler implements IMessageHandler<MessageChunkPollution, IMessage> { @Override public IMessage onMessage(MessageChunkPollution message, MessageContext ctx) { IThreadListener mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(() -> { final World world = Minecraft.getMinecraft().world; final IChunkPollutionHolder chunkPollutionHolder = CapabilityPollution.getChunkPollutionHolder(world); if(chunkPollutionHolder == null) return; final IChunkPollution chunkPollution = chunkPollutionHolder.getChunkPollution(new ChunkPos(message.chunkPosX, message.chunkPosZ)); System.err.println("t: " + chunkPollution + " tt: " + chunkPollution == null); // output: false chunkPollution.setPollution(message.pollution); // Error occurs here }); // No respond packet return null; } }
  20. Ok, I got the capability system now implemented. Does the ChunkWatchEvent.Watch gets only called once, for example the player goes into this chunk and the event gets called and then never again until the player goes into this chunk again? So it does not get called like every 20 ticks when a player is in this chunk. I'm also wondering how I should access my capability from a block to let this block update the value stored in the chunk, as I've only worked with capabilities where the data is directly saved to the block and thus every block had it own instance of in that case the EnergyStorage class. And how do I access the value stored in the chunk in events like CropGrowEvent or SaplingGrowTreeEvent to do something within those events when the value reaches a critical point. Should I just do something like this: final IChunkEnergy chunkEnergy = getChunkEnergy(player.getEntityWorld(), event.getChunk());
  21. Oh, yeah. So basically you are directly sending the new data to the client while with the forge implementation each block/item has to ask for the current value when it wants to display it, correct?
  22. Ok, thx. Just one question, why do you send a packet to the client instead of changing the value directly in your ChunkEnergy class? I mean, you basically build your system on top of the existing one from forge and the one from forge changes the energy direclty without sending an packet which does this.
  23. Hi, I'm wondering how I can measure the performance of a Server outside of the IDE. The reason for this is because a few friends of mine got a Server on which we play, but since a few days we have somewhere a performance issue and probably a memory leak. The problem, no one knows if the problem is caused by our own mods or other mods nor do we know what actually causes the performance problems. So are there any tools or mods which can help finding out the problem? Thx in advance. Bektor
  24. Well, that way the stuff is changes always, it doesn't matter where I change it and I don't have to create a new instance of the map etc. everytime the event is called. Also all blocks don't need to create or access some instance of it to be able to get values. Ok, I created now a new world to get rid of all old NBT data which might have been saved and the result with the debugger is that the first block placed in the chunk will always have the value 0, which should be quite easy to fix. But it seems like the problem that it was always 0 came from a lot of testing with saving the stuff to NBT etc. What do you mean by it that mods need to specify the world anyways? Also in your last answer you suggested using world capability or WorldSavedData. So what's exactly the difference between these two and which one would be a better choice to give also other mods access to the polution data saved per chunk so that these mods may add their own blocks and items using the values from them? I also guess that those world capability stuff is just this thing here: AttachCapabilityEvent<World> Why would this leak memory? That way it would just be saved like it is currenlty, except for that it is not only chunkPos.toString() anymore but instead world.provider.getDimension() + chunkPos.toString()
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.