add registerBlockItemOverride event + refactor

This commit is contained in:
Joshua Castle 2023-01-05 22:28:32 -08:00
parent 880d8e528e
commit d019160939
No known key found for this signature in database
GPG key ID: F674F38216C35D5D
6 changed files with 24 additions and 5 deletions

View file

@ -54,4 +54,13 @@ public abstract class GeyserDefineCustomBlocksEvent implements Event {
* @param customBlockState the custom block state with which to override java state identifier
*/
public abstract void registerBlockStateOverride(@NonNull String javaIdentifier, @NonNull CustomBlockState customBlockState);
/**
* Registers the given {@link CustomBlockData} as an override for the
* given java item identifier
*
* @param javaIdentifier the java item identifier to override
* @param customBlockData the custom block data with which to override java item identifier
*/
public abstract void registerBlockItemOverride(@NonNull String javaIdentifier, @NonNull CustomBlockData customBlockData);
}

View file

@ -29,8 +29,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.block.custom.CustomBlockMapping;
import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping;
import org.geysermc.geyser.registry.mappings.versions.MappingsReader;
import org.geysermc.geyser.registry.mappings.versions.MappingsReader_v1;

View file

@ -23,11 +23,13 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.block.custom;
package org.geysermc.geyser.registry.mappings.util;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.api.block.custom.CustomBlockState;
/**
* This class is used to store a custom block mappings, which contain all of the

View file

@ -27,10 +27,10 @@ package org.geysermc.geyser.registry.mappings.versions;
import com.fasterxml.jackson.databind.JsonNode;
import org.geysermc.geyser.api.block.custom.CustomBlockMapping;
import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping;
import java.nio.file.Path;
import java.util.function.BiConsumer;

View file

@ -31,7 +31,6 @@ import com.google.common.base.CharMatcher;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.api.block.custom.CustomBlockMapping;
import org.geysermc.geyser.api.block.custom.CustomBlockPermutation;
import org.geysermc.geyser.api.block.custom.CustomBlockState;
import org.geysermc.geyser.api.block.custom.component.BoxComponent;
@ -47,6 +46,7 @@ import org.geysermc.geyser.level.block.GeyserCustomBlockData.CustomBlockDataBuil
import org.geysermc.geyser.level.physics.BoundingBox;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.mappings.util.BlockPropertyTypeMaps;
import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping;
import org.geysermc.geyser.registry.type.BlockMapping;
import org.geysermc.geyser.util.BlockUtils;
@ -480,7 +480,7 @@ public class MappingsReader_v1 extends MappingsReader {
return pairs;
}
public float clamp(float value, float min, float max) {
private float clamp(float value, float min, float max) {
return Math.max(min, Math.min(max, value));
}

View file

@ -72,6 +72,14 @@ public class CustomBlockRegistryPopulator {
javaIdentifier + " Old override: " + oldBlockState.name() + " New override: " + customBlockState.name());
}
}
@Override
public void registerBlockItemOverride(@NonNull String javaIdentifier, @NonNull CustomBlockData customBlockData) {
if (!customBlocks.contains(customBlockData)) {
throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockData.name());
}
customBlockItemOverrides.put(javaIdentifier, customBlockData);
}
});
for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) {