Skip to content
This repository was archived by the owner on May 25, 2024. It is now read-only.

Use mixins accessors + some misc fixes #77

Merged
merged 28 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
28e65a9
Change reflections to mixins
kuba6000 Apr 11, 2023
ba735db
Wrap witchery checking
kuba6000 Apr 11, 2023
6ee90cb
Remove more repeating code
kuba6000 Apr 11, 2023
fca9368
hmm
kuba6000 Apr 14, 2023
c7e39d9
test generation
kuba6000 Apr 14, 2023
e077622
test
kuba6000 Apr 17, 2023
fba05bc
client sided
kuba6000 Apr 23, 2023
a447645
Merge branch 'master' into accessors
kuba6000 Jun 3, 2023
f962516
Update CommandCustomDrops.java
kuba6000 Jun 3, 2023
bc06dae
Update MobRecipeLoader.java
kuba6000 Jun 3, 2023
da0062a
Save to static variable
kuba6000 Jun 3, 2023
1a1a71f
Imports
kuba6000 Jun 3, 2023
542776e
Log message
kuba6000 Jun 3, 2023
b95e2fe
Convert InfernalHelper to mixin accessors
kuba6000 Jun 3, 2023
9e3a4ae
Update build.gradle
kuba6000 Jun 3, 2023
b46e160
One more
kuba6000 Jun 3, 2023
813e60c
Return class nodes to optimize
kuba6000 Jun 3, 2023
a3b1e34
Merge branch 'master' into accessors
kuba6000 Jun 10, 2023
507dd95
Translations mixin
kuba6000 Jun 14, 2023
8dbcc3a
Automatically add commands
kuba6000 Jun 14, 2023
08aa496
Fixes
kuba6000 Jun 14, 2023
51c8727
Fix https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/1…
kuba6000 Jun 15, 2023
c85e544
Update kubatech.java
kuba6000 Jun 15, 2023
b91f9ba
Update CommonProxy.java
kuba6000 Jun 15, 2023
cd6584c
Unnecessary qualified reference
kuba6000 Jun 15, 2023
2d52178
Simplify ItemUtils
kuba6000 Jun 15, 2023
74331d1
Check if single player diffrently
kuba6000 Jun 15, 2023
08b21f5
Remove accessor for infernal-mobs
kuba6000 Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ def getManifestAttributes() {
"ForceLoadAsMod": !containsMixinsAndOrCoreModOnly.toBoolean()
]
}
manifestAttributes += ["Main-class": "kubatech.standalone"]
return manifestAttributes
}

