mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 00:49:31 +00:00
* Fix terminal color on Windows Windows doesn't have environment variables TERM and COLORTERM by default, but we assuming that it supports the `truecolor` for terminal. * Add back revert to original java console on Java 22
101 lines
6.0 KiB
Diff
101 lines
6.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Warrior <50800980+Warriorrrr@users.noreply.github.com>
|
|
Date: Thu, 31 Aug 2023 10:23:06 +0200
|
|
Subject: [PATCH] PaperPR: Fix some beacon event issues
|
|
|
|
Original license: GPLv3
|
|
Original project: https://github.com/PaperMC/Paper
|
|
Paper pull request: https://github.com/PaperMC/Paper/pull/9674
|
|
|
|
Closes Paper#8947
|
|
|
|
Moves the deactivate event call into the onRemove method for the beacon block itself to prevent it from running when the block entity is unloaded. Also fixes an issue where the events were not being called when the beacon beam gets blocked.
|
|
|
|
The field I added feels a bit wrong but it works, it's to prevent the activation event being called immediately after loading, can't see any better way to differentiate between a newly placed beacon and a newly loaded one.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/BeaconBlock.java b/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
|
|
index 56793f1ce1a4b919b5066966abf1768bf64540c8..d93756eadfef8ae260ba4f8253775aa4aa92c0d3 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
|
|
@@ -61,4 +61,16 @@ public class BeaconBlock extends BaseEntityBlock implements BeaconBeamBlock {
|
|
protected RenderShape getRenderShape(BlockState state) {
|
|
return RenderShape.MODEL;
|
|
}
|
|
+
|
|
+ // Paper start - BeaconDeactivatedEvent
|
|
+ @Override
|
|
+ public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) {
|
|
+ if (!state.is(newState.getBlock()) && world.getBlockEntity(pos) instanceof BeaconBlockEntity beacon && beacon.levels > 0 && !beacon.getBeamSections().isEmpty()) {
|
|
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
|
|
+ new io.papermc.paper.event.block.BeaconDeactivatedEvent(block).callEvent();
|
|
+ }
|
|
+
|
|
+ super.onRemove(state, world, pos, newState, moved);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
index df02a78855f1d0c32d1f744c20803fc97a8085c0..fa7f74811755186417508dc1bbb523c833060168 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
@@ -122,6 +122,8 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
return BeaconBlockEntity.VALID_EFFECTS.contains(effect) ? effect : null;
|
|
}
|
|
|
|
+ public boolean justLoadedAndPreviouslyActive; // Paper - consider beacon previously active for first tick to skip activate event/sound
|
|
+
|
|
public BeaconBlockEntity(BlockPos pos, BlockState state) {
|
|
super(BlockEntityType.BEACON, pos, state);
|
|
this.lockKey = LockCode.NO_LOCK;
|
|
@@ -240,10 +242,15 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
}
|
|
}
|
|
// Paper start - beacon activation/deactivation events
|
|
- if (i1 <= 0 && blockEntity.levels > 0) {
|
|
+ // Paper start
|
|
+ final boolean prevActive = i1 > 0 && (!blockEntity.beamSections.isEmpty() || (blockEntity.justLoadedAndPreviouslyActive && !blockEntity.checkingBeamSections.isEmpty()));
|
|
+ blockEntity.justLoadedAndPreviouslyActive = false;
|
|
+ final boolean newActive = blockEntity.levels > 0 && !blockEntity.checkingBeamSections.isEmpty();
|
|
+ if (!prevActive && newActive) {
|
|
+ // Paper end
|
|
org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
|
|
new io.papermc.paper.event.block.BeaconActivatedEvent(block).callEvent();
|
|
- } else if (i1 > 0 && blockEntity.levels <= 0) {
|
|
+ } else if (prevActive && !newActive) { // Paper
|
|
org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
|
|
new io.papermc.paper.event.block.BeaconDeactivatedEvent(block).callEvent();
|
|
}
|
|
@@ -251,11 +258,11 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
|
|
if (blockEntity.lastCheckY >= l) {
|
|
blockEntity.lastCheckY = world.getMinBuildHeight() - 1;
|
|
- boolean flag = i1 > 0;
|
|
+ boolean flag = prevActive; // Paper - Fix MC-183981
|
|
|
|
blockEntity.beamSections = blockEntity.checkingBeamSections;
|
|
if (!world.isClientSide) {
|
|
- boolean flag1 = blockEntity.levels > 0;
|
|
+ boolean flag1 = newActive; // Paper - Fix MC-183981
|
|
|
|
if (!flag && flag1) {
|
|
BeaconBlockEntity.playSound(world, pos, SoundEvents.BEACON_ACTIVATE);
|
|
@@ -305,10 +312,6 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
|
|
@Override
|
|
public void setRemoved() {
|
|
- // Paper start - beacon activation/deactivation events
|
|
- org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(level, worldPosition);
|
|
- new io.papermc.paper.event.block.BeaconDeactivatedEvent(block).callEvent();
|
|
- // Paper end - beacon activation/deactivation events
|
|
// Paper start - fix MC-153086
|
|
if (this.levels > 0 && !this.beamSections.isEmpty()) {
|
|
BeaconBlockEntity.playSound(this.level, this.worldPosition, SoundEvents.BEACON_DEACTIVATE);
|
|
@@ -466,6 +469,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
this.primaryPower = BeaconBlockEntity.loadEffect(nbt, "primary_effect");
|
|
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");
|
|
this.levels = nbt.getInt("Levels"); // CraftBukkit - SPIGOT-5053, use where available
|
|
+ this.justLoadedAndPreviouslyActive = this.levels > 0; // Paper
|
|
if (nbt.contains("CustomName", 8)) {
|
|
this.name = parseCustomNameSafe(nbt.getString("CustomName"), registryLookup);
|
|
}
|