add env fluid with unused textures as they look like shit

This commit is contained in:
Robin 2024-06-30 16:51:37 +02:00
parent 48daa3d43d
commit 2a2d257f01
12 changed files with 268 additions and 2 deletions

View File

@ -6,7 +6,7 @@ plugins {
idea
`maven-publish`
id("io.freefair.lombok") version "8.6"
id ("net.neoforged.gradle.userdev") version ("7.0.151")
id ("net.neoforged.gradle.userdev") version ("7.0.152")
id("com.diffplug.spotless") version "7.0.0.BETA1"
}

View File

@ -12,7 +12,7 @@ minecraftVersion=1.21.0
# as they do not follow standard versioning conventions.
minecraftVersionRange=[1.21.0,1.22)
# The Neo version must agree with the Minecraft version to get a valid artifact
neoVersion=21.0.37-beta
neoVersion=21.0.42-beta
# The Neo version range can use any version of Neo as bounds
neoVersionRange=[21,)
# The loader version range can only use the major version of FML as bounds

View File

@ -25,6 +25,8 @@ import robaertschi.environmenttech.data.components.ETComponents;
import robaertschi.environmenttech.data.recipes.ETRecipes;
import robaertschi.environmenttech.level.block.ETBlocks;
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
import robaertschi.environmenttech.level.fluid.ETFluidTypes;
import robaertschi.environmenttech.level.fluid.ETFluids;
import robaertschi.environmenttech.level.item.ETItems;
import robaertschi.environmenttech.level.particle.ETParticles;
import robaertschi.environmenttech.menu.ETMenus;
@ -54,6 +56,8 @@ public class EnvironmentTech
ETMenus.init(modEventBus);
ETParticles.init(modEventBus);
ETComponents.init(modEventBus);
ETFluids.init(modEventBus);
ETFluidTypes.init(modEventBus);
ETCompat.init(modEventBus);
NeoForge.EVENT_BUS.register(this);

View File

@ -20,6 +20,7 @@ import robaertschi.environmenttech.data.components.ETComponents;
import robaertschi.environmenttech.data.components.FilledComponent;
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
import robaertschi.environmenttech.level.block.entity.renderer.EnvCollectorRenderer;
import robaertschi.environmenttech.level.block.entity.renderer.EnvDistributorRenderer;
import robaertschi.environmenttech.level.item.ETItems;
import robaertschi.environmenttech.level.particle.ETParticles;
import robaertschi.environmenttech.menu.ETMenus;
@ -44,6 +45,7 @@ public class ETClient {
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(ETBlockEntities.ENV_COLLECTOR_BLOCK_ENTITY.get(), EnvCollectorRenderer::new);
event.registerBlockEntityRenderer(ETBlockEntities.ENV_DISTRIBUTOR_BLOCK_ENTITY.get(), EnvDistributorRenderer::new);
}
@SubscribeEvent

View File

@ -0,0 +1,144 @@
package robaertschi.environmenttech.client;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.fluids.FluidStack;
import org.joml.Vector3f;
import javax.annotation.ParametersAreNonnullByDefault;
public class RenderUtils {
public static void vertex(VertexConsumer consumer,
PoseStack stack,
float x, float y, float z,
float u, float v,
int packedLight,
int color) {
consumer.addVertex(stack.last().pose(), x, y, z)
.setColor(color)
.setUv(u, v)
.setLight(packedLight)
.setNormal(1, 0, 0);
}
public static void quad(VertexConsumer consumer,
PoseStack stack,
int packedLight, int color,
float x0, float y0, float z0,
float x1, float y1, float z1,
float u0, float v0, float u1, float v1
) {
vertex(consumer, stack, x0, y0, z0, u0, v0, packedLight, color);
vertex(consumer, stack, x0, y1, z1, u0, v1, packedLight, color);
vertex(consumer, stack, x1, y1, z1, u1, v1, packedLight, color);
vertex(consumer, stack, x1, y0, z0, u1, v0, packedLight, color);
}
public static void quadReversed(VertexConsumer consumer,
PoseStack stack,
int packedLight, int color,
float x0, float y0, float z0,
float x1, float y1, float z1,
float u0, float v0, float u1, float v1
) {
vertex(consumer, stack, x0, y0, z0, u0, v0, packedLight, color);
vertex(consumer, stack, x1, y0, z1, u1, v0, packedLight, color);
vertex(consumer, stack, x1, y1, z1, u1, v1, packedLight, color);
vertex(consumer, stack, x0, y1, z0, u0, v1, packedLight, color);
}
public static void cuboid(
VertexConsumer consumer,
PoseStack stack,
BlockPos fromPos,
Vector3f start, Vector3f end,
TextureAtlasSprite sprite,
int packedLight, int color
) {
var relativeStart = Vec3.atLowerCornerWithOffset(fromPos, -start.x(), -start.y(), -start.z());
float width = end.x() - start.x();
float height = end.y() - start.y();
float depth = end.z() - start.z();
float u0 = sprite.getU0();
float v0 = sprite.getV0();
float u1 = sprite.getU1();
float v1 = sprite.getV1();
stack.pushPose();
stack.translate(-relativeStart.x(), -relativeStart.y(), -relativeStart.z());
// Front
quad(consumer, stack, packedLight, color, 0, 0, 0, width, height, 0, u0, v0, u1, v1);
// Back
quad(consumer, stack, packedLight, color, width, 0, depth, 0, height, depth, u0, v0, u1, v1);
// Top
quad(consumer, stack, packedLight, color, 0, height, 0, width, height, depth, u0, v0, u1, v1);
// Bottom
quad(consumer, stack, packedLight, color, 0, 0, depth, width, 0, 0, u0, v0, u1, v1);
// Right
quadReversed(consumer, stack, packedLight, color, 0, 0, 0, 0, height, depth, u0, v0, u1, v1);
// Left
quadReversed(consumer, stack, packedLight, color, width, 0, depth, width, height, 0, u0, v0, u1, v1);
stack.popPose();
}
@ParametersAreNonnullByDefault
public static void renderFluidBox(PoseStack poseStack,
MultiBufferSource bufferSource,
int packedLight,
RenderType renderType,
ResourceLocation stillTexture,
int tintColor,
long amount,
long capacity,
Vector3f start,
Vector3f end,
BlockPos blockPos
) {
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(stillTexture);
VertexConsumer consumer = bufferSource.getBuffer(renderType);
float percent = ((float) amount / (float) capacity);
end.y = start.y() + (percent * (end.y() - start.y()));
cuboid(consumer, poseStack, blockPos, start, end, sprite, packedLight, tintColor);
}
public static void renderFluidBox(FluidStack fluidStack,
PoseStack stack,
MultiBufferSource bufferSource,
int packedLight,
long amount,
long capacity,
Vector3f start,
Vector3f end,
BlockPos blockPos
) {
IClientFluidTypeExtensions extensions = IClientFluidTypeExtensions.of(fluidStack.getFluid());
ResourceLocation stillTexture = extensions.getStillTexture();
int tintColor = extensions.getTintColor(fluidStack);
RenderType renderType = ItemBlockRenderTypes.getRenderLayer(fluidStack.getFluid().defaultFluidState());
renderFluidBox(
stack, bufferSource, packedLight, renderType, stillTexture, tintColor, amount, capacity, start, end, blockPos
);
}
}

