Skip to content

Commit b5e234d

Browse files
committed
Unsafe block entity pos reading in ItemStack
1 parent 1e27cd9 commit b5e234d

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

paper-server/patches/sources/net/minecraft/world/item/crafting/SmithingTrimRecipe.java.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition, Holder<TrimPattern> pattern) {
1010
+ // Paper start - Option to prevent data components copy
11-
+ this(template, base, addition, true);
11+
+ this(template, base, addition, pattern, true);
1212
+ }
1313
+ public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition, Holder<TrimPattern> pattern, final boolean copyDataComponents) {
1414
+ this.copyDataComponents = copyDataComponents;

paper-server/patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@
1919
}
2020

2121
private void validateBlockState(BlockState state) {
22+
@@ -64,6 +_,7 @@
23+
int intOr = compoundTag.getIntOr("x", 0);
24+
int intOr1 = compoundTag.getIntOr("y", 0);
25+
int intOr2 = compoundTag.getIntOr("z", 0);
26+
+ if (chunkPos != null) { // Paper - allow reading non-validated pos from tag - used to parse block entities on items
27+
int sectionPosCoord = SectionPos.blockToSectionCoord(intOr);
28+
int sectionPosCoord1 = SectionPos.blockToSectionCoord(intOr2);
29+
if (sectionPosCoord != chunkPos.x || sectionPosCoord1 != chunkPos.z) {
30+
@@ -71,6 +_,7 @@
31+
intOr = chunkPos.getBlockX(SectionPos.sectionRelative(intOr));
32+
intOr2 = chunkPos.getBlockZ(SectionPos.sectionRelative(intOr2));
33+
}
34+
+ } // Paper - allow reading non-validated pos from tag - used to parse block entities on items
35+
36+
return new BlockPos(intOr, intOr1, intOr2);
37+
}
2238
@@ -89,6 +_,14 @@
2339
}
2440

paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.bukkit.entity.Minecart;
1414
import org.bukkit.material.MaterialData;
1515
import org.bukkit.util.Vector;
16+
import java.util.Optional;
1617

1718
public abstract class CraftMinecart extends CraftVehicle implements Minecart {
1819
public CraftMinecart(CraftServer server, AbstractMinecart entity) {
@@ -87,23 +88,21 @@ public AbstractMinecart getHandle() {
8788
public void setDisplayBlock(MaterialData material) {
8889
if (material != null) {
8990
BlockState block = CraftMagicNumbers.getBlock(material);
90-
this.getHandle().setDisplayBlockState(block);
91+
this.getHandle().setCustomDisplayBlockState(Optional.of(block));
9192
} else {
9293
// Set block to air (default) and set the flag to not have a display block.
93-
this.getHandle().setDisplayBlockState(Blocks.AIR.defaultBlockState());
94-
this.getHandle().setCustomDisplay(false);
94+
this.getHandle().setCustomDisplayBlockState(Optional.empty());
9595
}
9696
}
9797

9898
@Override
9999
public void setDisplayBlockData(BlockData blockData) {
100100
if (blockData != null) {
101101
BlockState block = ((CraftBlockData) blockData).getState();
102-
this.getHandle().setDisplayBlockState(block);
102+
this.getHandle().setCustomDisplayBlockState(Optional.of(block));
103103
} else {
104104
// Set block to air (default) and set the flag to not have a display block.
105-
this.getHandle().setDisplayBlockState(Blocks.AIR.defaultBlockState());
106-
this.getHandle().setCustomDisplay(false);
105+
this.getHandle().setCustomDisplayBlockState(Optional.empty());
107106
}
108107
}
109108

paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public CraftBlockEntityState<?> getBlockState() {
282282
final Material stateMaterial = this.materialForBlockEntityType();
283283
if (!this.blockEntityTag.isEmpty()) {
284284
// Paper "id" field is always present now
285-
pos = BlockEntity.getPosFromTag(this.blockEntityTag.getUnsafe()); // unsafe is fine here, just querying
285+
pos = BlockEntity.getPosFromTag(null, this.blockEntityTag.getUnsafe()); // unsafe is fine here, just querying
286286
}
287287
final net.minecraft.world.level.block.entity.BlockEntityType<?> type = java.util.Objects.requireNonNull(CraftBlockStates.getBlockEntityType(stateMaterial));
288288
final net.minecraft.world.level.block.state.BlockState nmsBlockState = ((org.bukkit.craftbukkit.block.data.CraftBlockData) this.getBlockData(stateMaterial)).getState();
@@ -314,7 +314,7 @@ private static CraftBlockEntityState<?> getBlockState(Material material, Compoun
314314
blockEntityTag.putString("id", "minecraft:shulker_box");
315315
}
316316

317-
pos = BlockEntity.getPosFromTag(blockEntityTag);
317+
pos = BlockEntity.getPosFromTag(null, blockEntityTag);
318318
}
319319

320320
// This is expected to always return a CraftBlockEntityState for the passed material:

paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftTransmuteRecipe.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import net.minecraft.core.Holder;
44
import net.minecraft.server.MinecraftServer;
5+
import net.minecraft.world.item.ItemStack;
56
import net.minecraft.world.item.crafting.RecipeHolder;
7+
import net.minecraft.world.item.crafting.TransmuteResult;
68
import org.bukkit.Material;
79
import org.bukkit.NamespacedKey;
810
import org.bukkit.inventory.RecipeChoice;
@@ -26,15 +28,16 @@ public static CraftTransmuteRecipe fromBukkitRecipe(TransmuteRecipe recipe) {
2628

2729
@Override
2830
public void addToCraftingManager() {
31+
final ItemStack unwrappedInternalStack = CraftItemStack.unwrap(this.getResult());
2932
MinecraftServer.getServer().getRecipeManager().addRecipe(
30-
new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()),
31-
new net.minecraft.world.item.crafting.TransmuteRecipe(this.getGroup(),
32-
CraftRecipe.getCategory(this.getCategory()),
33-
this.toNMS(this.getInput(), true),
34-
this.toNMS(this.getMaterial(), true),
35-
Holder.direct(CraftItemType.bukkitToMinecraft(this.getResult().getType()))
36-
)
33+
new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()),
34+
new net.minecraft.world.item.crafting.TransmuteRecipe(this.getGroup(),
35+
CraftRecipe.getCategory(this.getCategory()),
36+
this.toNMS(this.getInput(), true),
37+
this.toNMS(this.getMaterial(), true),
38+
new TransmuteResult(unwrappedInternalStack.getItemHolder(), unwrappedInternalStack.getCount(), unwrappedInternalStack.getComponentsPatch())
3739
)
40+
)
3841
);
3942
}
4043
}

0 commit comments

Comments
 (0)