From a24c08ead948fad10a4ec080d7b80889f124789e Mon Sep 17 00:00:00 2001 From: Articdive <13535885+Articdive@users.noreply.github.com> Date: Mon, 7 Jun 2021 17:23:31 +0200 Subject: [PATCH 1/2] Fix potion effect IDs. --- .../net/minestom/codegen/potion/PotionEffectGenerator.java | 6 +++--- .../java/net/minestom/server/potion/PotionEffect.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java b/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java index 4116f8620..05423ba89 100644 --- a/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java +++ b/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java @@ -81,7 +81,7 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator { potionEffectClass.addMethod( MethodSpec.methodBuilder("getId") .returns(TypeName.SHORT) - .addStatement("return (short) ordinal()") + .addStatement("return (short) (ordinal() + 1)") .addModifiers(Modifier.PUBLIC) .build() ); @@ -100,8 +100,8 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator { .returns(potionEffectClassName) .addAnnotation(Nullable.class) .addParameter(TypeName.SHORT, "id") - .beginControlFlow("if(id >= 0 && id < VALUES.length)") - .addStatement("return VALUES[id]") + .beginControlFlow("if(id >= 0 && id < VALUES.length + 1)") + .addStatement("return VALUES[id - 1]") .endControlFlow() .addStatement("return null") .addModifiers(Modifier.PUBLIC, Modifier.STATIC) diff --git a/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java b/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java index 7cdcb463a..e69b8d332 100644 --- a/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java +++ b/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java @@ -92,7 +92,7 @@ public enum PotionEffect implements Keyed { } public short getId() { - return (short) ordinal(); + return (short) (ordinal() + 1); } @NotNull @@ -102,8 +102,8 @@ public enum PotionEffect implements Keyed { @Nullable public static PotionEffect fromId(short id) { - if(id >= 0 && id < VALUES.length) { - return VALUES[id]; + if(id >= 0 && id < VALUES.length + 1) { + return VALUES[id - 1]; } return null; } From b0a991773a596331a490f674be0f6a97acc27704 Mon Sep 17 00:00:00 2001 From: Articdive <13535885+Articdive@users.noreply.github.com> Date: Mon, 7 Jun 2021 17:36:29 +0200 Subject: [PATCH 2/2] Make sure we stay in the potion ID range. --- .../java/net/minestom/codegen/potion/PotionEffectGenerator.java | 2 +- .../java/net/minestom/server/potion/PotionEffect.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java b/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java index 05423ba89..cc7eac6b4 100644 --- a/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java +++ b/code-generators/src/main/java/net/minestom/codegen/potion/PotionEffectGenerator.java @@ -100,7 +100,7 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator { .returns(potionEffectClassName) .addAnnotation(Nullable.class) .addParameter(TypeName.SHORT, "id") - .beginControlFlow("if(id >= 0 && id < VALUES.length + 1)") + .beginControlFlow("if(id >= 1 && id < VALUES.length + 1)") .addStatement("return VALUES[id - 1]") .endControlFlow() .addStatement("return null") diff --git a/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java b/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java index e69b8d332..e45255803 100644 --- a/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java +++ b/src/autogenerated/java/net/minestom/server/potion/PotionEffect.java @@ -102,7 +102,7 @@ public enum PotionEffect implements Keyed { @Nullable public static PotionEffect fromId(short id) { - if(id >= 0 && id < VALUES.length + 1) { + if(id >= 1 && id < VALUES.length + 1) { return VALUES[id - 1]; } return null;