Scissors/patches/server/0023-Add-MasterBlockFireEvent.patch
2024-04-16 00:08:13 -05:00

160 lines
7.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Sun, 10 Dec 2023 18:11:55 -0600
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 7ef14e4441a329c680a5dfe4bfb5033ffcb8f9d5..eff5bdf00b0aa7a9925ff59a62ead72509dc67b8 100644
--- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
@@ -4,6 +4,7 @@ import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
@@ -28,6 +29,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
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;
import org.slf4j.Logger;
import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
@@ -130,6 +132,14 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
}
private void execute(BlockState state, Level world, BlockPos pos, BaseCommandBlock executor, boolean hasCommand) {
+ // Scissors start - Add master block fire event
+ 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 447b0359922011fe12b1bb9628d23a47c9d7dc89..0d6be671e1512074ae1265fe93a5d5437f3929dd 100644
--- 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,8 @@ package net.minecraft.world.level.block.entity;
import java.util.Arrays;
import java.util.Optional;
+
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
@@ -17,6 +19,7 @@ import net.minecraft.world.level.block.JigsawBlock;
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;
public class JigsawBlockEntity extends BlockEntity {
public static final String TARGET = "target";
@@ -134,6 +137,16 @@ public class JigsawBlockEntity extends BlockEntity {
}
public void generate(ServerLevel world, int maxDepth, boolean keepJigsaws) {
+ // Scissors start - Add master block fire event
+ 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());
Registry<StructureTemplatePool> registry = world.registryAccess().registryOrThrow(Registries.TEMPLATE_POOL);
// Paper start - Replace getHolderOrThrow with a null check
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
index 29c59e4a1283ac211b18b953ed6c03834a2587bd..fb385cd66226200ed0b8439cb6659dbac6c2b229 100644
--- 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,8 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+
+import me.totalfreedom.scissors.event.block.MasterBlockFireEvent;
import net.minecraft.ResourceLocationException;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
@@ -29,6 +31,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProce
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;
public class StructureBlockEntity extends BlockEntity {
private static final int SCAN_CORNER_BLOCKS_RANGE = 5;
@@ -259,7 +262,7 @@ public class StructureBlockEntity extends BlockEntity {
return false;
} else {
BlockPos blockPos = this.getBlockPos();
- int i = 80;
+ // Scissors - Obfuscation fixes
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);
@@ -316,6 +319,16 @@ public class StructureBlockEntity extends BlockEntity {
if (this.structureName == null) {
return false;
} else {
+ // Scissors start - Add master block fire event
+ 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();
@@ -367,6 +380,16 @@ public class StructureBlockEntity extends BlockEntity {
if (structureTemplate == null) {
return false;
} else {
+ // Scissors start - Add master block fire event
+ 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
+
this.loadStructureInfo(structureTemplate);
return true;
}
@@ -407,6 +430,15 @@ public class StructureBlockEntity extends BlockEntity {
}
public void unloadStructure() {
+ // Scissors start - Add master block fire event
+ 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();