Skip to content

Commit

Permalink
Fixes for 1.20.6 + new particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Fierioziy committed May 13, 2024
1 parent c51dbc2 commit bda5cdd
Show file tree
Hide file tree
Showing 46 changed files with 1,723 additions and 156 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.1.0</version>
<version>4.2.0</version>
</parent>

<artifactId>ParticleNativeAPI-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public abstract class ParticleList_1_13 extends ParticleSupplier_1_13 {
public final ParticleTypeMotion LARGE_SMOKE = LARGE_SMOKE();
public final ParticleType EFFECT = EFFECT();
public final ParticleType INSTANT_EFFECT = INSTANT_EFFECT();
public final ParticleTypeColorable ENTITY_EFFECT = ENTITY_EFFECT();
public final ParticleTypeColorable AMBIENT_ENTITY_EFFECT = AMBIENT_ENTITY_EFFECT();
public final ParticleTypeColorable ENTITY_EFFECT = ENTITY_EFFECT();// replaced in 1.20.5 in ParticleList_1_19_Part (mutually exclusive)
public final ParticleTypeColorable AMBIENT_ENTITY_EFFECT = AMBIENT_ENTITY_EFFECT();// removed in 1.20.5
public final ParticleType WITCH = WITCH();
public final ParticleType DRIPPING_WATER = DRIPPING_WATER();
public final ParticleType DRIPPING_LAVA = DRIPPING_LAVA();
Expand Down Expand Up @@ -167,6 +167,26 @@ public abstract class ParticleList_1_13 extends ParticleSupplier_1_13 {

public final ParticleType EGG_CRACK = EGG_CRACK();

// 1.20.5
public final ParticleType GUST = GUST();
public final ParticleType SMALL_GUST = SMALL_GUST();
public final ParticleType GUST_EMITTER_LARGE = GUST_EMITTER_LARGE();
public final ParticleType GUST_EMITTER_SMALL = GUST_EMITTER_SMALL();

public final ParticleType INFESTED = INFESTED();
public final ParticleType ITEM_COBWEB = ITEM_COBWEB();
public final ParticleTypeMotion WHITE_SMOKE = WHITE_SMOKE();

public final ParticleTypeMotion DUST_PLUME = DUST_PLUME();
public final ParticleTypeBlockMotion DUST_PILLAR = DUST_PILLAR();

public final ParticleTypeMotion TRIAL_SPAWNER_DETECTION = TRIAL_SPAWNER_DETECTION();
public final ParticleTypeMotion TRIAL_SPAWNER_DETECTION_OMINOUS = TRIAL_SPAWNER_DETECTION_OMINOUS();
public final ParticleTypeMotion OMINOUS_SPAWNING = OMINOUS_SPAWNING();

public final ParticleTypeMotion VAULT_CONNECTION = VAULT_CONNECTION();
public final ParticleType TRIAL_OMEN = TRIAL_OMEN();

protected ParticleList_1_13(ParticleNativeAPI api) {
this.api = api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public abstract class ParticleList_1_19_Part extends ParticleSupplier_1_19_Part
// 1.19
public final ParticleTypeVibration VIBRATION = VIBRATION();

// 1.20.5
public final ParticleTypeColor ENTITY_EFFECT = ENTITY_EFFECT();

protected ParticleList_1_19_Part(ParticleNativeAPI api) {
this.api = api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public abstract class ParticleList_1_8 extends ParticleSupplier_1_8 {
public final ParticleTypeMotion SMOKE_LARGE = SMOKE_LARGE();
public final ParticleType SPELL = SPELL();
public final ParticleType SPELL_INSTANT = SPELL_INSTANT();
public final ParticleTypeColorable SPELL_MOB = SPELL_MOB();
public final ParticleTypeColorable SPELL_MOB_AMBIENT = SPELL_MOB_AMBIENT();
public final ParticleTypeColorable SPELL_MOB = SPELL_MOB();// replaced in 1.20.5 in ParticleList_1_19_Part (mutually exclusive)
public final ParticleTypeColorable SPELL_MOB_AMBIENT = SPELL_MOB_AMBIENT();// removed in 1.20.5
public final ParticleType SPELL_WITCH = SPELL_WITCH();
public final ParticleType DRIP_WATER = DRIP_WATER();
public final ParticleType DRIP_LAVA = DRIP_LAVA();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,24 @@ abstract class ParticleSupplier_1_13 {
protected abstract ParticleType CHERRY_LEAVES();
protected abstract ParticleType EGG_CRACK();

// 1.20.5
protected abstract ParticleType GUST();
protected abstract ParticleType SMALL_GUST();
protected abstract ParticleType GUST_EMITTER_LARGE();
protected abstract ParticleType GUST_EMITTER_SMALL();

protected abstract ParticleType INFESTED();
protected abstract ParticleType ITEM_COBWEB();
protected abstract ParticleTypeMotion WHITE_SMOKE();

protected abstract ParticleTypeMotion DUST_PLUME();
protected abstract ParticleTypeBlockMotion DUST_PILLAR();

protected abstract ParticleTypeMotion TRIAL_SPAWNER_DETECTION();
protected abstract ParticleTypeMotion TRIAL_SPAWNER_DETECTION_OMINOUS();
protected abstract ParticleTypeMotion OMINOUS_SPAWNING();

protected abstract ParticleTypeMotion VAULT_CONNECTION();
protected abstract ParticleType TRIAL_OMEN();

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ abstract class ParticleSupplier_1_19_Part {
// 1.19
protected abstract ParticleTypeVibration VIBRATION();

// 1.20.5
protected abstract ParticleTypeColor ENTITY_EFFECT();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.fierioziy.particlenativeapi.api.particle.type;

import com.github.fierioziy.particlenativeapi.api.utils.Shared;
import org.bukkit.Color;

/**
* <p>Class used to represent particle type that needs a color.</p>
*
* <p>It provides a non-reflective <code>color</code> method overloads
* to construct <code>ParticleType</code> with selected color.</p>
*
* <p>All <code>color</code> methods does not validate parameters in any way.</p>
*
* <p><b>IMPORTANT NOTE</b>: All methods annotated with {@link Shared} annotation
* caches and returns exactly one and the same instance with changed state between method calls.
* For an independent copy of returned instances, check <code>detachCopy</code> methods on them.</p>
*
* @see ParticleType
*/
public interface ParticleTypeColor {

/**
* <p>Selects a color this particle should get.</p>
*
* <p>Parameters are not validated in any way.</p>
*
* @param color a {@link Color} object representing
* desired particle color.
* @return a valid shared {@link ParticleType} object with selected
* color.
*/
@Shared ParticleType color(Color color);

/**
* <p>Selects a color this particle should get.</p>
*
* <p>Parameters are not validated in any way.</p>
*
* <p><b>This method is overridden by dynamically generated
* subclasses.</b></p>
*
* @param r red color value that should be between 0 and 255.
* @param g green color value that should be between 0 and 255.
* @param b blue color value that should be between 0 and 255.
* @return a valid shared {@link ParticleType} object with selected
* color.
*/
@Shared ParticleType color(int r, int g, int b);

/**
* <p>Checks if this particle is supported by this Spigot version.</p>
*
* <p><b>This method is overridden by dynamically generated
* subclasses.</b></p>
*
* @return true if this particle is supported by
* this Spigot version, false otherwise.
*/
boolean isPresent();

}
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.1.0</version>
<version>4.2.0</version>
</parent>

<artifactId>ParticleNativeAPI-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ else if (internal.isVersion_1_20_2()) {
particlePacketProvider = new ParticlePacketProvider_1_20_2(this);
particleTypesProvider = new ParticleTypesProvider_1_19_3(this);
}
else if (internal.isVersion_1_20_5()) {
currentVersion = SpigotVersion.V1_20_5;
currentParticleVersion = SpigotParticleVersion.V1_20_5;
particlePacketProvider = new ParticlePacketProvider_1_20_2(this);
particleTypesProvider = new ParticleTypesProvider_1_20_5(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 @@ -101,6 +101,8 @@ public class SpigotClassRegistry {

public ClassMapping serverCommonPacketListenerImpl = unregistered("ServerCommonPacketListenerImpl");

public ClassMapping colorParticleOption = unregistered("ColorParticleOption");

// 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 @@ -94,6 +94,8 @@ public SpigotClassRegistry provideRegistry() {

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

classRegistry.colorParticleOption = classRegistry.of("net/minecraft/core/particles/ColorParticleOption");

// 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
Expand Up @@ -75,13 +75,18 @@ public void generateParticleFactoryMethods(ClassWriter cw, SpigotParticleVersion

int local_this = 0;

// try to convert particle name to current server version
// try to convert particle name to current particle version
Optional<String> resolvedName = particleRegistry
.find(interfaceVersion, particleName.toLowerCase(), SpigotParticleVersion.V1_13)
.map(String::toUpperCase);

// if it is ENTITY_EFFECT in 1.19 list which doesn't have implementation, visit invalid particle type
if (particleListSkeleton.equals(ClassSkeleton.PARTICLE_LIST_1_19_PART)
&& particleName.equals("ENTITY_EFFECT")) {
visitInvalidType(mv, returnSkeleton);
}
// if found and it exists, then instantiate
if (resolvedName.isPresent() && currentParticleSet.contains(resolvedName.get())) {
else if (resolvedName.isPresent() && currentParticleSet.contains(resolvedName.get())) {
mv.visitTypeInsn(NEW, particleReturnTypeImpl.internalName());
mv.visitInsn(DUP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.fierioziy.particlenativeapi.core.asm.skeleton.ClassSkeleton;
import com.github.fierioziy.particlenativeapi.core.asm.particle.type.v1_17.*;
import com.github.fierioziy.particlenativeapi.core.asm.utils.SpigotParticleVersion;
import com.github.fierioziy.particlenativeapi.core.asm.utils.SpigotVersion;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;

Expand Down Expand Up @@ -89,12 +90,19 @@ public void generateParticleFactoryMethods(ClassWriter cw, SpigotParticleVersion
Optional<String> resolvedName = particleRegistry
.find(interfaceVersion, particleName.toLowerCase(), SpigotParticleVersion.V1_13);

// if it is vibration in new interface, don't instantiate it
if (interfaceVersion.equals(SpigotParticleVersion.V1_18)
// if it is vibration in 1.19 list between 1.17 and 1.18, visit invalid particle type
if (particleListSkeleton.equals(ClassSkeleton.PARTICLE_LIST_1_19_PART)
&& context.currentVersion.between(SpigotVersion.V1_17, SpigotVersion.V1_18)
&& particleName.equals("VIBRATION")
&& currentParticlesMap.containsKey("vibration")) {
visitInvalidType(mv, returnSkeleton);
} // if found and it exists, then instantiate
}
// if it is ENTITY_EFFECT in 1.19 list which doesn't have implementation, visit invalid particle type
else if (particleListSkeleton.equals(ClassSkeleton.PARTICLE_LIST_1_19_PART)
&& particleName.equals("ENTITY_EFFECT")) {
visitInvalidType(mv, returnSkeleton);
}
// if found and it exists, then instantiate
else if (resolvedName.isPresent() && currentParticlesMap.containsKey(resolvedName.get())) {
// get field name from Particles class associated with particle name
String fieldName = currentParticlesMap.get(resolvedName.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ public void generateParticleFactoryMethods(ClassWriter cw, SpigotParticleVersion
Optional<String> resolvedName = particleRegistry
.find(particleVersion, particleName.toLowerCase(), SpigotParticleVersion.V1_18);

// if it is vibration in new interface, don't instantiate it
// if it is vibration in new interface between 1.17 and 1.18, visit invalid particle type
if (particleListSkeleton.equals(ClassSkeleton.PARTICLE_LIST_1_19_PART)
&& context.currentVersion.equals(SpigotVersion.V1_18)// TODO can be better?
&& context.currentVersion.between(SpigotVersion.V1_17, SpigotVersion.V1_18)
&& particleName.equals("VIBRATION")
&& currentParticlesMap.containsKey("vibration")) {
visitInvalidType(mv, returnSkeleton);
} // if found and it exists, then instantiate
}
// if it is ENTITY_EFFECT in 1.19 list which doesn't have implementation, visit invalid particle type
else if (particleListSkeleton.equals(ClassSkeleton.PARTICLE_LIST_1_19_PART)
&& particleName.equals("ENTITY_EFFECT")) {
visitInvalidType(mv, returnSkeleton);
}
// if found and it exists, then instantiate
else if (resolvedName.isPresent() && currentParticlesMap.containsKey(resolvedName.get())) {
// get field name from Particles class associated with particle name
String fieldName = currentParticlesMap.get(resolvedName.get());
Expand Down
Loading

0 comments on commit bda5cdd

Please sign in to comment.