Expand Down
38 changes: 36 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
// Add your dependencies here
/*
* Add your dependencies here. Supported configurations:
* - api("group:name:version:classifier"): if you use the types from this dependency in the public API of this mod
* Available at runtime and compiletime for mods depending on this mod
* - implementation("g:n:v:c"): if you need this for internal implementation details of the mod, but none of it is visible via the public API
* Available at runtime but not compiletime for mods depending on this mod
* - compileOnly("g:n:v:c"): if the mod you're building doesn't need this dependency during runtime at all, e.g. for optional mods
* Not available at all for mods depending on this mod, only visible at compiletime for this mod
* - compileOnlyApi("g:n:v:c"): like compileOnly, but also visible at compiletime for mods depending on this mod
* Available at compiletime but not runtime for mods depending on this mod
* - runtimeOnlyNonPublishable("g:n:v:c"): if you want to include a mod in this mod's runClient/runServer runs, but not publish it as a dependency
* Not available at all for mods depending on this mod, only visible at runtime for this mod
* - devOnlyNonPublishable("g:n:v:c"): a combination of runtimeOnlyNonPublishable and compileOnly for dependencies present at both compiletime and runtime,
* but not published as Maven dependencies - useful for RFG-deobfuscated dependencies or local testing
* - runtimeOnly("g:n:v:c"): if you don't need this at compile time, but want it to be present at runtime
* Available at runtime for mods depending on this mod
* - annotationProcessor("g:n:v:c"): mostly for java compiler plugins, if you know you need this, use it, otherwise don't worry
* - testCONFIG("g:n:v:c") - replace CONFIG by one of the above (except api), same as above but for the test sources instead of main
*
* - shadowImplementation("g:n:v:c"): effectively the same as API, but the dependency is included in your jar under a renamed package name
* Requires you to enable usesShadowedDependencies in gradle.properties
*
* - compile("g:n:v:c"): deprecated, replace with "api" (works like the old "compile") or "implementation" (can be more efficient)
*
* You can exclude transitive dependencies (dependencies of the chosen dependency) by appending { transitive = false } if needed,
* but use this sparingly as it can break using your mod as another mod's dependency if you're not careful.
*
* To depend on obfuscated jars you can use `devOnlyNonPublishable(rfg.deobf("dep:spec:1.2.3"))` to fetch an obfuscated jar from maven,
* or `devOnlyNonPublishable(rfg.deobf(project.files("libs/my-mod-jar.jar")))` to use a file.
*
* Gradle names for some of the configuration can be misleading, compileOnlyApi and runtimeOnly both get published as dependencies in Maven, but compileOnly does not.
* The buildscript adds runtimeOnlyNonPublishable to also have a runtime dependency that's not published.
*
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/

dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.82:dev')
api("com.github.GTNewHorizons:EnderCore:0.2.16:dev")
api("com.github.GTNewHorizons:EnderIO:2.4.18:dev")
api("com.github.GTNewHorizons:Infernal-Mobs:1.7.8-GTNH:dev")
api("com.github.GTNewHorizons:ForestryMC:4.6.7:dev")
api("com.github.GTNewHorizons:ModularUI:1.1.10:dev")
devOnlyNonPublishable("com.github.GTNewHorizons:Infernal-Mobs:1.7.9-GTNH:dev")
//compileOnly("curse.maven:extrautilities-225561:2264384") {
// transitive = false
//}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/kubatech/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import kubatech.api.LoaderReference;
import kubatech.commands.CommandBees;
import kubatech.commands.CommandConfig;
import kubatech.commands.CommandHandler;
import kubatech.commands.CommandHelp;
import kubatech.commands.CommandTea;
import kubatech.config.Config;
import kubatech.loaders.MTLoader;
import kubatech.loaders.RecipeLoader;
Expand Down Expand Up @@ -76,10 +72,6 @@ public void serverAboutToStart(FMLServerAboutToStartEvent event) {}
public void serverStarting(FMLServerStartingEvent event) {
RecipeLoader.addRecipesLate();
CommandHandler cmd = new CommandHandler();
cmd.addCommand(new CommandHelp());
cmd.addCommand(new CommandConfig());
cmd.addCommand(new CommandBees());
cmd.addCommand(new CommandTea());
event.registerServerCommand(cmd);
}

Expand Down
231 changes: 0 additions & 231 deletions src/main/java/kubatech/api/helpers/InfernalHelper.java

This file was deleted.

63 changes: 63 additions & 0 deletions src/main/java/kubatech/api/helpers/ReflectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@

package kubatech.api.helpers;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

import net.minecraft.launchwrapper.Launch;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

public class ReflectionHelper {

Expand Down Expand Up @@ -140,4 +154,53 @@ public static <T> T callMethod(Object obj, String methodName, T defaultValue, Ob
return defaultValue;
}
}

/**
* Gets all classes in a specific package path, works only for jar files.
*
* @param packageName The package name
* @return The class nodes
*/
public static Collection<ClassNode> getClasses(String packageName) throws IOException, SecurityException {
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
assert classLoader != null;
String packagePath = packageName.replace('.', '/');
URL resource = classLoader.getResource(packagePath);
if (resource == null) throw new FileNotFoundException();
if (!resource.getProtocol()
.equals("jar")) return Collections.emptySet();
String jarPath = resource.getPath();

try (JarFile jar = new JarFile(jarPath.substring(5, jarPath.indexOf('!')))) {
return jar.stream()
.filter(
j -> !j.isDirectory() && j.getName()
.startsWith(packagePath)
&& j.getName()
.endsWith(".class"))
.map(j -> {
try {
String name = j.getName();
URL jarResource = Launch.classLoader.getResource(name);
if (jarResource == null) return null;
byte[] bytes;
try (InputStream is = jarResource.openStream()) {
bytes = new byte[(int) j.getSize()];
if (is.read(bytes) != bytes.length) return null;
if (is.available() > 0) return null;
}

ClassNode cn = new ClassNode();
ClassReader cr = new ClassReader(bytes);
cr.accept(cn, 0);

return cn;
} catch (IOException ignored) {}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static class Handler implements IMessageHandler<CustomTileEntityPacket, I

@Override
public IMessage onMessage(CustomTileEntityPacket message, MessageContext ctx) {
if (!ModUtils.isClientSided) return null;
if (!ModUtils.isClientThreaded()) return null;
Minecraft mc = Minecraft.getMinecraft();
if (mc == null) return null;
if (mc.thePlayer == null) return null;
Expand Down
Loading