mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 12:11:27 +01:00
Fixed PotionEffect ids
This commit is contained in:
parent
daa72719a0
commit
38bcb755c2
@ -82,7 +82,7 @@ public enum PotionEffect {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
return ordinal() + 1;
|
||||
}
|
||||
|
||||
public String getNamespaceID() {
|
||||
@ -90,8 +90,8 @@ public enum PotionEffect {
|
||||
}
|
||||
|
||||
public static PotionEffect fromId(int id) {
|
||||
if(id >= 0 && id < values().length) {
|
||||
return values()[id];
|
||||
if (id >= 0 && id < values().length + 1) {
|
||||
return values()[id - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -20,13 +20,23 @@ public abstract class BasicEnumGenerator extends MinestomEnumGenerator<BasicEnum
|
||||
private final boolean linear;
|
||||
private NamespaceID defaultEntry;
|
||||
|
||||
protected BasicEnumGenerator(File targetFolder) throws IOException {
|
||||
this(targetFolder, true);
|
||||
/**
|
||||
* True if the enum is linear and start by 1 instead of 0
|
||||
*/
|
||||
private boolean incrementOrdinal;
|
||||
|
||||
protected BasicEnumGenerator(File targetFolder, boolean linear, boolean incrementOrdinal) throws IOException {
|
||||
this.linear = linear;
|
||||
this.incrementOrdinal = incrementOrdinal;
|
||||
generateTo(targetFolder);
|
||||
}
|
||||
|
||||
protected BasicEnumGenerator(File targetFolder, boolean linear) throws IOException {
|
||||
this.linear = linear;
|
||||
generateTo(targetFolder);
|
||||
this(targetFolder, linear, false);
|
||||
}
|
||||
|
||||
protected BasicEnumGenerator(File targetFolder) throws IOException {
|
||||
this(targetFolder, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,9 +69,11 @@ public abstract class BasicEnumGenerator extends MinestomEnumGenerator<BasicEnum
|
||||
ParameterSpec idParam = ParameterSpec.builder(TypeName.INT, "id").build();
|
||||
ParameterSpec[] signature = new ParameterSpec[]{idParam};
|
||||
if (linear) {
|
||||
final String ordinalIncrementCondition = incrementOrdinal ? " + 1" : "";
|
||||
final String ordinalIncrementIndex = incrementOrdinal ? " - 1" : "";
|
||||
generator.addStaticMethod("fromId", signature, className, code -> {
|
||||
code.beginControlFlow("if($N >= 0 && $N < values().length)", idParam, idParam)
|
||||
.addStatement("return values()[$N]", idParam)
|
||||
code.beginControlFlow("if ($N >= 0 && $N < values().length" + ordinalIncrementCondition + ")", idParam, idParam)
|
||||
.addStatement("return values()[$N" + ordinalIncrementIndex + "]", idParam)
|
||||
.endControlFlow()
|
||||
.addStatement("return " + (defaultEntry == null ? "null" : identifier(defaultEntry)));
|
||||
}
|
||||
@ -94,7 +106,7 @@ public abstract class BasicEnumGenerator extends MinestomEnumGenerator<BasicEnum
|
||||
ClassName registriesClass = ClassName.get(Registries.class);
|
||||
if (linear) {
|
||||
generator.setParams(ParameterSpec.builder(ClassName.get(String.class), "namespaceID").build());
|
||||
generator.addMethod("getId", new ParameterSpec[0], TypeName.INT, code -> code.addStatement("return ordinal()"));
|
||||
generator.addMethod("getId", new ParameterSpec[0], TypeName.INT, code -> code.addStatement("return ordinal()" + (incrementOrdinal ? " + 1" : "")));
|
||||
} else {
|
||||
generator.setParams(ParameterSpec.builder(ClassName.get(String.class), "namespaceID").build(), ParameterSpec.builder(TypeName.INT, "id").build());
|
||||
generator.addMethod("getId", new ParameterSpec[0], TypeName.INT, code -> code.addStatement("return $N", "id"));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.codegen.potions;
|
||||
|
||||
import net.minestom.codegen.BasicEnumGenerator;
|
||||
import net.minestom.codegen.stats.StatsEnumGenerator;
|
||||
import net.minestom.server.registry.ResourceGatherer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -42,7 +41,7 @@ public class PotionEffectEnumGenerator extends BasicEnumGenerator {
|
||||
}
|
||||
|
||||
private PotionEffectEnumGenerator(File targetFolder) throws IOException {
|
||||
super(targetFolder);
|
||||
super(targetFolder, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user