Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Fix API Registration of Custom Block Overrides (#4178)
* Api reg vanilla blockstate overrides; Closes #4177 Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * proper case non static Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Clear queue when done --------- Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
3547fab228
Commit
89d7225c54
@ -72,9 +72,9 @@ public class CustomBlockRegistryPopulator {
|
||||
|
||||
private static Set<CustomBlockData> CUSTOM_BLOCKS;
|
||||
private static Set<String> CUSTOM_BLOCK_NAMES;
|
||||
private static Int2ObjectMap<CustomBlockState> BLOCK_STATE_OVERRIDES;
|
||||
private static Map<String, CustomBlockData> CUSTOM_BLOCK_ITEM_OVERRIDES;
|
||||
private static Map<JavaBlockState, CustomBlockState> NON_VANILLA_BLOCK_STATE_OVERRIDES;
|
||||
private static Map<String, CustomBlockState> BLOCK_STATE_OVERRIDES_QUEUE;
|
||||
|
||||
/**
|
||||
* Initializes custom blocks defined by API
|
||||
@ -82,9 +82,9 @@ public class CustomBlockRegistryPopulator {
|
||||
private static void populateBedrock() {
|
||||
CUSTOM_BLOCKS = new ObjectOpenHashSet<>();
|
||||
CUSTOM_BLOCK_NAMES = new ObjectOpenHashSet<>();
|
||||
BLOCK_STATE_OVERRIDES = new Int2ObjectOpenHashMap<>();
|
||||
CUSTOM_BLOCK_ITEM_OVERRIDES = new HashMap<>();
|
||||
NON_VANILLA_BLOCK_STATE_OVERRIDES = new HashMap<>();
|
||||
BLOCK_STATE_OVERRIDES_QUEUE = new HashMap<>();
|
||||
|
||||
GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomBlocksEvent() {
|
||||
@Override
|
||||
@ -103,18 +103,11 @@ public class CustomBlockRegistryPopulator {
|
||||
|
||||
@Override
|
||||
public void registerOverride(@NonNull String javaIdentifier, @NonNull CustomBlockState customBlockState) {
|
||||
int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(javaIdentifier, -1);
|
||||
if (id == -1) {
|
||||
throw new IllegalArgumentException("Unknown Java block state. Identifier: " + javaIdentifier);
|
||||
}
|
||||
if (!CUSTOM_BLOCKS.contains(customBlockState.block())) {
|
||||
throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockState.name());
|
||||
}
|
||||
CustomBlockState oldBlockState = BLOCK_STATE_OVERRIDES.put(id, customBlockState);
|
||||
if (oldBlockState != null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Duplicate block state override for Java Identifier: " +
|
||||
javaIdentifier + " Old override: " + oldBlockState.name() + " New override: " + customBlockState.name());
|
||||
}
|
||||
// We can't register these yet as we don't have the java block id registry populated
|
||||
BLOCK_STATE_OVERRIDES_QUEUE.put(javaIdentifier, customBlockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -139,10 +132,28 @@ public class CustomBlockRegistryPopulator {
|
||||
* Registers all vanilla custom blocks and skulls defined by API and mappings
|
||||
*/
|
||||
private static void populateVanilla() {
|
||||
Int2ObjectMap<CustomBlockState> blockStateOverrides = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) {
|
||||
CUSTOM_BLOCKS.add(customSkull.getCustomBlockData());
|
||||
}
|
||||
|
||||
for(Map.Entry<String, CustomBlockState> entry : BLOCK_STATE_OVERRIDES_QUEUE.entrySet()) {
|
||||
int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(entry.getKey(), -1);
|
||||
if (id == -1) {
|
||||
GeyserImpl.getInstance().getLogger().warning("Custom block state override for Java Identifier: " +
|
||||
entry.getKey() + " could not be registered as it is not a valid block state.");
|
||||
continue;
|
||||
}
|
||||
|
||||
CustomBlockState oldBlockState = blockStateOverrides.put(id, entry.getValue());
|
||||
if (oldBlockState != null) {
|
||||
GeyserImpl.getInstance().getLogger().warning("Duplicate block state override for Java Identifier: " +
|
||||
entry.getKey() + " Old override: " + oldBlockState.name() + " New override: " + entry.getValue().name());
|
||||
}
|
||||
}
|
||||
BLOCK_STATE_OVERRIDES_QUEUE = null;
|
||||
|
||||
Map<CustomBlockData, Set<Integer>> extendedCollisionBoxes = new HashMap<>();
|
||||
Map<BoxComponent, CustomBlockData> extendedCollisionBoxSet = new HashMap<>();
|
||||
MappingsConfigReader mappingsConfigReader = new MappingsConfigReader();
|
||||
@ -153,7 +164,7 @@ public class CustomBlockRegistryPopulator {
|
||||
}
|
||||
block.states().forEach((javaIdentifier, customBlockState) -> {
|
||||
int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(javaIdentifier, -1);
|
||||
BLOCK_STATE_OVERRIDES.put(id, customBlockState.state());
|
||||
blockStateOverrides.put(id, customBlockState.state());
|
||||
BoxComponent extendedCollisionBox = customBlockState.extendedCollisionBox();
|
||||
if (extendedCollisionBox != null) {
|
||||
CustomBlockData extendedCollisionBlock = extendedCollisionBoxSet.computeIfAbsent(extendedCollisionBox, box -> {
|
||||
@ -167,9 +178,9 @@ public class CustomBlockRegistryPopulator {
|
||||
});
|
||||
});
|
||||
|
||||
BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(BLOCK_STATE_OVERRIDES);
|
||||
if (BLOCK_STATE_OVERRIDES.size() != 0) {
|
||||
GeyserImpl.getInstance().getLogger().info("Registered " + BLOCK_STATE_OVERRIDES.size() + " custom block overrides.");
|
||||
BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(blockStateOverrides);
|
||||
if (blockStateOverrides.size() != 0) {
|
||||
GeyserImpl.getInstance().getLogger().info("Registered " + blockStateOverrides.size() + " custom block overrides.");
|
||||
}
|
||||
|
||||
BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.set(CUSTOM_BLOCK_ITEM_OVERRIDES);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren