Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

1979 profile views

GenElectrovise's Achievements

Creeper Killer

Creeper Killer (4/8)



  1. There'd also be a small startup time tradeoff but I don't know how much of a difference that would make. Interesting idea with running tests later on... I hadn't thought of that... Might try that out just to satisfy curiosity!
  2. 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
  3. All of it. If you don't have a repo, please make one. Everything will be easier.
  4. Hi all, I've been wondering recently about how one would go about testing mods (I mean testing in a unit-testing sense here). Took a look around the MinecraftForge GitHub repo and found the expected src/test/java folder, but most of the tests in here seem to be standalone mods (activated individually with booleans) designed to test a specific behavior. Some, however, such as the LazyOptionalTest use JUnit. I suppose this is because game behaviours are really hard to mock-up for testing? What's Forge's testing ethos?
  5. There's probably something in or nearby to PlayerEntity (as a movement controller or something similar?) I'd start with searching my workspace for something along the lines of KeystrokeHandler or PlayerMovementController
  6. Never heard of an error like this but what's your version.
  7. Uhhh ok then. This is very strange. It now works for me too. I... uhh... ok then Thanks!? It seems to only store one package at a time? Maybe it only shows the most recent - who knows! I'll look around for this... build.gradle publishing { repositories { maven { name = "GitHubPackages" url = uri("https://maven.pkg.github.com/genelectrovise/magiksmostevile") // MUST BE --ALL-- LOWER CASE credentials { username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") } } maven { name = "LocalMaven" url = uri("file:///${project.projectDir}/mcmodsrepo") } } publications { gpr(MavenPublication) { groupId = group artifactId = archivesBaseName version = version artifact jar } } } gpr.user and gpr.key are secrets contained in my User/.gradle/gradle.properties. They are defined like so: gpr.user=INSERT_USERNAME_HERE gpr.key=INSERT_SECRET_PERSONAL_ACCESS_TOKEN_HERE
  8. @DaemonUmbra Yes... I would prefer 'maven-publish'... I kept getting the error "Could not write to resource", and Stackoverflow was incredibly unhelpful on the subject... 'maven' is kind of a stand-in right now... Could you send your working publication/build.gradle? The issue is probably with me authenticating but syntax is always an option. Note: Where are you storing credentials? Naturally they shouldn't be in the project sources, so I'm keeping them in my master User/.gradle/gradle.properties. They seem to be being located there. Are you using a Personal Access Token or standard login credentials? I believe that a PAT is preferred by Github? EDIT: A PAT is required https://docs.github.com/en/packages/guides/configuring-gradle-for-use-with-github-packages
  9. 1.12.2 is no longer supported on this forum. Please upgrade to a modern version to receive support.
  10. Thanks @DaemonUmbra - while this thread has been silent I've been wrangling with Gradle... I had a lot of trouble (authenticating?) with the maven publishing, so in the end, I have activated the maven (as opposed to maven-publish) plugin, and have set it up like so, which works well. It requires that I run that uploadArchives command, rather than publish, which I hope won't cause errors with jar re/obfustication (first two lines of snippet). From the tasks that are run, I can see that the jar is, in fact, reobfusticated prior to uploading (as part of the build process), so I suppose that I'll have to wait and see for the future as to what will work and what not... jar.finalizedBy('reobfJar') //publish.dependsOn('reobfJar') publishing { } configurations { deployerJars } uploadArchives { repositories { mavenDeployer { configuration = configurations.deployerJars repository(url: "https://maven.pkg.github.com/GenElectrovise/MagiksMostEvile") { authentication(userName: project.githubGenElectroviseUsername, password: project.githubGenElectroviseToken) } } mavenDeployer { repository(url: "file:///${project.projectDir}/mcmodsrepo") } } }
  11. How can I publish my mod project to a GitHub package? I noticed that Forge already has a publishing section in build.gradle, but some of it clashes with the GitHub documentation on this, so I figured Forge might have some requirements for this? If there is, in fact, nothing special to do, just say and I'll go back to the Gradle and GitHub docs but I thought it'd be good to ask here first Edit: The "clashes" I mentioned: https://docs.github.com/en/packages/guides/configuring-gradle-for-use-with-github-packages publications { gpr(MavenPublication) { from(components.java) } } https://github.com/GenElectrovise/MagiksMostEvile/blob/feature/1.16.4/kitty_the_kraken/build.gradle (Default Forge build.gradle - see line 144) publications { mavenJava(MavenPublication) { artifact jar } }
  12. @Purplicious_Cow Hmmm I've also been looking at this: Might be a problem with this line: field_242740_q refers to a set of DimensionSettings generated by func_242745_a. That function takes a RegistryKey as a parameter, and in this case, it is passed field_242734_c which is the key for the overworld dimension. That might be the issue? Don't quote me on this! I have the same issue as you, but for all dimensions!
  13. @CaiGuyCrafter "We" refers to the members of this forum, which is for people modding using Forge directly, not MCreator. Given that you are using MCreator, I would recommend using the MCreator forum https://mcreator.net/forum. Mixing auto-generated code with human-written stuff sounds like a pretty gruelling experience to me, but maybe someone there can help. If you want help with Forge, you've come to the right place. Only Forge though.
  14. We need more information - this may not be a problem with Forge. Please post debug.log This is found in ".minecraft/run/logs/debug.log"
  15. How did you set up your workspace thus far?
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.