use of net.minecraft.resource.ResourceManager in project tweed-api by Siphalor.
the class ClientCore method onInitializeClient.
@Override
public void onInitializeClient() {
ConfigLoader.initialReload(ConfigEnvironment.UNIVERSAL);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier(Tweed.MOD_ID, "assets_listener");
}
@Override
public void apply(ResourceManager resourceManager) {
try {
ConfigLoader.loadConfigs(resourceManager, ConfigEnvironment.CLIENT, ConfigScope.SMALLEST);
} catch (Throwable e) {
Tweed.LOGGER.error("Tweed failed to load config files");
e.printStackTrace();
}
}
});
ServerStartCallback.EVENT.register(minecraftServer -> ConfigLoader.loadConfigs(minecraftServer.getDataManager(), ConfigEnvironment.UNIVERSAL, ConfigScope.WORLD));
ClientSidePacketRegistry.INSTANCE.register(Tweed.CONFIG_SYNC_S2C_PACKET, (packetContext, packetByteBuf) -> {
ConfigOrigin origin = packetByteBuf.readEnumConstant(ConfigOrigin.class);
String fileName = packetByteBuf.readString();
for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
if (configFile.getName().equals(fileName)) {
configFile.read(packetByteBuf, ConfigEnvironment.SERVER, ConfigScope.WORLD, origin);
if (scheduledClothBridge != null) {
scheduledClothBridge.onSync(configFile);
}
break;
}
}
});
}
use of net.minecraft.resource.ResourceManager in project Paradise-Lost by devs-immortal.
the class FluidRenderSetup method setupFluidRendering.
public static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_still");
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
final Sprite[] fluidSprites = { null, null };
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return listenerId;
}
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void apply(ResourceManager resourceManager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
});
// The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
final FluidRenderHandler renderHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
return fluidSprites;
}
@Override
public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
return color;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler);
}
use of net.minecraft.resource.ResourceManager in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method load.
public static Optional<NbtPlacerUtil> load(ResourceManager manager, Identifier id) {
try {
Optional<NbtCompound> nbtOptional = loadNbtFromFile(manager, id);
if (nbtOptional.isPresent()) {
NbtCompound nbt = nbtOptional.get();
NbtList paletteList = nbt.getList("palette", 10);
HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
for (int i = 0; i < paletteCompoundList.size(); i++) {
palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)));
}
NbtList sizeList = nbt.getList("size", 3);
BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2));
BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
NbtList positionsList = nbt.getList("blocks", 10);
HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
return Optional.of(new NbtPlacerUtil(nbt, positions, nbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector));
}
throw new NullPointerException();
} catch (Exception e) {
e.printStackTrace();
return Optional.empty();
}
}
use of net.minecraft.resource.ResourceManager in project quilt-standard-libraries by QuiltMC.
the class ResourceReloaderTestMod method setupServerReloadListeners.
private void setupServerReloadListeners() {
ResourceLoader.get(ResourceType.SERVER_DATA).registerReloader(new SimpleSynchronousResourceReloader() {
@Override
public Identifier getQuiltId() {
return ResourceLoaderTestMod.id("server_second");
}
@Override
public void reload(ResourceManager manager) {
if (!serverResources) {
throw new AssertionError("Second resource reloader was called before the first!");
}
LOGGER.info("Second server resource reloader is called.");
}
@Override
public Collection<Identifier> getQuiltDependencies() {
return Collections.singletonList(ResourceLoaderTestMod.id("server_first"));
}
});
ResourceLoader.get(ResourceType.SERVER_DATA).registerReloader(new SimpleSynchronousResourceReloader() {
@Override
public Identifier getQuiltId() {
return ResourceLoaderTestMod.id("server_first");
}
@Override
public void reload(ResourceManager manager) {
serverResources = true;
LOGGER.info("First server resource reloader is called.");
}
});
}
use of net.minecraft.resource.ResourceManager in project SpeedRunIGT by RedLime.
the class MinecraftClientMixin method onInit.
/**
* Add import font system
*/
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/debug/DebugRenderer;<init>(Lnet/minecraft/client/MinecraftClient;)V", shift = At.Shift.BEFORE))
public void onInit(RunArgs args, CallbackInfo ci) {
this.resourceManager.registerListener(new SinglePreparationResourceReloadListener<Map<Identifier, List<Font>>>() {
@Override
protected Map<Identifier, List<Font>> prepare(ResourceManager manager, Profiler profiler) {
SpeedRunIGT.FONT_MAPS.clear();
try {
HashMap<Identifier, List<Font>> map = new HashMap<>();
File[] fontFiles = SpeedRunIGT.FONT_PATH.toFile().listFiles();
if (fontFiles == null)
return new HashMap<>();
for (File file : Arrays.stream(fontFiles).filter(file -> file.getName().endsWith(".ttf")).collect(Collectors.toList())) {
File config = SpeedRunIGT.FONT_PATH.resolve(file.getName().substring(0, file.getName().length() - 4) + ".json").toFile();
if (config.exists()) {
FontUtils.addFont(map, file, config);
} else {
FontUtils.addFont(map, file, null);
}
}
return map;
} catch (Throwable e) {
return new HashMap<>();
}
}
@Override
protected void apply(Map<Identifier, List<Font>> loader, ResourceManager manager, Profiler profiler) {
try {
FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) MinecraftClient.getInstance()).getFontManager();
for (Map.Entry<Identifier, List<Font>> listEntry : loader.entrySet()) {
FontStorage fontStorage = new FontStorage(fontManager.getTextureManager(), listEntry.getKey());
fontStorage.setFonts(listEntry.getValue());
fontManager.getFontStorages().put(listEntry.getKey(), fontStorage);
}
TimerDrawer.fontHeightMap.clear();
} catch (Throwable e) {
SpeedRunIGT.error("Error! failed import timer fonts!");
e.printStackTrace();
}
}
});
}
Aggregations