Update silk touch patch to use minimessage

This commit is contained in:
William Blake Galbreath
2021-09-02 15:17:12 -05:00
parent 8c2e417757
commit c28262576c
174 changed files with 656 additions and 599 deletions

View File

@@ -30,12 +30,15 @@ index f68639508d7ff9a0e743b5282301e62435d53656..89d4b7e4cd4222b61b49833fceda56ff
public static final Item CHEST = registerBlock(Blocks.CHEST, CreativeModeTab.TAB_DECORATIONS);
public static final Item CRAFTING_TABLE = registerBlock(Blocks.CRAFTING_TABLE, CreativeModeTab.TAB_DECORATIONS);
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 b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63cf3b84ab 100644
index b1e04d41de80971a7a1616beb0860226ecc25045..a499cf626a54fcef62bc34bba4193ba0565d8379 100644
--- a/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
@@ -2,8 +2,16 @@ package net.minecraft.world.level.block;
@@ -1,9 +1,19 @@
package net.minecraft.world.level.block;
import javax.annotation.Nullable;
+
+import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
@@ -50,7 +53,7 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -13,6 +21,18 @@ import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
@@ -13,6 +23,19 @@ import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
@@ -62,6 +65,7 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+
+import java.util.List;
+import java.util.Locale;
+
+import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
+// Purpur end
@@ -69,7 +73,7 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
public class SpawnerBlock extends BaseEntityBlock {
protected SpawnerBlock(BlockBehaviour.Properties settings) {
@@ -30,6 +50,59 @@ public class SpawnerBlock extends BaseEntityBlock {
@@ -30,6 +53,55 @@ public class SpawnerBlock extends BaseEntityBlock {
return createTickerHelper(type, BlockEntityType.MOB_SPAWNER, world.isClientSide ? SpawnerBlockEntity::clientTick : SpawnerBlockEntity::serverTick);
}
@@ -80,39 +84,35 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
+ ResourceLocation type = ((SpawnerBlockEntity) blockEntity).getSpawner().getEntityId(level, pos);
+ if (type != null) {
+ final Component mobName = PaperAdventure.asAdventure(EntityType.getFromKey(type).getDescription());
+ final TextReplacementConfig config = TextReplacementConfig.builder()
+ .matchLiteral("{mob}")
+ .replacement(mobName)
+ .build();
+
+ CompoundTag display = new CompoundTag();
+ boolean customDisplay = false;
+ CompoundTag tag = new CompoundTag();
+
+ String name = level.purpurConfig.silkTouchSpawnerName;
+ if (name != null && !name.isEmpty() && !name.equals("Spawner")) {
+ final Component displayName = PaperAdventure.LEGACY_AMPERSAND.deserialize(name).replaceText(config).decoration(ITALIC, false);
+ display.put("Name", StringTag.valueOf(GsonComponentSerializer.gson().serialize(displayName)));
+ customDisplay = true;
+ Component displayName = MiniMessage.get().parse(name, "mob", mobName);
+ if (name.startsWith("<reset>")) {
+ displayName = displayName.decoration(ITALIC, false);
+ }
+ display.put("Name", StringTag.valueOf(PaperAdventure.asJsonString(displayName, Locale.ROOT)));
+ tag.put("display", display);
+ }
+
+ List<String> lore = level.purpurConfig.silkTouchSpawnerLore;
+ if (lore != null && !lore.isEmpty()) {
+ ListTag list = new ListTag();
+ for (String line : lore) {
+ final Component lineComponent = PaperAdventure.LEGACY_AMPERSAND.deserialize(line).replaceText(config).decoration(ITALIC, false);
+ list.add(StringTag.valueOf(GsonComponentSerializer.gson().serialize(lineComponent)));
+ Component lineComponent = MiniMessage.get().parse(line, "mob", mobName);
+ if (line.startsWith("<reset>")) {
+ lineComponent = lineComponent.decoration(ITALIC, false);
+ }
+ list.add(StringTag.valueOf(PaperAdventure.asJsonString(lineComponent, Locale.ROOT)));
+ }
+ display.put("Lore", list);
+ customDisplay = true;
+ }
+
+ CompoundTag tag = new CompoundTag();
+ if (customDisplay) {
+ tag.put("display", display);
+ }
+ tag.putString("Purpur.mob_type", type.toString());
+
+ ItemStack item = new ItemStack(Blocks.SPAWNER.asItem());
+ tag.putString("Purpur.mob_type", type.toString());
+ item.setTag(tag);
+
+ popResource(level, pos, item);
@@ -129,7 +129,7 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
@Override
public void spawnAfterBreak(BlockState state, ServerLevel world, BlockPos pos, ItemStack stack) {
super.spawnAfterBreak(state, world, pos, stack);
@@ -42,6 +115,7 @@ public class SpawnerBlock extends BaseEntityBlock {
@@ -42,6 +114,7 @@ public class SpawnerBlock extends BaseEntityBlock {
@Override
public int getExpDrop(BlockState iblockdata, ServerLevel worldserver, BlockPos blockposition, ItemStack itemstack) {
@@ -138,33 +138,40 @@ index b1e04d41de80971a7a1616beb0860226ecc25045..295ae3877b955978105b756055c21e63
return i;
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index a4abc312a9c173fb6a4374c97012abc43c801b7a..48670fd7e51c39e207d95059261c09d52f309db6 100644
index 6df320ab8214669517d5de30a28f044a5a6b4a33..8920b47610a323ceb6b19a05b7592d8acf809bc4 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -115,6 +115,31 @@ public class PurpurWorldConfig {
@@ -116,6 +116,38 @@ public class PurpurWorldConfig {
playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
}
+ public boolean silkTouchEnabled = false;
+ public String silkTouchSpawnerName = "Spawner";
+ public String silkTouchSpawnerName = "<reset><white>Spawner";
+ public List<String> silkTouchSpawnerLore = new ArrayList<>();
+ public List<Item> silkTouchTools = new ArrayList<>();
+ public int minimumSilkTouchSpawnerRequire = 1;
+ private void silkTouchSettings() {
+ if (PurpurConfig.version < 21) {
+ String oldName = getString("gameplay-mechanics.silk-touch.spawner-name", silkTouchSpawnerName);
+ set("gameplay-mechanics.silk-touch.spawner-name", "<reset>" + ChatColor.toMM(oldName.replace("{mob}", "<mob>")));
+ List<String> list = new ArrayList<>();
+ getList("gameplay-mechanics.silk-touch.spawner-lore", List.of("Spawns a <mob>"))
+ .forEach(line -> list.add("<reset>" + ChatColor.toMM(line.toString().replace("{mob}", "<mob>"))));
+ set("gameplay-mechanics.silk-touch.spawner-lore", list);
+ }
+ silkTouchEnabled = getBoolean("gameplay-mechanics.silk-touch.enabled", silkTouchEnabled);
+ silkTouchSpawnerName = getString("gameplay-mechanics.silk-touch.spawner-name", silkTouchSpawnerName);
+ minimumSilkTouchSpawnerRequire = getInt("gameplay-mechanics.silk-touch.minimal-level", minimumSilkTouchSpawnerRequire);
+ silkTouchSpawnerLore.clear();
+ getList("gameplay-mechanics.silk-touch.spawner-lore", new ArrayList<String>(){{
+ add("Spawns a {mob}");
+ }}).forEach(line -> silkTouchSpawnerLore.add(line.toString()));
+ getList("gameplay-mechanics.silk-touch.spawner-lore", List.of("Spawns a <mob>"))
+ .forEach(line -> silkTouchSpawnerLore.add(line.toString()));
+ silkTouchTools.clear();
+ getList("gameplay-mechanics.silk-touch.tools", new ArrayList<String>(){{
+ add("minecraft:iron_pickaxe");
+ add("minecraft:golden_pickaxe");
+ add("minecraft:diamond_pickaxe");
+ add("minecraft:netherite_pickaxe");
+ }}).forEach(key -> {
+ getList("gameplay-mechanics.silk-touch.tools", List.of(
+ "minecraft:iron_pickaxe",
+ "minecraft:golden_pickaxe",
+ "minecraft:diamond_pickaxe",
+ "minecraft:netherite_pickaxe"
+ )).forEach(key -> {
+ Item item = Registry.ITEM.get(new ResourceLocation(key.toString()));
+ if (item != Items.AIR) silkTouchTools.add(item);
+ });