Skip to content

Commit

Permalink
Fixes for 1.20.2 + added 2 new particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Fierioziy committed Oct 14, 2023
1 parent 3f5e61b commit c51dbc2
Show file tree
Hide file tree
Showing 25 changed files with 608 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ParticleNativeAPI-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ParticleNativeAPI-parent</artifactId>
<groupId>com.github.fierioziy.particlenativeapi</groupId>
<version>4.0.0</version>
<version>4.1.0</version>
</parent>

<artifactId>ParticleNativeAPI-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public abstract class ParticleList_1_13 extends ParticleSupplier_1_13 {

public final ParticleTypeShriek SHRIEK = SHRIEK();

// 1.20.1
public final ParticleType CHERRY_LEAVES = CHERRY_LEAVES();

public final ParticleType EGG_CRACK = EGG_CRACK();

protected ParticleList_1_13(ParticleNativeAPI api) {
this.api = api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,8 @@ abstract class ParticleSupplier_1_13 {

protected abstract ParticleTypeShriek SHRIEK();

// 1.20.1
protected abstract ParticleType CHERRY_LEAVES();
protected abstract ParticleType EGG_CRACK();

}
2 changes: 1 addition & 1 deletion ParticleNativeAPI-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ParticleNativeAPI-parent</artifactId>
<groupId>com.github.fierioziy.particlenativeapi</groupId>
<version>4.0.0</version>
<version>4.1.0</version>
</parent>

<artifactId>ParticleNativeAPI-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.fierioziy.particlenativeapi.core.asm.mapping.SpigotClassRegistry;
import com.github.fierioziy.particlenativeapi.core.asm.packet.ParticlePacketProvider;
import com.github.fierioziy.particlenativeapi.core.asm.packet.ParticlePacketProvider_1_17;
import com.github.fierioziy.particlenativeapi.core.asm.packet.ParticlePacketProvider_1_20_2;
import com.github.fierioziy.particlenativeapi.core.asm.packet.ParticlePacketProvider_1_7;
import com.github.fierioziy.particlenativeapi.core.asm.particle.type.*;
import com.github.fierioziy.particlenativeapi.core.asm.skeleton.ClassSkeleton;
Expand Down Expand Up @@ -78,6 +79,12 @@ else if (internal.isVersion_1_19_3()) {
particlePacketProvider = new ParticlePacketProvider_1_17(this);
particleTypesProvider = new ParticleTypesProvider_1_19_3(this);
}
else if (internal.isVersion_1_20_2()) {
currentVersion = SpigotVersion.V1_20_2;
currentParticleVersion = SpigotParticleVersion.V1_18;
particlePacketProvider = new ParticlePacketProvider_1_20_2(this);
particleTypesProvider = new ParticleTypesProvider_1_19_3(this);
}
else throw new ParticleException("Error: this server version is not supported!");

suffix = currentVersion.getSuffix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public class SpigotClassRegistry {

public ClassMapping entity = unregistered("Entity");

public ClassMapping serverCommonPacketListenerImpl = unregistered("ServerCommonPacketListenerImpl");

// mojang
public ClassMapping vector3fa = unregistered("Vector3fa");
public ClassMapping vector3f = unregistered("Vector3f");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public SpigotClassRegistry provideRegistry() {

classRegistry.entity = classRegistry.of("net/minecraft/world/entity/Entity");

classRegistry.serverCommonPacketListenerImpl = classRegistry.of("net/minecraft/server/network/ServerCommonPacketListenerImpl");

// mojang
classRegistry.vector3fa = classRegistry.of("com/mojang/math/Vector3fa");
classRegistry.vector3f = classRegistry.of("org/joml/Vector3f");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.fierioziy.particlenativeapi.core.asm.packet;

import com.github.fierioziy.particlenativeapi.core.asm.ContextASM;
import com.github.fierioziy.particlenativeapi.core.asm.packet.v1_17.ParticlePacketASM_1_17;
import com.github.fierioziy.particlenativeapi.core.asm.skeleton.ClassSkeleton;

public class ParticlePacketProvider_1_20_2 extends ParticlePacketProvider {

private final String playerConnectionFieldName;
private final String sendPacketMethodName;

public ParticlePacketProvider_1_20_2(ContextASM context) {
super(context);

playerConnectionFieldName = context.internal.getPlayerConnectionFieldName_1_17();
sendPacketMethodName = context.internal.getSendPacketMethodName_1_20_2();
}

@Override
public void registerClasses() {
new ParticlePacketASM_1_17(context,
ClassSkeleton.PARTICLE_PACKET,
playerConnectionFieldName, sendPacketMethodName)
.registerClass();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public String getPlayerConnectionFieldName_1_17() {
}

/**
* <p>Gets sendPacket method name in <code>PlayerConnection</code> class.</p>
* <p>Gets sendPacket method name in <code>PlayerConnection</code> class since 1.18.</p>
*
* @return a sendPacket method name in <code>PlayerConnection</code> class.
*/
Expand All @@ -259,6 +259,18 @@ public String getSendPacketMethodName_1_18() {
return RefUtils.tryInferMethodName(playerConnectionClass, void.class, packetClass);
}

/**
* <p>Gets sendPacket method name in <code>PlayerConnection</code> class since 1.20.2.</p>
*
* @return a sendPacket method name in <code>PlayerConnection</code> class.
*/
public String getSendPacketMethodName_1_20_2() {
Class<?> serverCommonPacketListenerImplClass = tryGetClass(refs.serverCommonPacketListenerImpl.className());
Class<?> packetClass = tryGetClass(refs.packet_1_17.className());

return RefUtils.tryInferMethodName(serverCommonPacketListenerImplClass, void.class, packetClass);
}

/**
* <p>Checks whenever current Spigot version is around MC 1.7 version.</p>
*
Expand All @@ -267,7 +279,7 @@ public String getSendPacketMethodName_1_18() {
*/
public boolean isVersion_1_7() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
clazz(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
String.class,
float.class, float.class, float.class,
float.class, float.class, float.class,
Expand All @@ -287,8 +299,8 @@ public boolean isVersion_1_7() {
*/
public boolean isVersion_1_8() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
Class.forName(refs.enumParticle.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
clazz(refs.enumParticle.className()), boolean.class,
float.class, float.class, float.class,
float.class, float.class, float.class,
float.class, int.class, int[].class
Expand All @@ -307,8 +319,8 @@ public boolean isVersion_1_8() {
*/
public boolean isVersion_1_13() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
Class.forName(refs.particleParam_1_7.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
clazz(refs.particleParam_1_7.className()), boolean.class,
float.class, float.class, float.class,
float.class, float.class, float.class,
float.class, int.class
Expand All @@ -327,8 +339,8 @@ public boolean isVersion_1_13() {
*/
public boolean isVersion_1_15() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
Class.forName(refs.particleParam_1_7.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_7.className()).getConstructor(
clazz(refs.particleParam_1_7.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
Expand All @@ -347,14 +359,14 @@ public boolean isVersion_1_15() {
*/
public boolean isVersion_1_17() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
Class.forName(refs.particleParam_1_17.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
clazz(refs.particleParam_1_17.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
);
Class<?> packetClass = Class.forName(refs.packet_1_17.className());
Class.forName(refs.playerConnection_1_17.className())
Class<?> packetClass = clazz(refs.packet_1_17.className());
clazz(refs.playerConnection_1_17.className())
.getDeclaredMethod("sendPacket", packetClass);

return true;
Expand All @@ -371,14 +383,14 @@ public boolean isVersion_1_17() {
*/
public boolean isVersion_1_18() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
Class.forName(refs.particleParam_1_17.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
clazz(refs.particleParam_1_17.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
);

Class.forName(refs.vibrationPath.className());
clazz(refs.vibrationPath.className());

return true;
} catch (NoSuchMethodException | ClassNotFoundException e) {
Expand All @@ -394,18 +406,18 @@ public boolean isVersion_1_18() {
*/
public boolean isVersion_1_19() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
Class.forName(refs.particleParam_1_17.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
clazz(refs.particleParam_1_17.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
);

Class.forName(refs.vibrationParticleOption.className()).getConstructor(
Class.forName(refs.positionSource.className()), int.class
clazz(refs.vibrationParticleOption.className()).getConstructor(
clazz(refs.positionSource.className()), int.class
);

Class.forName(refs.vector3fa.className());
clazz(refs.vector3fa.className());

return true;
} catch (NoSuchMethodException | ClassNotFoundException e) {
Expand All @@ -421,33 +433,68 @@ public boolean isVersion_1_19() {
*/
public boolean isVersion_1_19_3() {
try {
Class.forName(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
Class.forName(refs.particleParam_1_17.className()), boolean.class,
clazz(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
clazz(refs.particleParam_1_17.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
);

Class.forName(refs.vibrationParticleOption.className()).getConstructor(
Class.forName(refs.positionSource.className()), int.class
clazz(refs.vibrationParticleOption.className()).getConstructor(
clazz(refs.positionSource.className()), int.class
);

Class.forName(refs.vector3f.className());
clazz(refs.vector3f.className());

getSendPacketMethodName_1_18();

return true;
} catch (NoSuchMethodException | ClassNotFoundException e) {
} catch (NoSuchMethodException | ClassNotFoundException | ParticleException e) {
return false;
}
}

public Class<?> tryGetClass(String className) {
/**
* <p>Checks whenever current Spigot version is around MC 1.20.2 version.</p>
*
* @return true if this Spigot version has constructor
* from MC 1.20.2 version, false otherwise.
*/
public boolean isVersion_1_20_2() {
try {
return Class.forName(className, false, classLoader);
clazz(refs.packetPlayOutWorldParticles_1_17.className()).getConstructor(
clazz(refs.particleParam_1_17.className()), boolean.class,
double.class, double.class, double.class,
float.class, float.class, float.class,
float.class, int.class
);

clazz(refs.vibrationParticleOption.className()).getConstructor(
clazz(refs.positionSource.className()), int.class
);

clazz(refs.vector3f.className());

getSendPacketMethodName_1_20_2();

return true;
} catch (NoSuchMethodException | ClassNotFoundException | ParticleException e) {
return false;
}
}

private Class<?> tryGetClass(String className) {
try {
return clazz(className);
} catch (ClassNotFoundException e) {
throw new ParticleException(String.format(
"Class %s could not be found", className
));
}
}

public Class<?> clazz(String className) throws ClassNotFoundException {
return Class.forName(className, false, classLoader);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ private void fillMap_1_18() {

registrar.followNew("shriek");

// 1.20.1
registrar.followNew("cherry_leaves");
registrar.followNew("egg_crack");

registrar.defaultFollowUnprocessedNodes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum SpigotVersion {
V1_17("_1_17"),
V1_18("_1_18"),
V1_19("_1_19"),
V1_19_3("_1_19_3");
V1_19_3("_1_19_3"),
V1_20_2("_1_20_2");

private final String suffix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ParticleNativeCoreTest {
private static ParticleNativeAPI api_1_18;
private static ParticleNativeAPI api_1_19;
private static ParticleNativeAPI api_1_19_3;
private static ParticleNativeAPI api_1_20_2;

private static boolean initialized = false;

Expand All @@ -47,6 +48,7 @@ private static void initializeAPI() {
api_1_18 = loadAPI_1_18();
api_1_19 = loadAPI_1_19();
api_1_19_3 = loadAPI_1_19_3();
api_1_20_2 = loadAPI_1_20_2();
});

initialized = true;
Expand Down Expand Up @@ -96,6 +98,11 @@ public static ParticleNativeAPI getAPI_1_19_3() {
return api_1_19_3;
}

public static ParticleNativeAPI getAPI_1_20_2() {
initializeAPI();
return api_1_20_2;
}

/*
API loading methods
*/
Expand Down Expand Up @@ -196,6 +203,18 @@ private static ParticleNativeAPI loadAPI_1_19_3() {
return generationResult.api;
}

private static ParticleNativeAPI loadAPI_1_20_2() {
ParticleNativeClassLoader classLoader = prepareProperClassLoader();
SpigotClassRegistryProvider_1_20_2 classRegistryProvider = new SpigotClassRegistryProvider_1_20_2();

ParticleNativeCore core = new ParticleNativeCore(classLoader, classRegistryProvider);
ParticleNativeCore.GenerationResult generationResult = core.setupCore();

assertEquals(SpigotVersion.V1_20_2, generationResult.spigotVersion);

return generationResult.api;
}

private static ParticleNativeClassLoader prepareProperClassLoader() {
return new ParticleNativeClassLoader(ParticleNativeCoreTest.class.getClassLoader());
}
Expand Down
Loading

0 comments on commit c51dbc2

Please sign in to comment.