mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Enchantment Table Persists Lapis
This commit is contained in:
@@ -1,153 +0,0 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Ben Kerllenevich <ben@omega24.dev>
|
|
||||||
Date: Sat, 25 Jun 2022 08:04:06 -0400
|
|
||||||
Subject: [PATCH] Enchantment Table Persists Lapis
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/net/minecraft/world/inventory/EnchantmentMenu.java b/net/minecraft/world/inventory/EnchantmentMenu.java
|
|
||||||
index bb9b17a058273ee1519b2abbefba97cad7feb51b..29996864b35711b29629e9071d28493ac27fbde6 100644
|
|
||||||
--- a/net/minecraft/world/inventory/EnchantmentMenu.java
|
|
||||||
+++ b/net/minecraft/world/inventory/EnchantmentMenu.java
|
|
||||||
@@ -41,6 +41,12 @@ import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
// CraftBukkit end
|
|
||||||
|
|
||||||
+// Purpur start
|
|
||||||
+import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
+import net.minecraft.world.level.block.entity.EnchantingTableBlockEntity;
|
|
||||||
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
||||||
+// Purpur end
|
|
||||||
+
|
|
||||||
public class EnchantmentMenu extends AbstractContainerMenu {
|
|
||||||
|
|
||||||
static final ResourceLocation EMPTY_SLOT_LAPIS_LAZULI = ResourceLocation.withDefaultNamespace("container/slot/lapis_lazuli");
|
|
||||||
@@ -75,6 +81,22 @@ public class EnchantmentMenu extends AbstractContainerMenu {
|
|
||||||
return context.getLocation();
|
|
||||||
}
|
|
||||||
// CraftBukkit end
|
|
||||||
+
|
|
||||||
+ // Purpur start
|
|
||||||
+ @Override
|
|
||||||
+ public void onClose(CraftHumanEntity who) {
|
|
||||||
+ super.onClose(who);
|
|
||||||
+
|
|
||||||
+ if (who.getHandle().level().purpurConfig.enchantmentTableLapisPersists) {
|
|
||||||
+ access.execute((level, pos) -> {
|
|
||||||
+ BlockEntity blockEntity = level.getBlockEntity(pos);
|
|
||||||
+ if (blockEntity instanceof EnchantingTableBlockEntity enchantmentTable) {
|
|
||||||
+ enchantmentTable.setLapis(this.getItem(1).getCount());
|
|
||||||
+ }
|
|
||||||
+ });
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ // Purpur end
|
|
||||||
};
|
|
||||||
this.random = RandomSource.create();
|
|
||||||
this.enchantmentSeed = DataSlot.standalone();
|
|
||||||
@@ -99,6 +121,16 @@ public class EnchantmentMenu extends AbstractContainerMenu {
|
|
||||||
return EnchantmentMenu.EMPTY_SLOT_LAPIS_LAZULI;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
+ // Purpur start
|
|
||||||
+ access.execute((level, pos) -> {
|
|
||||||
+ if (level.purpurConfig.enchantmentTableLapisPersists) {
|
|
||||||
+ BlockEntity blockEntity = level.getBlockEntity(pos);
|
|
||||||
+ if (blockEntity instanceof EnchantingTableBlockEntity enchantmentTable) {
|
|
||||||
+ this.getSlot(1).set(new ItemStack(Items.LAPIS_LAZULI, enchantmentTable.getLapis()));
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ });
|
|
||||||
+ // Purpur end
|
|
||||||
this.addStandardInventorySlots(playerInventory, 8, 84);
|
|
||||||
this.addDataSlot(DataSlot.shared(this.costs, 0));
|
|
||||||
this.addDataSlot(DataSlot.shared(this.costs, 1));
|
|
||||||
@@ -328,6 +360,7 @@ public class EnchantmentMenu extends AbstractContainerMenu {
|
|
||||||
public void removed(net.minecraft.world.entity.player.Player player) {
|
|
||||||
super.removed(player);
|
|
||||||
this.access.execute((world, blockposition) -> {
|
|
||||||
+ if (world.purpurConfig.enchantmentTableLapisPersists) this.getSlot(1).set(ItemStack.EMPTY); // Purpur
|
|
||||||
this.clearContainer(player, this.enchantSlots);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
diff --git a/net/minecraft/world/level/block/EnchantingTableBlock.java b/net/minecraft/world/level/block/EnchantingTableBlock.java
|
|
||||||
index 4c4e6290035710480cd5c1d7399f2443df01a5a6..248039ac7eab85b29ae3c525a986d91aa8d177fe 100644
|
|
||||||
--- a/net/minecraft/world/level/block/EnchantingTableBlock.java
|
|
||||||
+++ b/net/minecraft/world/level/block/EnchantingTableBlock.java
|
|
||||||
@@ -118,4 +118,18 @@ public class EnchantingTableBlock extends BaseEntityBlock {
|
|
||||||
protected boolean isPathfindable(BlockState state, PathComputationType type) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ // Purpur start
|
|
||||||
+ @Override
|
|
||||||
+ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean moved) {
|
|
||||||
+ BlockEntity blockEntity = level.getBlockEntity(pos);
|
|
||||||
+
|
|
||||||
+ if (level.purpurConfig.enchantmentTableLapisPersists && blockEntity instanceof EnchantingTableBlockEntity enchantmentTable) {
|
|
||||||
+ net.minecraft.world.Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.LAPIS_LAZULI, enchantmentTable.getLapis()));
|
|
||||||
+ level.updateNeighbourForOutputSignal(pos, this);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ super.onRemove(state, level, pos, newState, moved);
|
|
||||||
+ }
|
|
||||||
+ // Purpur end
|
|
||||||
}
|
|
||||||
diff --git a/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java b/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
|
|
||||||
index 39aac959775afeaeea211f21d498cb0ddf0a3fcb..6349a342c023f378af431a73a62fb017882e257d 100644
|
|
||||||
--- a/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
|
|
||||||
+++ b/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
|
|
||||||
@@ -28,6 +28,7 @@ public class EnchantingTableBlockEntity extends BlockEntity implements Nameable
|
|
||||||
private static final RandomSource RANDOM = RandomSource.create();
|
|
||||||
@Nullable
|
|
||||||
private Component name;
|
|
||||||
+ private int lapis = 0; // Purpur
|
|
||||||
|
|
||||||
public EnchantingTableBlockEntity(BlockPos pos, BlockState state) {
|
|
||||||
super(BlockEntityType.ENCHANTING_TABLE, pos, state);
|
|
||||||
@@ -39,6 +40,7 @@ public class EnchantingTableBlockEntity extends BlockEntity implements Nameable
|
|
||||||
if (this.hasCustomName()) {
|
|
||||||
nbt.putString("CustomName", Component.Serializer.toJson(this.name, registries));
|
|
||||||
}
|
|
||||||
+ nbt.putInt("Purpur.Lapis", this.lapis); // Purpur
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@@ -47,6 +49,7 @@ public class EnchantingTableBlockEntity extends BlockEntity implements Nameable
|
|
||||||
if (nbt.contains("CustomName", 8)) {
|
|
||||||
this.name = parseCustomNameSafe(nbt.getString("CustomName"), registries);
|
|
||||||
}
|
|
||||||
+ this.lapis = nbt.getInt("Purpur.Lapis"); // Purpur
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void bookAnimationTick(Level world, BlockPos pos, BlockState state, EnchantingTableBlockEntity blockEntity) {
|
|
||||||
@@ -138,4 +141,14 @@ public class EnchantingTableBlockEntity extends BlockEntity implements Nameable
|
|
||||||
public void removeComponentsFromTag(CompoundTag nbt) {
|
|
||||||
nbt.remove("CustomName");
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ // Purpur start
|
|
||||||
+ public int getLapis() {
|
|
||||||
+ return this.lapis;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public void setLapis(int lapis) {
|
|
||||||
+ this.lapis = lapis;
|
|
||||||
+ }
|
|
||||||
+ // Purpur
|
|
||||||
}
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
index c122af4829a2edd3977af0310b27bb984d8eaad5..71a631b2adcd9f67ae8831a002129b6f76c3a331 100644
|
|
||||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
@@ -1565,6 +1565,11 @@ public class PurpurWorldConfig {
|
|
||||||
elderGuardianAlwaysDropExp = getBoolean("mobs.elder_guardian.always-drop-exp", elderGuardianAlwaysDropExp);
|
|
||||||
}
|
|
||||||
|
|
||||||
+ public boolean enchantmentTableLapisPersists = false;
|
|
||||||
+ private void enchantmentTableSettings() {
|
|
||||||
+ enchantmentTableLapisPersists = getBoolean("blocks.enchantment-table.lapis-persists", enchantmentTableLapisPersists);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
public boolean enderDragonRidable = false;
|
|
||||||
public boolean enderDragonRidableInWater = true;
|
|
||||||
public boolean enderDragonControllable = true;
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
--- a/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||||
|
+++ b/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||||
|
@@ -63,6 +_,22 @@
|
||||||
|
return access.getLocation();
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
+
|
||||||
|
+ // Purpur start - Enchantment Table Persists Lapis
|
||||||
|
+ @Override
|
||||||
|
+ public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
|
||||||
|
+ super.onClose(who);
|
||||||
|
+
|
||||||
|
+ if (who.getHandle().level().purpurConfig.enchantmentTableLapisPersists) {
|
||||||
|
+ access.execute((level, pos) -> {
|
||||||
|
+ net.minecraft.world.level.block.entity.BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
+ if (blockEntity instanceof net.minecraft.world.level.block.entity.EnchantingTableBlockEntity enchantmentTable) {
|
||||||
|
+ enchantmentTable.setLapis(this.getItem(1).getCount());
|
||||||
|
+ }
|
||||||
|
+ });
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Purpur end - Enchantment Table Persists Lapis
|
||||||
|
};
|
||||||
|
// Paper end - Add missing InventoryHolders
|
||||||
|
this.access = access;
|
||||||
|
@@ -83,6 +_,16 @@
|
||||||
|
return EnchantmentMenu.EMPTY_SLOT_LAPIS_LAZULI;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
+ // Purpur start - Enchantment Table Persists Lapis
|
||||||
|
+ access.execute((level, pos) -> {
|
||||||
|
+ if (level.purpurConfig.enchantmentTableLapisPersists) {
|
||||||
|
+ net.minecraft.world.level.block.entity.BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
+ if (blockEntity instanceof net.minecraft.world.level.block.entity.EnchantingTableBlockEntity enchantmentTable) {
|
||||||
|
+ this.getSlot(1).set(new ItemStack(Items.LAPIS_LAZULI, enchantmentTable.getLapis()));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ });
|
||||||
|
+ // Purpur end - Enchantment Table Persists Lapis
|
||||||
|
this.addStandardInventorySlots(playerInventory, 8, 84);
|
||||||
|
this.addDataSlot(DataSlot.shared(this.costs, 0));
|
||||||
|
this.addDataSlot(DataSlot.shared(this.costs, 1));
|
||||||
|
@@ -292,7 +_,7 @@
|
||||||
|
@Override
|
||||||
|
public void removed(Player player) {
|
||||||
|
super.removed(player);
|
||||||
|
- this.access.execute((level, blockPos) -> this.clearContainer(player, this.enchantSlots));
|
||||||
|
+ this.access.execute((level, blockPos) -> {if (level.purpurConfig.enchantmentTableLapisPersists) this.getSlot(1).set(ItemStack.EMPTY);this.clearContainer(player, this.enchantSlots);}); // Purpur - Enchantment Table Persists Lapis
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
--- a/net/minecraft/world/level/block/EnchantingTableBlock.java
|
||||||
|
+++ b/net/minecraft/world/level/block/EnchantingTableBlock.java
|
||||||
|
@@ -119,4 +_,18 @@
|
||||||
|
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Purpur start - Enchantment Table Persists Lapis
|
||||||
|
+ @Override
|
||||||
|
+ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean moved) {
|
||||||
|
+ BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
+
|
||||||
|
+ if (level.purpurConfig.enchantmentTableLapisPersists && blockEntity instanceof EnchantingTableBlockEntity enchantmentTable) {
|
||||||
|
+ net.minecraft.world.Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.LAPIS_LAZULI, enchantmentTable.getLapis()));
|
||||||
|
+ level.updateNeighbourForOutputSignal(pos, this);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ super.onRemove(state, level, pos, newState, moved);
|
||||||
|
+ }
|
||||||
|
+ // Purpur end - Enchantment Table Persists Lapis
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
--- a/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
|
||||||
|
+++ b/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
|
||||||
|
@@ -28,6 +_,7 @@
|
||||||
|
private static final RandomSource RANDOM = RandomSource.create();
|
||||||
|
@Nullable
|
||||||
|
private Component name;
|
||||||
|
+ private int lapis = 0; // Purpur - Enchantment Table Persists Lapis
|
||||||
|
|
||||||
|
public EnchantingTableBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
super(BlockEntityType.ENCHANTING_TABLE, pos, state);
|
||||||
|
@@ -39,6 +_,7 @@
|
||||||
|
if (this.hasCustomName()) {
|
||||||
|
tag.putString("CustomName", Component.Serializer.toJson(this.name, registries));
|
||||||
|
}
|
||||||
|
+ tag.putInt("Purpur.Lapis", this.lapis); // Purpur - Enchantment Table Persists Lapis
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@@ -47,6 +_,7 @@
|
||||||
|
if (tag.contains("CustomName", 8)) {
|
||||||
|
this.name = parseCustomNameSafe(tag.getString("CustomName"), registries);
|
||||||
|
}
|
||||||
|
+ this.lapis = tag.getInt("Purpur.Lapis"); // Purpur - Enchantment Table Persists Lapis
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void bookAnimationTick(Level level, BlockPos pos, BlockState state, EnchantingTableBlockEntity enchantingTable) {
|
||||||
|
@@ -138,4 +_,14 @@
|
||||||
|
public void removeComponentsFromTag(CompoundTag tag) {
|
||||||
|
tag.remove("CustomName");
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Purpur start - Enchantment Table Persists Lapis
|
||||||
|
+ public int getLapis() {
|
||||||
|
+ return this.lapis;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void setLapis(int lapis) {
|
||||||
|
+ this.lapis = lapis;
|
||||||
|
+ }
|
||||||
|
+ // Purpur end - Enchantment Table Persists Lapis
|
||||||
|
}
|
||||||
@@ -1564,6 +1564,11 @@ public class PurpurWorldConfig {
|
|||||||
elderGuardianAlwaysDropExp = getBoolean("mobs.elder_guardian.always-drop-exp", elderGuardianAlwaysDropExp);
|
elderGuardianAlwaysDropExp = getBoolean("mobs.elder_guardian.always-drop-exp", elderGuardianAlwaysDropExp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean enchantmentTableLapisPersists = false;
|
||||||
|
private void enchantmentTableSettings() {
|
||||||
|
enchantmentTableLapisPersists = getBoolean("blocks.enchantment-table.lapis-persists", enchantmentTableLapisPersists);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean enderDragonRidable = false;
|
public boolean enderDragonRidable = false;
|
||||||
public boolean enderDragonRidableInWater = true;
|
public boolean enderDragonRidableInWater = true;
|
||||||
public boolean enderDragonControllable = true;
|
public boolean enderDragonControllable = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user