View File

@ -0,0 +1,26 @@
package robaertschi.environmenttech.level.block.entity.renderer;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import robaertschi.environmenttech.level.block.entity.EnvDistributorBlockEntity;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class EnvDistributorRenderer implements BlockEntityRenderer<EnvDistributorBlockEntity> {
@SuppressWarnings("unused")
public EnvDistributorRenderer(BlockEntityRendererProvider.Context context) {}
@Override
public void render(EnvDistributorBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) {
poseStack.pushPose();
poseStack.translate(0, 5, 0);
poseStack.popPose();
}
}

View File

@ -0,0 +1,56 @@
package robaertschi.environmenttech.level.fluid;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import robaertschi.environmenttech.client.renderer.EnvStorageRenderer;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
import static robaertschi.environmenttech.ET.MODID;
public class ETFluidTypes {
public static final ResourceLocation WATER_STILL_RL = ResourceLocation.withDefaultNamespace("block/water_still");
public static final ResourceLocation WATER_FLOWING_RL = ResourceLocation.withDefaultNamespace("block/water_flow");
public static final DeferredRegister<FluidType> FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.FLUID_TYPES, MODID);
public static final DeferredHolder<FluidType, FluidType> ENV = FLUID_TYPES.register("env",
resourceLocation -> new FluidType(
FluidType.Properties.create().density(15).viscosity(5)
) {
@Override
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
consumer.accept(new IClientFluidTypeExtensions() {
@Override
public int getTintColor() {
return EnvStorageRenderer.to;
}
@Override
public ResourceLocation getFlowingTexture() {
return WATER_FLOWING_RL;
}
@Override
public ResourceLocation getStillTexture() {
return WATER_STILL_RL;
}
});
}
}
);
public static void init(IEventBus modEventBus) {
FLUID_TYPES.register(modEventBus);
}
}

View File

@ -0,0 +1,26 @@
package robaertschi.environmenttech.level.fluid;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.fluids.BaseFlowingFluid;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import static robaertschi.environmenttech.ET.MODID;
public class ETFluids {
public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(BuiltInRegistries.FLUID, MODID);
public static final DeferredHolder<Fluid, Fluid> ENV_FLOWING = FLUIDS.register("env_flowing", resourceLocation -> new BaseFlowingFluid.Flowing(ETFluids.ENV_PROPERTIES));
public static final DeferredHolder<Fluid, Fluid> ENV_STILL = FLUIDS.register("env", resourceLocation -> new BaseFlowingFluid.Source(ETFluids.ENV_PROPERTIES));
public static final BaseFlowingFluid.Properties ENV_PROPERTIES = new BaseFlowingFluid.Properties(ETFluidTypes.ENV, ENV_STILL, ENV_FLOWING)
.slopeFindDistance(2).levelDecreasePerBlock(2);
public static void init(IEventBus modEventBus) {
FLUIDS.register(modEventBus);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,3 @@
{
"animation": {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}