Skip to content

Commit

Permalink
fix potion effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed May 21, 2024
1 parent 22e18ca commit 0c2ec57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableList;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static void register(final DataProviderRegistrator registrator) {
.create(Keys.POTION_TYPE)
.get(h -> (PotionType) h.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion().map(Holder::value).orElse(null)) // TODO empty POTION gone?
.set((h, v) -> {
final var potion = Optional.ofNullable(v).map(Potion.class::cast).map(Holder::direct); // TODO set empty POTION? same as delete?
final var potion = Optional.ofNullable(v).map(Potion.class::cast).map(BuiltInRegistries.POTION::wrapAsHolder); // TODO set empty POTION? same as delete?
h.update(DataComponents.POTION_CONTENTS, PotionContents.EMPTY, contents -> new PotionContents(potion, contents.customColor(), contents.customEffects()));
})
.delete(h -> h.update(DataComponents.POTION_CONTENTS, PotionContents.EMPTY, contents -> new PotionContents(Optional.empty(), contents.customColor(), contents.customEffects())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package org.spongepowered.common.effect.potion;


import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -148,7 +148,8 @@ public PotionEffect build() throws IllegalStateException {
if (!this.duration.isInfinite() && this.duration.ticks() <= 0) {
throw new IllegalStateException("Duration has not been set");
}
return (PotionEffect) new MobEffectInstance(Holder.direct((MobEffect) this.potionType),

return (PotionEffect) new MobEffectInstance(BuiltInRegistries.MOB_EFFECT.wrapAsHolder((MobEffect) this.potionType),
SpongeTicks.toSaturatedIntOrInfinite(this.duration),
this.amplifier,
this.isAmbient,
Expand Down

0 comments on commit 0c2ec57

Please sign in to comment.