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

Commit 829e582

Browse files
committed
fix: potion effects not working on 1.20.2 (#88)
1 parent 9c49c84 commit 829e582

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

common/src/main/java/com/github/franckyi/ibeeditor/client/screen/model/category/item/ItemPotionEffectsCategoryModel.java

+20-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import com.github.franckyi.ibeeditor.client.screen.model.entry.item.PotionEffectEntryModel;
77
import com.github.franckyi.ibeeditor.client.screen.model.entry.item.PotionSelectionEntryModel;
88
import com.github.franckyi.ibeeditor.common.ModTexts;
9+
import net.minecraft.core.registries.BuiltInRegistries;
910
import net.minecraft.nbt.CompoundTag;
1011
import net.minecraft.nbt.ListTag;
1112
import net.minecraft.nbt.Tag;
1213
import net.minecraft.network.chat.MutableComponent;
14+
import net.minecraft.world.effect.MobEffects;
1315

1416
public class ItemPotionEffectsCategoryModel extends ItemEditorCategoryModel {
1517
private ListTag potionEffectList;
@@ -23,7 +25,7 @@ protected void setupEntries() {
2325
getEntries().add(new PotionSelectionEntryModel(this, ModTexts.DEFAULT_POTION,
2426
getTag().getString("Potion"), getCustomPotionColor(),
2527
p -> getTag().putString("Potion", p), this::setCustomPotionColor));
26-
getTag().getList("CustomPotionEffects", Tag.TAG_COMPOUND).stream()
28+
getTag().getList("custom_potion_effects", Tag.TAG_COMPOUND).stream()
2729
.map(CompoundTag.class::cast)
2830
.map(this::createPotionEffectEntry)
2931
.forEach(getEntries()::add);
@@ -63,36 +65,36 @@ private void setCustomPotionColor(int color) {
6365

6466
private EntryModel createPotionEffectEntry(CompoundTag tag) {
6567
if (tag != null) {
66-
int id = tag.getInt("Id");
67-
int amplifier = tag.getInt("Amplifier"); // defaults to 0
68-
int duration = tag.contains("Duration", Tag.TAG_INT) ? tag.getInt("Duration") : 1;
69-
boolean ambient = tag.getBoolean("Ambient"); // defaults to false
70-
boolean showParticles = !tag.contains("ShowParticles", Tag.TAG_BYTE) || tag.getBoolean("ShowParticles");
71-
boolean showIcon = tag.getBoolean("ShowIcon");
68+
String id = tag.getString("id");
69+
int amplifier = tag.getInt("amplifier"); // defaults to 0
70+
int duration = tag.contains("duration", Tag.TAG_INT) ? tag.getInt("duration") : 1;
71+
boolean ambient = tag.getBoolean("ambient"); // defaults to false
72+
boolean showParticles = !tag.contains("show_particles", Tag.TAG_BYTE) || tag.getBoolean("show_particles");
73+
boolean showIcon = tag.getBoolean("show_icon");
7274
return new PotionEffectEntryModel(this, id, amplifier, duration, ambient, showParticles, showIcon, this::addPotionEffect);
7375
}
74-
return new PotionEffectEntryModel(this, 1, 0, 1, false, true, true, this::addPotionEffect);
76+
return new PotionEffectEntryModel(this, BuiltInRegistries.MOB_EFFECT.getKey(MobEffects.MOVEMENT_SPEED).toString(), 0, 1, false, true, true, this::addPotionEffect);
7577
}
7678

7779
@Override
7880
public void apply() {
7981
potionEffectList = new ListTag();
8082
super.apply();
8183
if (!potionEffectList.isEmpty()) {
82-
getOrCreateTag().put("CustomPotionEffects", potionEffectList);
83-
} else if (getOrCreateTag().contains("CustomPotionEffects")) {
84-
getOrCreateTag().remove("CustomPotionEffects");
84+
getOrCreateTag().put("custom_potion_effects", potionEffectList);
85+
} else if (getOrCreateTag().contains("custom_potion_effects")) {
86+
getOrCreateTag().remove("custom_potion_effects");
8587
}
8688
}
8789

88-
private void addPotionEffect(int id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon) {
90+
private void addPotionEffect(String id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon) {
8991
CompoundTag tag = new CompoundTag();
90-
tag.putInt("Id", id);
91-
tag.putInt("Amplifier", amplifier);
92-
tag.putInt("Duration", duration);
93-
tag.putBoolean("Ambient", ambient);
94-
tag.putBoolean("ShowParticles", showParticles);
95-
tag.putBoolean("ShowIcon", showIcon);
92+
tag.putString("id", id);
93+
tag.putInt("amplifier", amplifier);
94+
tag.putInt("duration", duration);
95+
tag.putBoolean("ambient", ambient);
96+
tag.putBoolean("show_particles", showParticles);
97+
tag.putBoolean("show_icon", showIcon);
9698
potionEffectList.add(tag);
9799
}
98100
}

common/src/main/java/com/github/franckyi/ibeeditor/client/screen/model/entry/item/PotionEffectEntryModel.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.github.franckyi.ibeeditor.client.screen.model.entry.SelectionEntryModel;
88
import com.github.franckyi.ibeeditor.client.screen.model.selection.element.ListSelectionElementModel;
99
import com.github.franckyi.ibeeditor.common.ModTexts;
10-
import net.minecraft.core.Registry;
11-
import net.minecraft.core.registries.BuiltInRegistries;
1210
import net.minecraft.network.chat.MutableComponent;
13-
import net.minecraft.resources.ResourceLocation;
1411

1512
import java.util.List;
1613

@@ -19,8 +16,8 @@ public class PotionEffectEntryModel extends SelectionEntryModel {
1916
private final BooleanProperty ambientProperty, showParticlesProperty, showIconProperty;
2017
private final PotionEffectConsumer callback;
2118

22-
public PotionEffectEntryModel(CategoryModel category, int id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon, PotionEffectConsumer callback) {
23-
super(category, null, BuiltInRegistries.MOB_EFFECT.getKey(BuiltInRegistries.MOB_EFFECT.byId(id)).toString(), s -> {
19+
public PotionEffectEntryModel(CategoryModel category, String id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon, PotionEffectConsumer callback) {
20+
super(category, null, id, s -> {
2421
});
2522
amplifierProperty = IntegerProperty.create(amplifier);
2623
durationProperty = IntegerProperty.create(duration);
@@ -32,7 +29,7 @@ public PotionEffectEntryModel(CategoryModel category, int id, int amplifier, int
3229

3330
@Override
3431
public void apply() {
35-
callback.consume(BuiltInRegistries.MOB_EFFECT.getId(BuiltInRegistries.MOB_EFFECT.get(ResourceLocation.tryParse(getValue()))), getAmplifier(), getDuration(), isAmbient(), isShowParticles(), isShowIcon());
32+
callback.consume(getValue(), getAmplifier(), getDuration(), isAmbient(), isShowParticles(), isShowIcon());
3633
}
3734

3835
public int getAmplifier() {
@@ -117,6 +114,6 @@ public List<? extends ListSelectionElementModel> getSelectionItems() {
117114

118115
@FunctionalInterface
119116
public interface PotionEffectConsumer {
120-
void consume(int id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon);
117+
void consume(String id, int amplifier, int duration, boolean ambient, boolean showParticles, boolean showIcon);
121118
}
122119
}

forge_update.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"1.20-recommended": "2.2.3",
66
"1.20.1-latest": "2.2.3",
77
"1.20.1-recommended": "2.2.3",
8-
"1.20.2-latest": "2.2.5",
9-
"1.20.2-recommended": "2.2.5"
8+
"1.20.2-latest": "2.2.6",
9+
"1.20.2-recommended": "2.2.6"
1010
}
1111
}

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ org.gradle.daemon=false
44
# IBE Editor
55
minecraft_version=1.20.2
66
archives_base_name=IBEEditor
7-
mod_version=2.2.5
7+
mod_version=2.2.6
88
maven_group=com.github.franckyi.ibeeditor
99
# Fabric https://fabricmc.net/develop/
1010
fabric_loader_version=0.14.24
1111
fabric_api_version=0.90.7+1.20.2
12-
modmenu_version=8.0.0-beta.2
12+
modmenu_version=8.0.0
1313
# Forge https://files.minecraftforge.net/
14-
forge_version=48.0.34
14+
forge_version=48.0.40
1515
# NeoForge https://neoforged.net/
16-
neoforge_version=20.2.56-beta
16+
neoforge_version=20.2.62-beta
1717
# Build and release info
1818
java_version=17
1919
major_minecraft_version=1.20.2

versions.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"2.2.6": {
3+
"type": "release",
4+
"changelog": "* fix: potion effects not working on 1.20.2 (#88)"
5+
},
26
"2.2.5": {
37
"type": "release",
48
"changelog": "* fix: crash on startup due to Vault (#87)"

0 commit comments

Comments
 (0)