• Recently Browsing

    No registered users viewing this page.

  • Posts

    • Right then. I've tried some thing out over the last few days and come to the following verdict:   Unit-testing Minecraft and Forge classes is really hard. Let me give you an example:   For context, I'm using JUnit 5 with Mockito 3.8.  I have a custom implementation of a fluid tank. I first tried writing a simple unit-test to check that "when there is no fluid in the tank and I try to drain some, drain zero units". I used to extend FluidTank, but in trying to write a simple test, I niow implement IFluidHandler and IFluidTank directly. The reason for this is that creating my object to test, it constructs a FluidTank, which contains this field: @Nonnull protected FluidStack fluid = FluidStack.EMPTY; When FluidStack.EMPTY (a static field) is called on, the JVM tries to also load FluidStack's other static field, FluidStack.CODEC. This in turn causes a cascade of other static initialisations which  culminates in crashing the JVM with a NullPointerException sometime around it trying to either load a World or access a Registry. So not good. I tried to @InjectMocks on that field, but the injection occurs after the object is instantiated, so the JVM has already crashed.   In order to get around this, you have to implement the aforementioned interfaces directly because: 1) They are the required interfaces so they have to be there anyway; 2) They contain no static fields, so they won't start a cascade.   The upshot? Forge and Minecraft are not designed to be tested in this way (not surprising), and have interlinking fields with will cause crashes. What can we do? Well, you can test anything that you write. You can't test a FluidTank, but you can test an IFluidTank. Try to not have unnecessary static fields, and use constructor injection when possible. (This would fix the problem above: see my code below)   // How to fix that crash // In FluidTank.java: // Don't initialise the field now! protected FluidStack fluid; // Add a new constructor to allow modders to specify a starting stack. public FluidTank(int capacity, Predicate<FluidStack> validator, FluidStack initialFluid) // Using constructor injection here means that a tester *can* inject a mock object for the initialFluid. This means that no initialisation cascade occurs! { this.capacity = capacity; this.validator = validator; // Probably a good idea to test the stack for safety. if (!validator.test(initialFluid)) throw new IllegalStateException("Whatever kind of error you want"); this.fluid = initialFluid; } // Changing the current constructor to just use the overloaded one. public FluidTank(int capacity, Predicate<FluidStack> validator) { // This time it's safer to default to EMPTY this(capacity, validator, FluidStack.EMPTY); }   I realise that this all sounds very... ahhh... something? (can't think of the word) I'm certainly not the expert on this and I'm not a professional tester so I've probably made some errors or assumptions here. I would put this in as a pull request on the Forge Github if I could actually clone it (never works for some reason...)   Best, GenElectrovise
    • Hi under this link and the known issues 1.14-1.16 you can find the Worldgenerator freeze tab. I have this issue since I have played on 1.16.4-5 and I don't know how to fix it. The problem is that it just hocks up my game without a crash, I don't have a crash report because I don't get one. The attached file are my mods listed in a Textdocument. Please let me know if there is an issue. I would attach my latest logs and debug logs but I can't because see attached image.   Chunk-Pregenerator - Mods - Minecraft - CurseForge  Known issues and Potential Fixes 1.14-1.16: My mods.txt
    • I tried this with no luck: RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.HEARTBALL_PROJECTILE.get(), HeartballRenderer::new);  
    • Hello, My friends and I just bought a Minecraft hosting to use with forge. And we're encountering problem where the server starts fine, we can connect, but it just keeps spitting out warnings about incorrect config files and it's really annoying and I think it eats up some resources... When we tried forge by itself without any mods there wasn't any issue. When I try to run the server with the exact same files on my pc it works fine. So is there way to just stop the server from trying to correct the config files (or whatever it is that it is doing) or something? Thank you in advance.   Here is the link to the latest log file: https://www.dropbox.com/s/1ni8tko383q4mlg/2021-03-07-10.log?dl=0
    • thanks for the info, since the whole thing sounds pretty complicated, I will probably not change it
  • Topics

  • Who's Online (See full list)