I'm building a 1.18.1 pack and have been doing some profiling and noticed that this mod is accounting for a good portion of the TPS. Using spark profiler (https://spark.lucko.me/DJ3mxQgdBB) it looks like there's some unnecessary overhead in the isSpaceWorld() function in these lines here which is caused by creating bunch of strings. Each time you create a new ResourceLocation java has to do some work to create the string for the location.
|
public static boolean isSpaceWorld(Level world) { |
|
if (Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"moon")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"moon_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mars")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mars_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mercury")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mercury_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"venus")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"venus_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"overworld_orbit"))) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public static boolean isOrbitWorld(Level world) { |
|
if (Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"overworld_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"moon_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mars_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"mercury_orbit")) |
|
|| Methodes.isWorld(world, new ResourceLocation(BeyondEarthMod.MODID,"venus_orbit"))) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public static boolean isWorld(Level world, ResourceLocation loc) { |
|
return world.dimension() == ResourceKey.create(Registry.DIMENSION_REGISTRY, loc); |
|
} |
I think creating some public static variables and referencing them (similar to what you've done here) would be better:
|
public static final ResourceLocation USING_NAME = new ResourceLocation(BeyondEarthMod.MODID, "using"); |
I see other spots in your code doing same thing that should also be using this pattern I think.