9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-04 15:41:40 +00:00

optimize BlockEntityType#isValid (#290)

This commit is contained in:
hayanesuru
2025-04-25 17:10:50 +08:00
committed by GitHub
parent 124dc64a0d
commit 0bd14537d9

View File

@@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <mc@jvavav.com>
Date: Sat, 19 Apr 2025 22:12:19 +0800
Subject: [PATCH] optimize BlockEntityType#isValid
diff --git a/net/minecraft/world/level/block/entity/BlockEntityType.java b/net/minecraft/world/level/block/entity/BlockEntityType.java
index a2a674f18d7f2c2e50a6b25f9ac3bf4534275976..bcfd5dc20d20fe6b74d726c7086a0cc7ae2565de 100644
--- a/net/minecraft/world/level/block/entity/BlockEntityType.java
+++ b/net/minecraft/world/level/block/entity/BlockEntityType.java
@@ -246,12 +246,20 @@ public class BlockEntityType<T extends BlockEntity> {
}
Util.fetchChoiceType(References.BLOCK_ENTITY, name);
- return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, name, new BlockEntityType<>(factory, Set.of(validBlocks)));
+ return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, name, new BlockEntityType<>(factory, com.google.common.collect.ImmutableSet.copyOf(validBlocks))); // Leaf - ensure immutable
}
private BlockEntityType(BlockEntityType.BlockEntitySupplier<? extends T> factory, Set<Block> validBlocks) {
this.factory = factory;
this.validBlocks = validBlocks;
+ // Leaf start
+ for (Block validBlock : validBlocks) {
+ if (validBlock.blockEntityType != null) {
+ throw new IllegalStateException("Duplicate block entity type");
+ }
+ validBlock.blockEntityType = this;
+ }
+ // Leaf end
}
@Nullable
@@ -260,7 +268,7 @@ public class BlockEntityType<T extends BlockEntity> {
}
public boolean isValid(BlockState state) {
- return this.validBlocks.contains(state.getBlock());
+ return state.getBlock().blockEntityType == this; // Leaf - remove hash lookup
}
@Deprecated
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index d35211b0cae66b1a40e89539507e55973313f46f..fa6d4217f222e8d9decde18e967e951dd833a1c7 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -100,6 +100,7 @@ public abstract class BlockBehaviour implements FeatureElement {
protected final BlockBehaviour.Properties properties;
protected final Optional<ResourceKey<LootTable>> drops;
protected final String descriptionId;
+ @Nullable public net.minecraft.world.level.block.entity.BlockEntityType blockEntityType = null; // Leaf
public BlockBehaviour(BlockBehaviour.Properties properties) {
this.hasCollision = properties.hasCollision;