13
0
geforkt von Mirrors/Paper

#1160: Add more bell API

By: Parker Hawke <hawkeboyz2@hotmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2023-04-02 14:35:13 +10:00
Ursprung a9bdb77af1
Commit 496189d962
4 geänderte Dateien mit 127 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockBell.java
+++ b/net/minecraft/world/level/block/BlockBell.java
@@ -137,6 +137,11 @@
if (enumdirection == null) {
enumdirection = (EnumDirection) world.getBlockState(blockposition).getValue(BlockBell.FACING);
}
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBellRingEvent(world, blockposition, enumdirection, entity)) {
+ return false;
+ }
+ // CraftBukkit end
((TileEntityBell) tileentity).onHit(enumdirection);
world.playSound((EntityHuman) null, blockposition, SoundEffects.BELL_BLOCK, SoundCategory.BLOCKS, 2.0F, 1.0F);

Datei anzeigen

@ -0,0 +1,37 @@
--- a/net/minecraft/world/level/block/entity/TileEntityBell.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBell.java
@@ -35,8 +35,8 @@
public boolean shaking;
public EnumDirection clickDirection;
private List<EntityLiving> nearbyEntities;
- private boolean resonating;
- private int resonationTicks;
+ public boolean resonating;
+ public int resonationTicks;
public TileEntityBell(BlockPosition blockposition, IBlockData iblockdata) {
super(TileEntityTypes.BELL, blockposition, iblockdata);
@@ -120,7 +120,7 @@
EntityLiving entityliving = (EntityLiving) iterator.next();
if (entityliving.isAlive() && !entityliving.isRemoved() && blockposition.closerToCenterThan(entityliving.position(), 32.0D)) {
- entityliving.getBrain().setMemory(MemoryModuleType.HEARD_BELL_TIME, (Object) this.level.getGameTime());
+ entityliving.getBrain().setMemory(MemoryModuleType.HEARD_BELL_TIME, this.level.getGameTime()); // CraftBukkit - decompile error
}
}
}
@@ -144,9 +144,13 @@
}
private static void makeRaidersGlow(World world, BlockPosition blockposition, List<EntityLiving> list) {
+ List<org.bukkit.entity.LivingEntity> entities = // CraftBukkit
list.stream().filter((entityliving) -> {
return isRaiderWithinRange(blockposition, entityliving);
- }).forEach(TileEntityBell::glow);
+ }).map((entity) -> (org.bukkit.entity.LivingEntity) entity.getBukkitEntity()).collect(java.util.stream.Collectors.toCollection(java.util.ArrayList::new)); // CraftBukkit
+
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBellResonateEvent(world, blockposition, entities).forEach(TileEntityBell::glow);
+ // CraftBukkit end
}
private static void showBellParticles(World world, BlockPosition blockposition, List<EntityLiving> list) {

Datei anzeigen

@ -1,12 +1,70 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
import net.minecraft.core.EnumDirection;
import net.minecraft.world.level.block.BlockBell;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBell;
import org.bukkit.World;
import org.bukkit.block.Bell;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity;
public class CraftBell extends CraftBlockEntityState<TileEntityBell> implements Bell {
public CraftBell(World world, TileEntityBell tileEntity) {
super(world, tileEntity);
}
@Override
public boolean ring(Entity entity, BlockFace direction) {
Preconditions.checkArgument(direction == null || direction.isCartesian(), "direction must be cartesian, given %s", direction);
TileEntity tileEntity = getTileEntityFromWorld();
if (tileEntity == null) {
return false;
}
net.minecraft.world.entity.Entity nmsEntity = (entity != null) ? ((CraftEntity) entity).getHandle() : null;
EnumDirection enumDirection = CraftBlock.blockFaceToNotch(direction);
return ((BlockBell) Blocks.BELL).attemptToRing(nmsEntity, world.getHandle(), getPosition(), enumDirection);
}
@Override
public boolean ring(Entity entity) {
return ring(entity, null);
}
@Override
public boolean ring(BlockFace direction) {
return ring(null, direction);
}
@Override
public boolean ring() {
return ring(null, null);
}
@Override
public boolean isShaking() {
return getSnapshot().shaking;
}
@Override
public int getShakingTicks() {
return getSnapshot().ticks;
}
@Override
public boolean isResonating() {
return getSnapshot().resonating;
}
@Override
public int getResonatingTicks() {
return isResonating() ? getSnapshot().ticks : 0;
}
}

Datei anzeigen

@ -11,12 +11,12 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
import net.minecraft.network.protocol.game.PacketPlayInCloseWindow;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.tags.DamageTypeTags;
@ -24,7 +24,6 @@ import net.minecraft.util.Unit;
import net.minecraft.world.EnumHand;
import net.minecraft.world.IInventory;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.Entity;
@ -131,6 +130,8 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BellResonateEvent;
import org.bukkit.event.block.BellRingEvent;
import org.bukkit.event.block.BlockDamageAbortEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDropItemEvent;
@ -340,6 +341,21 @@ public class CraftEventFactory {
return tradeSelectEvent;
}
public static boolean handleBellRingEvent(World world, BlockPosition position, EnumDirection direction, Entity entity) {
Block block = CraftBlock.at(world, position);
BlockFace bukkitDirection = CraftBlock.notchToBlockFace(direction);
BellRingEvent event = new BellRingEvent(block, bukkitDirection, (entity != null) ? entity.getBukkitEntity() : null);
Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled();
}
public static Stream<EntityLiving> handleBellResonateEvent(World world, BlockPosition position, List<LivingEntity> bukkitEntities) {
Block block = CraftBlock.at(world, position);
BellResonateEvent event = new BellResonateEvent(block, bukkitEntities);
Bukkit.getPluginManager().callEvent(event);
return event.getResonatedEntities().stream().map((bukkitEntity) -> ((CraftLivingEntity) bukkitEntity).getHandle());
}
/**
* Block place methods
*/