net.minecraft.world.item.consume_effects

This commit is contained in:
Noah van der Aa 2024-12-14 18:27:10 +01:00
parent 1f128f76c7
commit 52d26db5a0
No known key found for this signature in database
GPG key ID: 547D90BC6FF753CF
10 changed files with 85 additions and 135 deletions

View file

@ -0,0 +1,19 @@
--- a/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
@@ -46,14 +_,14 @@
}
@Override
- public boolean apply(Level level, ItemStack stack, LivingEntity entity) {
+ public boolean apply(Level level, ItemStack stack, LivingEntity entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) { // CraftBukkit
if (entity.getRandom().nextFloat() >= this.probability) {
return false;
} else {
boolean flag = false;
for (MobEffectInstance mobEffectInstance : this.effects) {
- if (entity.addEffect(new MobEffectInstance(mobEffectInstance))) {
+ if (entity.addEffect(new MobEffectInstance(mobEffectInstance), cause)) { // CraftBukkit
flag = true;
}
}

View file

@ -0,0 +1,14 @@
--- a/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
@@ -18,7 +_,9 @@
}
@Override
- public boolean apply(Level level, ItemStack stack, LivingEntity entity) {
- return entity.removeAllEffects();
+ // CraftBukkit start
+ public boolean apply(Level level, ItemStack stack, LivingEntity entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) {
+ return entity.removeAllEffects(cause);
+ // CraftBukkit end
}
}

View file

@ -0,0 +1,19 @@
--- a/net/minecraft/world/item/consume_effects/ConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ConsumeEffect.java
@@ -19,7 +_,15 @@
ConsumeEffect.Type<? extends ConsumeEffect> getType();
- boolean apply(Level level, ItemStack stack, LivingEntity entity);
+ // CraftBukkit start
+ default boolean apply(Level level, ItemStack stack, LivingEntity entity) {
+ return this.apply(level, stack, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ default boolean apply(Level level, ItemStack stack, LivingEntity entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) {
+ return this.apply(level, stack, entity);
+ }
+ // CraftBukkit end
public record Type<T extends ConsumeEffect>(MapCodec<T> codec, StreamCodec<RegistryFriendlyByteBuf, T> streamCodec) {
public static final ConsumeEffect.Type<ApplyStatusEffectsConsumeEffect> APPLY_EFFECTS = register(

View file

@ -0,0 +1,16 @@
--- a/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
@@ -35,11 +_,11 @@
}
@Override
- public boolean apply(Level level, ItemStack stack, LivingEntity entity) {
+ public boolean apply(Level level, ItemStack stack, LivingEntity entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) { // CraftBukkit
boolean flag = false;
for (Holder<MobEffect> holder : this.effects) {
- if (entity.removeEffect(holder)) {
+ if (entity.removeEffect(holder, cause)) { // CraftBukkit
flag = true;
}
}

View file

@ -0,0 +1,17 @@
--- a/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
@@ -55,7 +_,13 @@
}
Vec3 vec3 = entity.position();
- if (entity.randomTeleport(d, d1, d2, true)) {
+ // CraftBukkit start - handle canceled status of teleport event
+ java.util.Optional<Boolean> status = entity.randomTeleport(d, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
+
+ // teleport event was canceled, no more tries
+ if (!status.isPresent()) break;
+ if (status.get()) {
+ // CraftBukkit end
level.gameEvent(GameEvent.TELEPORT, vec3, GameEvent.Context.of(entity));
SoundSource soundSource;
SoundEvent soundEvent;

View file

@ -1,32 +0,0 @@
--- a/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
@@ -12,6 +12,9 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
public record ApplyStatusEffectsConsumeEffect(List<MobEffectInstance> effects, float probability) implements ConsumeEffect {
@@ -38,8 +41,8 @@
}
@Override
- public boolean apply(Level world, ItemStack stack, LivingEntity user) {
- if (user.getRandom().nextFloat() >= this.probability) {
+ public boolean apply(Level world, ItemStack itemstack, LivingEntity entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit
+ if (entityliving.getRandom().nextFloat() >= this.probability) {
return false;
} else {
boolean flag = false;
@@ -48,7 +51,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
- if (user.addEffect(new MobEffectInstance(mobeffect))) {
+ if (entityliving.addEffect(new MobEffectInstance(mobeffect), cause)) { // CraftBukkit
flag = true;
}
}

View file

@ -1,24 +0,0 @@
--- a/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
@@ -6,6 +6,9 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
public record ClearAllStatusEffectsConsumeEffect() implements ConsumeEffect {
@@ -19,7 +22,9 @@
}
@Override
- public boolean apply(Level world, ItemStack stack, LivingEntity user) {
- return user.removeAllEffects();
+ // CraftBukkit start
+ public boolean apply(Level world, ItemStack itemstack, LivingEntity entityliving, EntityPotionEffectEvent.Cause cause) {
+ return entityliving.removeAllEffects(cause);
+ // CraftBukkit end
}
}

View file

@ -1,30 +0,0 @@
--- a/net/minecraft/world/item/consume_effects/ConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/ConsumeEffect.java
@@ -11,6 +11,9 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
public interface ConsumeEffect {
@@ -19,8 +22,16 @@
ConsumeEffect.Type<? extends ConsumeEffect> getType();
- boolean apply(Level world, ItemStack stack, LivingEntity user);
+ // CraftBukkit start
+ default boolean apply(Level world, ItemStack stack, LivingEntity user) {
+ return this.apply(world, stack, user, EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+ default boolean apply(Level world, ItemStack itemstack, LivingEntity entityliving, EntityPotionEffectEvent.Cause cause) {
+ return this.apply(world, itemstack, entityliving);
+ }
+ // CraftBukkit end
+
public static record Type<T extends ConsumeEffect>(MapCodec<T> codec, StreamCodec<RegistryFriendlyByteBuf, T> streamCodec) {
public static final ConsumeEffect.Type<ApplyStatusEffectsConsumeEffect> APPLY_EFFECTS = register("apply_effects", ApplyStatusEffectsConsumeEffect.CODEC, ApplyStatusEffectsConsumeEffect.STREAM_CODEC);

View file

@ -1,29 +0,0 @@
--- a/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
@@ -14,6 +14,9 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+// CraftBukkit end
public record RemoveStatusEffectsConsumeEffect(HolderSet<MobEffect> effects) implements ConsumeEffect {
@@ -32,14 +35,14 @@
}
@Override
- public boolean apply(Level world, ItemStack stack, LivingEntity user) {
+ public boolean apply(Level world, ItemStack itemstack, LivingEntity entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit
boolean flag = false;
Iterator iterator = this.effects.iterator();
while (iterator.hasNext()) {
Holder<MobEffect> holder = (Holder) iterator.next();
- if (user.removeEffect(holder)) {
+ if (entityliving.removeEffect(holder, cause)) { // CraftBukkit
flag = true;
}
}

View file

@ -1,20 +0,0 @@
--- a/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
+++ b/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
@@ -53,7 +53,16 @@
Vec3 vec3d = user.position();
- if (user.randomTeleport(d0, d1, d2, true)) {
+ // CraftBukkit start - handle canceled status of teleport event
+ java.util.Optional<Boolean> status = user.randomTeleport(d0, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
+
+ if (!status.isPresent()) {
+ // teleport event was canceled, no more tries
+ break;
+ }
+
+ if (status.get()) {
+ // CraftBukkit end
world.gameEvent((Holder) GameEvent.TELEPORT, vec3d, GameEvent.Context.of((Entity) user));
SoundEvent soundeffect;
SoundSource soundcategory;