3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +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:
Kas-tle 2023-10-04 09:56:47 -07:00 committet von GitHub
Ursprung 3547fab228
Commit 89d7225c54
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -72,9 +72,9 @@ public class CustomBlockRegistryPopulator {
private static Set<CustomBlockData> CUSTOM_BLOCKS; private static Set<CustomBlockData> CUSTOM_BLOCKS;
private static Set<String> CUSTOM_BLOCK_NAMES; 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<String, CustomBlockData> CUSTOM_BLOCK_ITEM_OVERRIDES;
private static Map<JavaBlockState, CustomBlockState> NON_VANILLA_BLOCK_STATE_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 * Initializes custom blocks defined by API
@ -82,9 +82,9 @@ public class CustomBlockRegistryPopulator {
private static void populateBedrock() { private static void populateBedrock() {
CUSTOM_BLOCKS = new ObjectOpenHashSet<>(); CUSTOM_BLOCKS = new ObjectOpenHashSet<>();
CUSTOM_BLOCK_NAMES = new ObjectOpenHashSet<>(); CUSTOM_BLOCK_NAMES = new ObjectOpenHashSet<>();
BLOCK_STATE_OVERRIDES = new Int2ObjectOpenHashMap<>();
CUSTOM_BLOCK_ITEM_OVERRIDES = new HashMap<>(); CUSTOM_BLOCK_ITEM_OVERRIDES = new HashMap<>();
NON_VANILLA_BLOCK_STATE_OVERRIDES = new HashMap<>(); NON_VANILLA_BLOCK_STATE_OVERRIDES = new HashMap<>();
BLOCK_STATE_OVERRIDES_QUEUE = new HashMap<>();
GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomBlocksEvent() { GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomBlocksEvent() {
@Override @Override
@ -103,18 +103,11 @@ public class CustomBlockRegistryPopulator {
@Override @Override
public void registerOverride(@NonNull String javaIdentifier, @NonNull CustomBlockState customBlockState) { 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())) { if (!CUSTOM_BLOCKS.contains(customBlockState.block())) {
throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockState.name()); throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockState.name());
} }
CustomBlockState oldBlockState = BLOCK_STATE_OVERRIDES.put(id, customBlockState); // We can't register these yet as we don't have the java block id registry populated
if (oldBlockState != null) { BLOCK_STATE_OVERRIDES_QUEUE.put(javaIdentifier, customBlockState);
GeyserImpl.getInstance().getLogger().debug("Duplicate block state override for Java Identifier: " +
javaIdentifier + " Old override: " + oldBlockState.name() + " New override: " + customBlockState.name());
}
} }
@Override @Override
@ -139,10 +132,28 @@ public class CustomBlockRegistryPopulator {
* Registers all vanilla custom blocks and skulls defined by API and mappings * Registers all vanilla custom blocks and skulls defined by API and mappings
*/ */
private static void populateVanilla() { private static void populateVanilla() {
Int2ObjectMap<CustomBlockState> blockStateOverrides = new Int2ObjectOpenHashMap<>();
for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) { for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) {
CUSTOM_BLOCKS.add(customSkull.getCustomBlockData()); 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<CustomBlockData, Set<Integer>> extendedCollisionBoxes = new HashMap<>();
Map<BoxComponent, CustomBlockData> extendedCollisionBoxSet = new HashMap<>(); Map<BoxComponent, CustomBlockData> extendedCollisionBoxSet = new HashMap<>();
MappingsConfigReader mappingsConfigReader = new MappingsConfigReader(); MappingsConfigReader mappingsConfigReader = new MappingsConfigReader();
@ -153,7 +164,7 @@ public class CustomBlockRegistryPopulator {
} }
block.states().forEach((javaIdentifier, customBlockState) -> { block.states().forEach((javaIdentifier, customBlockState) -> {
int id = BlockRegistries.JAVA_IDENTIFIER_TO_ID.getOrDefault(javaIdentifier, -1); 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(); BoxComponent extendedCollisionBox = customBlockState.extendedCollisionBox();
if (extendedCollisionBox != null) { if (extendedCollisionBox != null) {
CustomBlockData extendedCollisionBlock = extendedCollisionBoxSet.computeIfAbsent(extendedCollisionBox, box -> { CustomBlockData extendedCollisionBlock = extendedCollisionBoxSet.computeIfAbsent(extendedCollisionBox, box -> {
@ -167,9 +178,9 @@ public class CustomBlockRegistryPopulator {
}); });
}); });
BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(BLOCK_STATE_OVERRIDES); BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.set(blockStateOverrides);
if (BLOCK_STATE_OVERRIDES.size() != 0) { if (blockStateOverrides.size() != 0) {
GeyserImpl.getInstance().getLogger().info("Registered " + BLOCK_STATE_OVERRIDES.size() + " custom block overrides."); GeyserImpl.getInstance().getLogger().info("Registered " + blockStateOverrides.size() + " custom block overrides.");
} }
BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.set(CUSTOM_BLOCK_ITEM_OVERRIDES); BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.set(CUSTOM_BLOCK_ITEM_OVERRIDES);