use of net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener in project Primeval by devs-immortal.
the class PrimevalFluids method setupFluidRendering.
/*
* Fluid rendering setup from Spectrum,
* Made by DaFaqs, credit to him for this
* method
*/
@Environment(EnvType.CLIENT)
private 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());
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() {
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void reload(ResourceManager manager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
@Override
public Identifier getFabricId() {
return listenerId;
}
});
// 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); // Temp removed because of flowing shenanigans
}
use of net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener in project fabric by FabricMC.
the class ResourceReloadModClient method onInitializeClient.
@Override
public void onInitializeClient() {
for (int i = 64; i >= 2; i--) {
final int _i = i;
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public void apply(ResourceManager var1) {
System.out.println("Reloading (should run as #" + _i + ")");
}
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc" + _i);
}
@Override
public Collection<Identifier> getFabricDependencies() {
return Collections.singletonList(new Identifier("fabric:rrmc" + (_i - 1)));
}
});
}
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc1");
}
@Override
public void apply(ResourceManager var1) {
System.out.println("Reloading (should run as #1)");
}
});
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc_should_not_resolve");
}
@Override
public Collection<Identifier> getFabricDependencies() {
return Collections.singletonList(new Identifier("fabric:rrmc_nonexistent"));
}
@Override
public void apply(ResourceManager var1) {
}
});
}
use of net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener in project tweed-api by Siphalor.
the class Tweed method onInitialize.
@Override
public void onInitialize() {
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier(Tweed.MOD_ID, "resource_reload");
}
@Override
public void apply(ResourceManager resourceManager) {
try {
ConfigLoader.loadConfigs(resourceManager, ConfigEnvironment.SERVER, ConfigScope.SMALLEST);
} catch (Throwable e) {
Tweed.LOGGER.error("Tweed failed to load config files:");
e.printStackTrace();
}
}
});
ServerSidePacketRegistry.INSTANCE.register(REQUEST_SYNC_C2S_PACKET, (packetContext, packetByteBuf) -> {
String fileName = packetByteBuf.readString(32767);
for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
if (configFile.getName().equals(fileName)) {
if (Objects.requireNonNull(packetContext.getPlayer().getServer()).getPermissionLevel(packetContext.getPlayer().getGameProfile()) == 4) {
configFile.syncToClient((ServerPlayerEntity) packetContext.getPlayer(), packetByteBuf.readEnumConstant(ConfigEnvironment.class), packetByteBuf.readEnumConstant(ConfigScope.class), packetByteBuf.readEnumConstant(ConfigOrigin.class));
} else {
packetByteBuf.readEnumConstant(ConfigEnvironment.class);
ConfigScope scope = packetByteBuf.readEnumConstant(ConfigScope.class);
packetByteBuf.readEnumConstant(ConfigOrigin.class);
configFile.syncToClient((ServerPlayerEntity) packetContext.getPlayer(), ConfigEnvironment.SYNCED, scope, ConfigOrigin.DATAPACK);
}
break;
}
}
});
ServerSidePacketRegistry.INSTANCE.register(TWEED_CLOTH_SYNC_C2S_PACKET, ((packetContext, packetByteBuf) -> {
String fileName = packetByteBuf.readString(32767);
for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
if (configFile.getName().equals(fileName)) {
if (Objects.requireNonNull(packetContext.getPlayer().getServer()).getPermissionLevel(packetContext.getPlayer().getGameProfile()) == 4) {
ConfigEnvironment environment = packetByteBuf.readEnumConstant(ConfigEnvironment.class);
ConfigScope scope = packetByteBuf.readEnumConstant(ConfigScope.class);
configFile.read(packetByteBuf, environment, ConfigScope.SMALLEST, ConfigOrigin.MAIN);
ConfigLoader.updateMainConfigFile(configFile, environment, scope);
} else {
packetByteBuf.clear();
}
break;
}
}
}));
}
use of net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener 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.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener 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);
}
Aggregations