Scissors/patches/server/0023-Add-MasterBlockFireEvent.patch

159 lines
8.0 KiB
Diff
Raw Normal View History

2022-07-28 03:57:50 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Mon, 4 Jul 2022 22:12:19 +0100
Subject: [PATCH] Add MasterBlockFireEvent
diff --git a/src/main/java/net/minecraft/world/level/block/CommandBlock.java b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
index 2e7c03b00bc941b86df6a7f1b2b188c9f0aede22..0ae03d3934ad7b2b38afa45a65c7753dcbe796d2 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
@@ -1,5 +1,6 @@
package net.minecraft.world.level.block;
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent; // Scissors
2022-07-28 03:57:50 +00:00
import com.mojang.logging.LogUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@@ -25,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
2022-07-28 03:57:50 +00:00
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
+import org.bukkit.Location; // Scissors
2022-07-28 03:57:50 +00:00
import org.slf4j.Logger;
import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
@@ -117,6 +119,15 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
2022-07-28 03:57:50 +00:00
}
private void execute(BlockState state, Level world, BlockPos pos, BaseCommandBlock executor, boolean hasCommand) {
+ // Scissors start - Add master block fire event
2022-07-28 03:57:50 +00:00
+ final MasterBlockFireEvent event = new MasterBlockFireEvent(new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+
+ if (!event.callEvent())
+ {
+ return;
+ }
+ // Scissors end
+
if (hasCommand) {
executor.performCommand(world);
} else {
diff --git a/src/main/java/net/minecraft/world/level/block/entity/JigsawBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/JigsawBlockEntity.java
index 182e16c1d968707a11329150d71b7d01df6c6e52..8582a9369cffe0eebeb82a81fc413d0bf4ad28ed 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/world/level/block/entity/JigsawBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/JigsawBlockEntity.java
@@ -2,6 +2,7 @@ package net.minecraft.world.level.block.entity;
2022-07-28 03:57:50 +00:00
import java.util.Arrays;
import java.util.Optional;
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent; // Scissors
2022-07-28 03:57:50 +00:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
@@ -17,6 +18,7 @@ import net.minecraft.world.level.block.JigsawBlock;
2022-07-28 03:57:50 +00:00
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.pools.JigsawPlacement;
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
+import org.bukkit.Location; // Scissors
2022-07-28 03:57:50 +00:00
public class JigsawBlockEntity extends BlockEntity {
public static final String TARGET = "target";
@@ -107,6 +109,16 @@ public class JigsawBlockEntity extends BlockEntity {
2022-07-28 03:57:50 +00:00
}
public void generate(ServerLevel world, int maxDepth, boolean keepJigsaws) {
+ // Scissors start - Add master block fire event
2022-07-28 03:57:50 +00:00
+ final BlockPos pos = this.getBlockPos();
+ final MasterBlockFireEvent event = new MasterBlockFireEvent(new Location(this.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+
+ if (!event.callEvent())
+ {
+ return;
+ }
+ // Scissors end
+
BlockPos blockPos = this.getBlockPos().relative(this.getBlockState().getValue(JigsawBlock.ORIENTATION).front());
2022-12-11 06:04:11 +00:00
Registry<StructureTemplatePool> registry = world.registryAccess().registryOrThrow(Registries.TEMPLATE_POOL);
2022-10-02 22:14:40 +00:00
// Paper start - Replace getHolderOrThrow with a null check
2022-07-28 03:57:50 +00:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/StructureBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/StructureBlockEntity.java
2023-09-24 21:42:28 +00:00
index e8ecced687261861953899a3bea162dbc03977b4..30720203173b23ccdbb0789f7e2adbbe180c7c69 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/world/level/block/entity/StructureBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/StructureBlockEntity.java
@@ -5,6 +5,7 @@ import java.util.Objects;
2022-07-28 03:57:50 +00:00
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent; // Scissors
2022-07-28 03:57:50 +00:00
import net.minecraft.ResourceLocationException;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
@@ -29,6 +30,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProce
2022-07-28 03:57:50 +00:00
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
+import org.bukkit.Location; // Scissors
2022-07-28 03:57:50 +00:00
public class StructureBlockEntity extends BlockEntity {
private static final int SCAN_CORNER_BLOCKS_RANGE = 5;
@@ -264,7 +266,7 @@ public class StructureBlockEntity extends BlockEntity {
2022-07-28 03:57:50 +00:00
return false;
} else {
BlockPos blockPos = this.getBlockPos();
- int i = 80;
+ // Scissors - Obfuscation fixes
2022-07-28 03:57:50 +00:00
BlockPos blockPos2 = new BlockPos(blockPos.getX() - 80, this.level.getMinBuildHeight(), blockPos.getZ() - 80);
BlockPos blockPos3 = new BlockPos(blockPos.getX() + 80, this.level.getMaxBuildHeight() - 1, blockPos.getZ() + 80);
Stream<BlockPos> stream = this.getRelatedCorners(blockPos2, blockPos3);
@@ -321,6 +323,16 @@ public class StructureBlockEntity extends BlockEntity {
2023-09-24 21:42:28 +00:00
public boolean saveStructure(boolean interactive) {
2022-07-28 03:57:50 +00:00
if (this.mode == StructureMode.SAVE && !this.level.isClientSide && this.structureName != null) {
+ // Scissors start - Add master block fire event
2022-07-28 03:57:50 +00:00
+ final BlockPos pos = this.getBlockPos();
+ final MasterBlockFireEvent event = new MasterBlockFireEvent(new Location(this.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+
+ if (!event.callEvent())
+ {
+ return false;
+ }
+ // Scissors end
+
BlockPos blockPos = this.getBlockPos().offset(this.structurePos);
ServerLevel serverLevel = (ServerLevel)this.level;
StructureTemplateManager structureTemplateManager = serverLevel.getStructureManager();
@@ -358,6 +370,16 @@ public class StructureBlockEntity extends BlockEntity {
2023-09-24 21:42:28 +00:00
public boolean loadStructure(ServerLevel world, boolean interactive) {
2022-07-28 03:57:50 +00:00
if (this.mode == StructureMode.LOAD && this.structureName != null) {
+ // Scissors start - Add master block fire event
2022-07-28 03:57:50 +00:00
+ final BlockPos blockPos = this.getBlockPos();
+ final MasterBlockFireEvent event = new MasterBlockFireEvent(new Location(this.getLevel().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ()));
+
+ if (!event.callEvent())
+ {
+ return false;
+ }
+ // Scissors end
+
StructureTemplateManager structureTemplateManager = world.getStructureManager();
Optional<StructureTemplate> optional;
@@ -403,6 +425,16 @@ public class StructureBlockEntity extends BlockEntity {
}
public void unloadStructure() {
+ // Scissors start - Add master block fire event
2022-07-28 03:57:50 +00:00
+ final BlockPos blockPos = this.getBlockPos();
+ final MasterBlockFireEvent event = new MasterBlockFireEvent(new Location(this.getLevel().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ()));
+
+ if (!event.callEvent())
+ {
+ return;
+ }
+ // Scissors end
+
if (this.structureName != null) {
ServerLevel serverLevel = (ServerLevel)this.level;
StructureTemplateManager structureTemplateManager = serverLevel.getStructureManager();