mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 01:17:42 +01:00
move SpawnerItem out of NMS
This commit is contained in:
@@ -17,7 +17,7 @@ index d24c569f00786b2bde953429aad57025abee72d6..44d837f624e2a23b0412cca4c0646f48
|
||||
public static final GsonComponentSerializer GSON = GsonComponentSerializer.builder()
|
||||
.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
|
||||
diff --git a/src/main/java/net/minecraft/world/item/Items.java b/src/main/java/net/minecraft/world/item/Items.java
|
||||
index bd52d7d19060b0922c5165a071a5d12123028f79..39f2b1f30a475a1e571789c24b63028bdeff6cbb 100644
|
||||
index bd52d7d19060b0922c5165a071a5d12123028f79..6322251336a4300649f207efdb4d404d25023c9a 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/Items.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/Items.java
|
||||
@@ -258,7 +258,7 @@ public class Items {
|
||||
@@ -25,50 +25,10 @@ index bd52d7d19060b0922c5165a071a5d12123028f79..39f2b1f30a475a1e571789c24b63028b
|
||||
public static final Item PURPUR_PILLAR = registerBlock(Blocks.PURPUR_PILLAR, CreativeModeTab.TAB_BUILDING_BLOCKS);
|
||||
public static final Item PURPUR_STAIRS = registerBlock(Blocks.PURPUR_STAIRS, CreativeModeTab.TAB_BUILDING_BLOCKS);
|
||||
- public static final Item SPAWNER = registerBlock(new BlockItem(Blocks.SPAWNER, (new Item.Properties()).rarity(Rarity.EPIC)));
|
||||
+ public static final Item SPAWNER = registerBlock(Blocks.SPAWNER, new SpawnerItem(Blocks.SPAWNER, new Item.Properties().rarity(Rarity.EPIC))); // Purpur
|
||||
+ public static final Item SPAWNER = registerBlock(Blocks.SPAWNER, new net.pl3x.purpur.item.SpawnerItem(Blocks.SPAWNER, new Item.Properties().rarity(Rarity.EPIC))); // Purpur
|
||||
public static final Item OAK_STAIRS = registerBlock(Blocks.OAK_STAIRS, CreativeModeTab.TAB_BUILDING_BLOCKS);
|
||||
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/item/SpawnerItem.java b/src/main/java/net/minecraft/world/item/SpawnerItem.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..db721669c86ca0d3e393005182a8592fd0dba8cd
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/world/item/SpawnerItem.java
|
||||
@@ -0,0 +1,34 @@
|
||||
+package net.minecraft.world.item;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import net.minecraft.nbt.CompoundTag;
|
||||
+import net.minecraft.world.entity.EntityType;
|
||||
+import net.minecraft.world.entity.player.Player;
|
||||
+import net.minecraft.world.level.Level;
|
||||
+import net.minecraft.world.level.block.Block;
|
||||
+import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
+import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
||||
+import net.minecraft.world.level.block.state.BlockState;
|
||||
+
|
||||
+public class SpawnerItem extends BlockItem {
|
||||
+
|
||||
+ public SpawnerItem(Block block, Properties settings) {
|
||||
+ super(block, settings);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected boolean updateCustomBlockEntityTag(BlockPos pos, Level level, Player player, ItemStack stack, BlockState state) {
|
||||
+ boolean handled = super.updateCustomBlockEntityTag(pos, level, player, stack, state);
|
||||
+ if (level.purpurConfig.silkTouchEnabled && player.getBukkitEntity().hasPermission("purpur.place.spawners")) {
|
||||
+ BlockEntity spawner = level.getBlockEntity(pos);
|
||||
+ if (spawner instanceof SpawnerBlockEntity && stack.hasTag()) {
|
||||
+ CompoundTag tag = stack.getTag();
|
||||
+ if (tag.contains("Purpur.mob_type")) {
|
||||
+ EntityType.getByName(tag.getString("Purpur.mob_type")).ifPresent(type ->
|
||||
+ ((SpawnerBlockEntity) spawner).getSpawner().setEntityId(type));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return handled;
|
||||
+ }
|
||||
+}
|
||||
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..9ce53046b7f67309c2d4636b95e6fb05c103a13f 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SpawnerBlock.java
|
||||
@@ -217,3 +177,45 @@ index eed56c24c0c5bceef42addaa7e1cc17662fd1c49..c13a37baf05af23ad332d5ee2892c0ef
|
||||
public boolean babiesAreRidable = true;
|
||||
public boolean untamedTamablesAreRidable = true;
|
||||
public boolean useNightVisionWhenRiding = false;
|
||||
diff --git a/src/main/java/net/pl3x/purpur/item/SpawnerItem.java b/src/main/java/net/pl3x/purpur/item/SpawnerItem.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..728da3d75ec957ee789f9625483565e38649acd5
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/item/SpawnerItem.java
|
||||
@@ -0,0 +1,36 @@
|
||||
+package net.pl3x.purpur.item;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import net.minecraft.nbt.CompoundTag;
|
||||
+import net.minecraft.world.entity.EntityType;
|
||||
+import net.minecraft.world.entity.player.Player;
|
||||
+import net.minecraft.world.item.BlockItem;
|
||||
+import net.minecraft.world.item.ItemStack;
|
||||
+import net.minecraft.world.level.Level;
|
||||
+import net.minecraft.world.level.block.Block;
|
||||
+import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
+import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
||||
+import net.minecraft.world.level.block.state.BlockState;
|
||||
+
|
||||
+public class SpawnerItem extends BlockItem {
|
||||
+
|
||||
+ public SpawnerItem(Block block, Properties settings) {
|
||||
+ super(block, settings);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected boolean updateCustomBlockEntityTag(BlockPos pos, Level level, Player player, ItemStack stack, BlockState state) {
|
||||
+ boolean handled = super.updateCustomBlockEntityTag(pos, level, player, stack, state);
|
||||
+ if (level.purpurConfig.silkTouchEnabled && player.getBukkitEntity().hasPermission("purpur.place.spawners")) {
|
||||
+ BlockEntity spawner = level.getBlockEntity(pos);
|
||||
+ if (spawner instanceof SpawnerBlockEntity && stack.hasTag()) {
|
||||
+ CompoundTag tag = stack.getTag();
|
||||
+ if (tag.contains("Purpur.mob_type")) {
|
||||
+ EntityType.byString(tag.getString("Purpur.mob_type")).ifPresent(type ->
|
||||
+ ((SpawnerBlockEntity) spawner).getSpawner().setEntityId(type));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return handled;
|
||||
+ }
|
||||
+}
|
||||
|
||||
Reference in New Issue
Block a user