#1248: Load GameEvent and MusicInstrument from registry
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
--- a/net/minecraft/world/level/gameevent/GameEventDispatcher.java
|
||||
+++ b/net/minecraft/world/level/gameevent/GameEventDispatcher.java
|
||||
@@ -11,6 +11,14 @@
|
||||
@@ -11,6 +11,13 @@
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.core.registries.BuiltInRegistries;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.craftbukkit.CraftGameEvent;
|
||||
+import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
+import org.bukkit.event.world.GenericGameEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class GameEventDispatcher {
|
||||
|
||||
private final WorldServer level;
|
||||
@@ -22,6 +30,14 @@
|
||||
@@ -22,6 +29,14 @@
|
||||
public void post(GameEvent gameevent, Vec3D vec3d, GameEvent.a gameevent_a) {
|
||||
int i = gameevent.getNotificationRadius();
|
||||
BlockPosition blockposition = BlockPosition.containing(vec3d);
|
||||
+ // CraftBukkit start
|
||||
+ GenericGameEvent event = new GenericGameEvent(org.bukkit.GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(gameevent))), CraftLocation.toBukkit(blockposition, level.getWorld()), (gameevent_a.sourceEntity() == null) ? null : gameevent_a.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread());
|
||||
+ GenericGameEvent event = new GenericGameEvent(CraftGameEvent.minecraftToBukkit(gameevent), CraftLocation.toBukkit(blockposition, level.getWorld()), (gameevent_a.sourceEntity() == null) ? null : gameevent_a.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread());
|
||||
+ level.getCraftServer().getPluginManager().callEvent(event);
|
||||
+ if (event.isCancelled()) {
|
||||
+ return;
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
--- a/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
|
||||
+++ b/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
|
||||
@@ -29,6 +29,13 @@
|
||||
@@ -29,6 +29,12 @@
|
||||
import net.minecraft.world.phys.MovingObjectPosition;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.core.registries.BuiltInRegistries;
|
||||
+import org.bukkit.craftbukkit.CraftGameEvent;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
+import org.bukkit.event.block.BlockReceiveGameEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public interface VibrationSystem {
|
||||
|
||||
GameEvent[] RESONANCE_EVENTS = new GameEvent[]{GameEvent.RESONATE_1, GameEvent.RESONATE_2, GameEvent.RESONATE_3, GameEvent.RESONATE_4, GameEvent.RESONATE_5, GameEvent.RESONATE_6, GameEvent.RESONATE_7, GameEvent.RESONATE_8, GameEvent.RESONATE_9, GameEvent.RESONATE_10, GameEvent.RESONATE_11, GameEvent.RESONATE_12, GameEvent.RESONATE_13, GameEvent.RESONATE_14, GameEvent.RESONATE_15};
|
||||
@@ -228,7 +235,8 @@
|
||||
@@ -228,7 +234,8 @@
|
||||
if (vibrationsystem_d.requiresAdjacentChunksToBeTicking() && !areAdjacentChunksTicking(worldserver, blockposition1)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -24,7 +23,7 @@
|
||||
vibrationsystem_a.setCurrentVibration((VibrationInfo) null);
|
||||
return true;
|
||||
}
|
||||
@@ -285,8 +293,14 @@
|
||||
@@ -285,8 +292,14 @@
|
||||
return false;
|
||||
} else {
|
||||
Vec3D vec3d1 = (Vec3D) optional.get();
|
||||
@@ -33,7 +32,7 @@
|
||||
+ // CraftBukkit start
|
||||
+ boolean defaultCancel = !vibrationsystem_d.canReceiveVibration(worldserver, BlockPosition.containing(vec3d), gameevent, gameevent_a);
|
||||
+ Entity entity = gameevent_a.sourceEntity();
|
||||
+ BlockReceiveGameEvent event = new BlockReceiveGameEvent(org.bukkit.GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(gameevent))), CraftBlock.at(worldserver, BlockPosition.containing(vec3d1)), (entity == null) ? null : entity.getBukkitEntity());
|
||||
+ BlockReceiveGameEvent event = new BlockReceiveGameEvent(CraftGameEvent.minecraftToBukkit(gameevent), CraftBlock.at(worldserver, BlockPosition.containing(vec3d1)), (entity == null) ? null : entity.getBukkitEntity());
|
||||
+ event.setCancelled(defaultCancel);
|
||||
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
|
||||
+ if (event.isCancelled()) {
|
||||
@@ -41,7 +40,7 @@
|
||||
return false;
|
||||
} else if (isOccluded(worldserver, vec3d, vec3d1)) {
|
||||
return false;
|
||||
@@ -339,7 +353,7 @@
|
||||
@@ -339,7 +352,7 @@
|
||||
return instance.group(VibrationInfo.CODEC.optionalFieldOf("event").forGetter((vibrationsystem_a) -> {
|
||||
return Optional.ofNullable(vibrationsystem_a.currentVibration);
|
||||
}), VibrationSelector.CODEC.fieldOf("selector").forGetter(VibrationSystem.a::getSelectionStrategy), ExtraCodecs.NON_NEGATIVE_INT.fieldOf("event_delay").orElse(0).forGetter(VibrationSystem.a::getTravelTimeInTicks)).apply(instance, (optional, vibrationselector, integer) -> {
|
||||
|
||||
Reference in New Issue
Block a user