Source dirs

This commit is contained in:
SD 2021-01-10 07:38:01 +05:30
parent df9762297f
commit 96204976b8
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
18 changed files with 108 additions and 91 deletions

View file

@ -46,6 +46,15 @@ dependencies {
version "4.0.0+alpha.4"
archivesBaseName = "dimensional-doors"
sourceSets {
main {
java {
srcDir 'src/main/schematics'
srcDir 'src/main/registry'
}
}
}
processResources {
filesMatching("fabric.mod.json") {
expand "version": project.version

View file

@ -2,9 +2,10 @@ package org.dimdev.dimdoors;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.client.ModRendering;
import org.dimdev.dimdoors.client.ModSkyRendering;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.entity.MonolithEntity;
import org.dimdev.dimdoors.fluid.ModFluids;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
@ -16,7 +17,8 @@ public class DimensionalDoorsClientInitializer implements ClientModInitializer {
@Override
public void onInitializeClient() {
ModEntityTypes.initClient();
ModRendering.initClient();
ModSkyRendering.initClient();
ModFluids.initClient();
ModBlockEntityTypes.initClient();
ModBlocks.initClient();

View file

@ -6,6 +6,7 @@ import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.command.ModCommands;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.fluid.ModFluids;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import org.dimdev.dimdoors.pockets.SchematicV2Handler;
@ -66,6 +67,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
ModEntityTypes.init();
ModBlockEntityTypes.init();
ModCommands.init();
ModFluids.init();
ModSoundEvents.init();
ModConfig.deserialize();

View file

@ -1,89 +0,0 @@
package org.dimdev.dimdoors.client;
import java.util.function.Function;
import io.github.waterpicker.openworlds.OpenWorlds;
import org.dimdev.dimdoors.fluid.ModFluids;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.Sprite;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockRenderView;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
@Environment(EnvType.CLIENT)
public class ModRendering {
public static void initClient() {
OpenWorlds.registerSkyRenderer(ModDimensions.POCKET_TYPE_KEY, new CustomSkyProvider(null, null, new Vec3i(0, 0, 0)));
OpenWorlds.registerSkyRenderer(ModDimensions.LIMBO_TYPE_KEY, new LimboSkyProvider());
OpenWorlds.registerCloudRenderer(ModDimensions.LIMBO_TYPE_KEY, (minecraftClient, matrixStack, v, v1, v2, v3) -> {
});
OpenWorlds.registerSkyProperty(ModDimensions.LIMBO_TYPE_KEY, new LimboSkyProperties());
setupFluidRendering(ModFluids.ETERNAL_FLUID, ModFluids.FLOWING_ETERNAL_FLUID, new Identifier("dimdoors:eternal_fluid"));
}
public static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId) {
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(PlayerScreenHandler.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(PlayerScreenHandler.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 16777215;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler);
}
}

View file

@ -0,0 +1,20 @@
package org.dimdev.dimdoors.client;
import io.github.waterpicker.openworlds.OpenWorlds;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.util.math.Vec3i;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class ModSkyRendering {
public static void initClient() {
OpenWorlds.registerSkyRenderer(ModDimensions.POCKET_TYPE_KEY, new CustomSkyProvider(null, null, new Vec3i(0, 0, 0)));
OpenWorlds.registerSkyRenderer(ModDimensions.LIMBO_TYPE_KEY, new LimboSkyProvider());
OpenWorlds.registerCloudRenderer(ModDimensions.LIMBO_TYPE_KEY, (minecraftClient, matrixStack, v, v1, v2, v3) -> {
});
OpenWorlds.registerSkyProperty(ModDimensions.LIMBO_TYPE_KEY, new LimboSkyProperties());
}
}

View file

@ -1,8 +1,25 @@
package org.dimdev.dimdoors.fluid;
import java.util.function.Function;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.Sprite;
import net.minecraft.fluid.FlowableFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockRenderView;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
public class ModFluids {
public static final FlowableFluid ETERNAL_FLUID = register("dimdoors:eternal_fluid", new EternalFluid.Still());
@ -11,4 +28,60 @@ public class ModFluids {
private static <T extends Fluid> T register(String string, T fluid) {
return Registry.register(Registry.FLUID, string, fluid);
}
public static void init() {
}
public static void initClient() {
setupFluidRendering(ModFluids.ETERNAL_FLUID, ModFluids.FLOWING_ETERNAL_FLUID, new Identifier("dimdoors:eternal_fluid"));
}
private static void setupFluidRendering(Fluid still, Fluid flowing, final Identifier textureFluidId) {
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(PlayerScreenHandler.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(PlayerScreenHandler.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 16777215;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler);
}
}