copy spawner data exactly when silk touching

This commit is contained in:
granny
2024-01-09 05:36:54 -08:00
parent d05e78bdb1
commit 544a2b6a4e

View File

@@ -18,10 +18,10 @@ index f692149d91b525bda6dc79d489d7496ea24037e8..7fbd4bf29bcc0795aa4b0e6d5d4bc374
public static final Item CRAFTING_TABLE = registerBlock(Blocks.CRAFTING_TABLE);
public static final Item FARMLAND = registerBlock(Blocks.FARMLAND);
diff --git a/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java b/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
index e8b1c44da90f60cde20cda65aba2aa1e30f89d25..c55576424993236da46ed1c2ccd03b72d7ee97f9 100644
index e8b1c44da90f60cde20cda65aba2aa1e30f89d25..1ac38424a44aa2225b9bd3fa0fbbe61b7b24875c 100644
--- a/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
@@ -42,6 +42,58 @@ public class SpawnerBlock extends BaseEntityBlock {
@@ -42,6 +42,60 @@ public class SpawnerBlock extends BaseEntityBlock {
return createTickerHelper(type, BlockEntityType.MOB_SPAWNER, world.isClientSide ? SpawnerBlockEntity::clientTick : SpawnerBlockEntity::serverTick);
}
@@ -35,6 +35,9 @@ index e8b1c44da90f60cde20cda65aba2aa1e30f89d25..c55576424993236da46ed1c2ccd03b72
+ final net.kyori.adventure.text.Component mobName = io.papermc.paper.adventure.PaperAdventure.asAdventure(entityType == null ? Component.empty() : entityType.getDescription());
+ net.minecraft.nbt.CompoundTag display = new net.minecraft.nbt.CompoundTag();
+ net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
+ net.minecraft.nbt.CompoundTag blockEntityTag = blockEntity.getUpdateTag();
+ blockEntityTag.remove("Delay"); // remove this tag to allow stacking duplicate spawners
+ tag.put("BlockEntityTag", blockEntityTag);
+
+ String name = level.purpurConfig.silkTouchSpawnerName;
+ if (name != null && !name.isEmpty() && !name.equals("Monster Spawner")) {
@@ -62,7 +65,6 @@ index e8b1c44da90f60cde20cda65aba2aa1e30f89d25..c55576424993236da46ed1c2ccd03b72
+
+ ItemStack item = new ItemStack(Blocks.SPAWNER.asItem());
+ if (entityType != null) {
+ tag.putString("Purpur.mob_type", entityType.getName());
+ tag.putDouble("HideFlags", ItemStack.TooltipPart.ADDITIONAL.getMask()); // hides the "Interact with Spawn Egg" tooltip
+ item.setTag(tag);
+ }
@@ -80,7 +82,7 @@ index e8b1c44da90f60cde20cda65aba2aa1e30f89d25..c55576424993236da46ed1c2ccd03b72
@Override
public void spawnAfterBreak(BlockState state, ServerLevel world, BlockPos pos, ItemStack tool, boolean dropExperience) {
super.spawnAfterBreak(state, world, pos, tool, dropExperience);
@@ -50,6 +102,7 @@ public class SpawnerBlock extends BaseEntityBlock {
@@ -50,6 +104,7 @@ public class SpawnerBlock extends BaseEntityBlock {
@Override
public int getExpDrop(BlockState iblockdata, ServerLevel worldserver, BlockPos blockposition, ItemStack itemstack, boolean flag) {
@@ -133,10 +135,10 @@ index 70f53ccb22de2c05c9ead68f8bd29d0b69d0993f..d4bca5b5f3d10c3a04befd8c365f4643
public boolean useNightVisionWhenRiding = false;
diff --git a/src/main/java/org/purpurmc/purpur/item/SpawnerItem.java b/src/main/java/org/purpurmc/purpur/item/SpawnerItem.java
new file mode 100644
index 0000000000000000000000000000000000000000..c038fb2bbb0f0e78380bc24bbd6348b869669a90
index 0000000000000000000000000000000000000000..d6cc7e434cb2bacc00e4cad9e1f4be7fcf5d0bee
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/item/SpawnerItem.java
@@ -0,0 +1,36 @@
@@ -0,0 +1,38 @@
+package org.purpurmc.purpur.item;
+
+import net.minecraft.core.BlockPos;
@@ -167,6 +169,8 @@ index 0000000000000000000000000000000000000000..c038fb2bbb0f0e78380bc24bbd6348b8
+ if (tag.contains("Purpur.mob_type")) {
+ EntityType.byString(tag.getString("Purpur.mob_type")).ifPresent(type ->
+ ((SpawnerBlockEntity) spawner).getSpawner().setEntityId(type, level, level.random, pos));
+ } else if (tag.contains("BlockEntityTag")) {
+ spawner.load(tag.getCompound("BlockEntityTag"));
+ }
+ }
+ }