make dimdoor registrar remember Block identifier mappings (dimdoor -> regular door)
This commit is contained in:
parent
f82c4dd78e
commit
d882f98432
4 changed files with 37 additions and 11 deletions
|
@ -70,6 +70,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
|||
private static final ConfigHolder<ModConfig> CONFIG_MANAGER = AutoConfig.register(ModConfig.class, ModConfig.SubRootJanksonConfigSerializer::new);
|
||||
private static MinecraftServer server;
|
||||
private static ModContainer dimDoorsMod;
|
||||
private static DimensionalDoorBlockRegistrar dimensionalDoorBlockRegistrar;
|
||||
|
||||
@NotNull
|
||||
public static MinecraftServer getServer() {
|
||||
|
@ -79,6 +80,10 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
|||
throw new UnsupportedOperationException("Accessed server too early!");
|
||||
}
|
||||
|
||||
public static DimensionalDoorBlockRegistrar getDimensionalDoorBlockRegistrar() {
|
||||
return dimensionalDoorBlockRegistrar;
|
||||
}
|
||||
|
||||
public static ServerWorld getWorld(RegistryKey<World> key) {
|
||||
return getServer().getWorld(key);
|
||||
}
|
||||
|
@ -119,7 +124,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
|||
ModParticleTypes.init();
|
||||
ModCriteria.init();
|
||||
|
||||
DimensionalDoorBlockRegistrar dimensionalDoorBlockRegistrar = new DimensionalDoorBlockRegistrar(Registry.BLOCK);
|
||||
dimensionalDoorBlockRegistrar = new DimensionalDoorBlockRegistrar(Registry.BLOCK);
|
||||
dimensionalDoorBlockRegistrar.init();
|
||||
RegistryEntryAddedCallback.event(Registry.BLOCK).register(new ItemRegistryEntryAddedListener(dimensionalDoorBlockRegistrar));
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package org.dimdev.dimdoors.block.door;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.TrapdoorBlock;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
|
@ -13,10 +18,12 @@ import java.util.Map;
|
|||
import java.util.function.Function;
|
||||
|
||||
public class DimensionalDoorBlockRegistrar {
|
||||
private static final String PREFIX = "autogen_";
|
||||
private static final String PREFIX = "autogen_dimensional_";
|
||||
|
||||
private final Registry<Block> registry;
|
||||
|
||||
private final Map<Identifier, Identifier> mappedDoorBlocks = new HashMap<>();
|
||||
|
||||
public DimensionalDoorBlockRegistrar(Registry<Block> registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
@ -41,7 +48,21 @@ public class DimensionalDoorBlockRegistrar {
|
|||
}
|
||||
|
||||
private void register(Identifier identifier, Block block, Function<AbstractBlock.Settings, ? extends Block> constructor) {
|
||||
Registry.register(registry, new Identifier("dimdoors", PREFIX + identifier.getNamespace() + "_dimdoors_" + identifier.getPath()), constructor.apply(AbstractBlock.Settings.copy(block)));
|
||||
Identifier gennedId = new Identifier("dimdoors", PREFIX + identifier.getPath());
|
||||
Block newBlock = Registry.register(registry, gennedId, constructor.apply(FabricBlockSettings.copy(block)));
|
||||
mappedDoorBlocks.put(gennedId, identifier);
|
||||
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(newBlock, RenderLayer.getCutout());
|
||||
}
|
||||
}
|
||||
|
||||
public Identifier get(Identifier identifier) {
|
||||
return mappedDoorBlocks.get(identifier);
|
||||
}
|
||||
|
||||
public boolean isMapped(Identifier identifier) {
|
||||
return mappedDoorBlocks.containsKey(identifier);
|
||||
}
|
||||
|
||||
// Just in case we want to support more Door classes in the future.
|
||||
|
|
|
@ -6,17 +6,18 @@ import net.fabricmc.fabric.api.client.model.ModelVariantProvider;
|
|||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.block.door.DimensionalDoorBlockRegistrar;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DimensionalDoorModelVariantProvider implements ModelVariantProvider {
|
||||
private static final String PREFIX = "autogen_";
|
||||
|
||||
@Override
|
||||
public @Nullable UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException {
|
||||
String path = modelId.getPath();
|
||||
if (!path.startsWith(PREFIX)) return null;
|
||||
String[] separatedId = path.substring(PREFIX.length()).split("_dimdoors_");
|
||||
ModelIdentifier newId = new ModelIdentifier(new Identifier(separatedId[0], separatedId[1]), modelId.getVariant());
|
||||
Identifier identifier = new Identifier(modelId.getNamespace(), modelId.getPath());
|
||||
DimensionalDoorBlockRegistrar registrar = DimensionalDoorsInitializer.getDimensionalDoorBlockRegistrar();
|
||||
if (!registrar.isMapped(identifier)) return null;
|
||||
Identifier mapped = registrar.get(identifier);
|
||||
ModelIdentifier newId = new ModelIdentifier(mapped, modelId.getVariant());
|
||||
return context.loadModel(newId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,5 +24,4 @@ public class ServerPlayerInteractionManagerMixin {
|
|||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue