Scissors/patches/server/0035-Add-MasterBlockFireEvent.patch
2022-07-04 22:26:04 +01:00

199 lines
9.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Mon, 4 Jul 2022 17:02:52 +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 fd73e9100feac8c7bf9a5fee21a0ab2d502dc3e0..4912d24683f5094b0b93798c3ad378516eed4746 100644
--- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
@@ -1,6 +1,6 @@
package net.minecraft.world.level.block;
-import java.util.Random;
+import com.github.atlasmediagroup.scissors.event.block.MasterBlockFireEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
@@ -25,8 +25,10 @@ import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.Location;
+import org.bukkit.event.block.BlockRedstoneEvent;
-import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+import java.util.Random;
public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
@@ -116,6 +118,15 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
}
private void execute(BlockState state, Level world, BlockPos pos, BaseCommandBlock executor, boolean hasCommand) {
+ // Scissors - 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/StructureBlock.java b/src/main/java/net/minecraft/world/level/block/StructureBlock.java
index 4142687c6bb08ac8a156fcaee39ce26308924615..fd9b338117f5cb4575b60bb5bc5664c548132265 100644
--- a/src/main/java/net/minecraft/world/level/block/StructureBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/StructureBlock.java
@@ -1,6 +1,8 @@
package net.minecraft.world.level.block;
import javax.annotation.Nullable;
+
+import com.github.atlasmediagroup.scissors.event.block.MasterBlockFireEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
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 c391db3b6cbe3140a92aec44fb52e90455209217..c93d21142c5f7b2799eeac7a8314ffdb7360162e 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
@@ -1,5 +1,6 @@
package net.minecraft.world.level.block.entity;
+import com.github.atlasmediagroup.scissors.event.block.MasterBlockFireEvent;
import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.List;
@@ -28,6 +29,7 @@ import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
+import org.bukkit.Location;
public class JigsawBlockEntity extends BlockEntity {
public static final String TARGET = "target";
@@ -120,11 +122,21 @@ public class JigsawBlockEntity extends BlockEntity {
}
public void generate(ServerLevel world, int maxDepth, boolean keepJigsaws) {
+ // Scissors - 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
+
ChunkGenerator chunkGenerator = world.getChunkSource().getGenerator();
StructureManager structureManager = world.getStructureManager();
StructureFeatureManager structureFeatureManager = world.structureFeatureManager();
Random random = world.getRandom();
- BlockPos blockPos = this.getBlockPos();
+ // BlockPos blockPos = this.getBlockPos(); // Scissors - We've already defined this in the scope
List<PoolElementStructurePiece> list = Lists.newArrayList();
StructureTemplate structureTemplate = new StructureTemplate();
structureTemplate.fillFromWorld(world, blockPos, new Vec3i(1, 1, 1), false, (Block)null);
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 a9b186e5a60838443d2ad2ee82ed3f4803a4899a..9134c8fc0b9363eadf6da288029b7a33c6d5d405 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
@@ -6,6 +6,8 @@ import java.util.Optional;
import java.util.Random;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+
+import com.github.atlasmediagroup.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.StructureManager;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
+import org.bukkit.Location;
public class StructureBlockEntity extends BlockEntity {
private static final int SCAN_CORNER_BLOCKS_RANGE = 5;
@@ -266,7 +269,6 @@ public class StructureBlockEntity extends BlockEntity {
return false;
} else {
BlockPos blockPos = this.getBlockPos();
- int i = 80;
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);
@@ -323,6 +325,16 @@ public class StructureBlockEntity extends BlockEntity {
public boolean saveStructure(boolean bl) {
if (this.mode == StructureMode.SAVE && !this.level.isClientSide && this.structureName != null) {
+ // Scissors - 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;
StructureManager structureManager = serverLevel.getStructureManager();
@@ -360,6 +372,16 @@ public class StructureBlockEntity extends BlockEntity {
public boolean loadStructure(ServerLevel world, boolean bl) {
if (this.mode == StructureMode.LOAD && this.structureName != null) {
+ // Scissors - 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
+
StructureManager structureManager = world.getStructureManager();
Optional<StructureTemplate> optional;
@@ -376,7 +398,16 @@ public class StructureBlockEntity extends BlockEntity {
}
public boolean loadStructure(ServerLevel world, boolean bl, StructureTemplate structureTemplate) {
- BlockPos blockPos = this.getBlockPos();
+ // Scissors - 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
+
if (!StringUtil.isNullOrEmpty(structureTemplate.getAuthor())) {
this.author = structureTemplate.getAuthor();
}
@@ -405,6 +436,16 @@ public class StructureBlockEntity extends BlockEntity {
}
public void unloadStructure() {
+ // Scissors - 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;
StructureManager structureManager = serverLevel.getStructureManager();