Skip to content

Commit

Permalink
Updated to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocelot5836 committed Nov 22, 2024
1 parent 6757a09 commit a31b7e6
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 101 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
}

version = project.mod_version
Expand Down Expand Up @@ -44,10 +44,10 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation("foundry.veil:Veil-fabric-${project.minecraft_version}:${project.veil_version}") {
modImplementation("foundry.veil:veil-fabric-${project.minecraft_version}:${project.veil_version}") {
exclude group: "maven.modrinth"
}
modRuntimeOnly "maven.modrinth:modmenu:7.2.2"
modRuntimeOnly "maven.modrinth:modmenu:11.0.3"

// modRuntimeOnly "maven.modrinth:sodium:mc1.20.1-0.5.3"
}
Expand Down
11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.11
minecraft_version=1.21
loader_version=0.16.9

# Mod Properties
mod_version=1.0.0
maven_group=foundry
archives_base_name=veil-example-mod

# Dependencies
fabric_version=0.92.0+1.20.1
#veil_version=1.0.0
veil_version=1.0.0.285
fabric_version=0.102.0+1.21
veil_version=1.0.0
#veil_version=1.0.0.10
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/foundry/veil/example/VeilExampleMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VeilExampleMod implements ModInitializer {
private static final ResourceKey<CreativeModeTab> ITEM_GROUP = ResourceKey.create(Registries.CREATIVE_MODE_TAB, VeilExampleMod.path("items"));

public static ResourceLocation path(String path) {
return new ResourceLocation(MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}

@Override
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/foundry/veil/example/VeilExampleModClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package foundry.veil.example;

import com.mojang.blaze3d.platform.NativeImage;
import foundry.veil.Veil;
import foundry.veil.api.client.render.VeilRenderBridge;
import foundry.veil.api.client.render.framebuffer.AdvancedFbo;
import foundry.veil.api.client.render.framebuffer.AdvancedFboAttachment;
import foundry.veil.api.client.render.rendertype.VeilRenderType;
import foundry.veil.api.client.render.texture.DynamicCubemapTexture;
import foundry.veil.api.event.VeilRenderLevelStageEvent;
import foundry.veil.example.blockentity.MapBlockEntity;
Expand All @@ -15,11 +17,14 @@
import foundry.veil.fabric.event.FabricVeilRenderLevelStageEvent;
import foundry.veil.fabric.event.FabricVeilRendererEvent;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import org.lwjgl.glfw.GLFW;

import java.util.Random;

Expand All @@ -32,9 +37,9 @@ public void onInitializeClient() {
BlockEntityRenderers.register(VeilExampleBlocks.MIRROR_BE, MirrorBlockEntityRenderer::new);
FabricVeilRendererEvent.EVENT.register(renderer -> renderer.getEditorManager().add(new VeilExampleModEditor()));

FabricVeilRenderLevelStageEvent.EVENT.register((stage, levelRenderer, bufferSource, poseStack, projectionMatrix, renderTick, partialTicks, camera, frustum) -> {
FabricVeilRenderLevelStageEvent.EVENT.register((stage, levelRenderer, bufferSource, matrixStack, frustumMatrix, projectionMatrix, renderTick, deltaTracker, camera, frustum) -> {
if (stage == VeilRenderLevelStageEvent.Stage.AFTER_LEVEL) {
MirrorBlockEntityRenderer.renderLevel(Minecraft.getInstance().level, projectionMatrix, partialTicks, VeilRenderBridge.create(frustum), camera);
MirrorBlockEntityRenderer.renderLevel(Minecraft.getInstance().level, projectionMatrix, deltaTracker, VeilRenderBridge.create(frustum), camera);
}
});

Expand All @@ -51,6 +56,12 @@ public void onInitializeClient() {
fbo.setColorAttachmentTexture(0, cubemap.getId(), 1);
AdvancedFbo.unbind();
});
ClientTickEvents.START_CLIENT_TICK.register(client -> {
if (GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_U) == GLFW.GLFW_PRESS) {
RenderType test = VeilRenderType.get(VeilExampleMod.path("test"), "test.png");
System.out.println(test);
}
});
}

private static NativeImage genTest(int width, int height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import org.joml.Matrix4fStack;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL32C;

Expand Down Expand Up @@ -40,16 +41,16 @@ public void render(MapBlockEntity blockEntity, float partialTicks, PoseStack pos
return;
}

PoseStack modelViewStack = RenderSystem.getModelViewStack();
modelViewStack.pushPose();
modelViewStack.mulPoseMatrix(poseStack.last().pose());
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
modelViewStack.pushMatrix();
modelViewStack.mul(poseStack.last().pose());
// modelViewStack.scale(25, 20, 25);

this.vbo.bind();
this.vbo.upload(render(20));

shader.applyRenderSystem();
shader.setMatrix("ModelViewMat", modelViewStack.last().pose());
shader.setMatrix("ModelViewMat", modelViewStack);
shader.setup();
if (VeilExampleModEditor.tessellationWireframe()) {
glPolygonMode(GL_FRONT_AND_BACK, GL11C.GL_LINE);
Expand All @@ -66,34 +67,29 @@ public void render(MapBlockEntity blockEntity, float partialTicks, PoseStack pos

VertexBuffer.unbind();

modelViewStack.popPose();
modelViewStack.popMatrix();
}

private static BufferBuilder.RenderedBuffer render(int resolution) {
private static MeshData render(int resolution) {
Tesselator tesselator = RenderSystem.renderThreadTesselator();
BufferBuilder builder = tesselator.getBuilder();
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
BufferBuilder builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);

for (int z = 0; z <= resolution - 1; z++) {
for (int x = 0; x <= resolution - 1; x++) {
builder.vertex(x / (float) resolution, 0, z / (float) resolution)
.uv(x / (float) resolution, z / (float) resolution)
.endVertex();
builder.addVertex(x / (float) resolution, 0, z / (float) resolution)
.setUv(x / (float) resolution, z / (float) resolution);

builder.vertex((x + 1) / (float) resolution, 0, z / (float) resolution)
.uv((x + 1) / (float) resolution, z / (float) resolution)
.endVertex();
builder.addVertex((x + 1) / (float) resolution, 0, z / (float) resolution)
.setUv((x + 1) / (float) resolution, z / (float) resolution);

builder.vertex(x / (float) resolution, 0, (z + 1) / (float) resolution)
.uv(x / (float) resolution, (z + 1) / (float) resolution)
.endVertex();
builder.addVertex(x / (float) resolution, 0, (z + 1) / (float) resolution)
.setUv(x / (float) resolution, (z + 1) / (float) resolution);

builder.vertex((x + 1) / (float) resolution, 0, (z + 1) / (float) resolution)
.uv((x + 1) / (float) resolution, (z + 1) / (float) resolution)
.endVertex();
builder.addVertex((x + 1) / (float) resolution, 0, (z + 1) / (float) resolution)
.setUv((x + 1) / (float) resolution, (z + 1) / (float) resolution);
}
}

return builder.end();
return builder.buildOrThrow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.MultiBufferSource;
Expand Down Expand Up @@ -93,17 +94,15 @@ public void render(MirrorBlockEntity blockEntity, float f, PoseStack poseStack,
poseStack.translate(-0.5, -0.5, -0.5);

Matrix4f pose = poseStack.last().pose();
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder builder = tesselator.getBuilder();
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP);
builder.vertex(pose, 0, 0, 0.125F).color(1.0F, 1.0F, 1.0F, 1.0F).uv(1.0F, 0.0F).uv2(i).endVertex();
builder.vertex(pose, 1, 0, 0.125F).color(1.0F, 1.0F, 1.0F, 1.0F).uv(0.0F, 0.0F).uv2(i).endVertex();
builder.vertex(pose, 1, 1, 0.125F).color(1.0F, 1.0F, 1.0F, 1.0F).uv(0.0F, 1.0F).uv2(i).endVertex();
builder.vertex(pose, 0, 1, 0.125F).color(1.0F, 1.0F, 1.0F, 1.0F).uv(1.0F, 1.0F).uv2(i).endVertex();
BufferBuilder builder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP);
builder.addVertex(pose, 0, 0, 0.125F).setColor(1.0F, 1.0F, 1.0F, 1.0F).setUv(1.0F, 0.0F).setLight(i);
builder.addVertex(pose, 1, 0, 0.125F).setColor(1.0F, 1.0F, 1.0F, 1.0F).setUv(0.0F, 0.0F).setLight(i);
builder.addVertex(pose, 1, 1, 0.125F).setColor(1.0F, 1.0F, 1.0F, 1.0F).setUv(0.0F, 1.0F).setLight(i);
builder.addVertex(pose, 0, 1, 0.125F).setColor(1.0F, 1.0F, 1.0F, 1.0F).setUv(1.0F, 1.0F).setLight(i);

RenderSystem.setShaderColor(0.9F, 0.9F, 0.9F, 1.0F);
RenderSystem.setShaderTexture(0, texture.getId());
VeilExampleRenderTypes.mirror().end(builder, RenderSystem.getVertexSorting());
VeilExampleRenderTypes.mirror().draw(builder.buildOrThrow());
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

poseStack.popPose();
Expand Down Expand Up @@ -143,7 +142,7 @@ private static float dot(BlockPos pos, Vec3i normal, double x, double y, double
return (float) ((pos.getX() + 0.5 - normal.getX() * 0.5 - x) * normal.getX() + (pos.getY() + 0.5 - normal.getY() * 0.5 - y) * normal.getY() + (pos.getZ() + 0.5 - normal.getZ() * 0.5 - z) * normal.getZ());
}

public static void renderLevel(ClientLevel level, Matrix4fc projection, float partialTicks, CullFrustum frustum, Camera camera) {
public static void renderLevel(ClientLevel level, Matrix4fc projection, DeltaTracker deltaTracker, CullFrustum frustum, Camera camera) {
if (VeilLevelPerspectiveRenderer.isRenderingPerspective() || !projection.isFinite()) {
return;
}
Expand Down Expand Up @@ -189,7 +188,7 @@ public static void renderLevel(ClientLevel level, Matrix4fc projection, float pa

calculateObliqueMatrix(RENDER_PROJECTION, plane, RENDER_PROJECTION);

VeilLevelPerspectiveRenderer.render(fbo, RENDER_MODELVIEW, RENDER_PROJECTION, renderPos, VIEW.identity().lookAlong(dir, up), RENDER_DISTANCE, partialTicks);
VeilLevelPerspectiveRenderer.render(fbo, RENDER_MODELVIEW, RENDER_PROJECTION, renderPos, VIEW.identity().lookAlong(dir, up), RENDER_DISTANCE, deltaTracker);
mirror.copy(fbo);
mirror.setRendered(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package foundry.veil.example.mixin.client;

import com.mojang.blaze3d.vertex.PoseStack;
import foundry.veil.Veil;
import foundry.veil.api.client.render.VeilRenderSystem;
import foundry.veil.api.quasar.particle.ParticleEmitter;
import foundry.veil.api.quasar.particle.ParticleSystemManager;
import foundry.veil.ext.EntityExtension;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public abstract class EntityRendererMixin<T extends Entity> {

@Inject(method = "render", at = @At("HEAD"))
public void render(T entity, float pEntityYaw, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, CallbackInfo ci) {
EntityExtension extension = (EntityExtension) entity;
if (entity.isOnFire()) {
if (extension.veil$getEmitters().isEmpty()) {
ParticleSystemManager particleManager = VeilRenderSystem.renderer().getParticleManager();
ParticleEmitter instance = particleManager.createEmitter(Veil.veilPath("basic_smoke"));
if (instance == null) {
return;
}

instance.setAttachedEntity(entity);
// instance.getEmitterSettingsModule().emissionShapeSettings().setDimensions(
// new Vector3f(
// pEntity.getBbWidth(),
// pEntity.getBbHeight(),
// pEntity.getBbWidth()
// )
// );
// instance.setLoop(true);
// instance.setMaxLifetime(5);
// instance.getParticleData().getForces().forEach(force -> {
// if (force instanceof PointForce pf) {
// pf.setPoint(pEntity::position);
// }
// });
// FIXME
extension.veil$addEmitter(instance);
particleManager.addParticleSystem(instance);
} else {
// ((EntityExtension) pEntity).getEmitters().stream().filter(emitter -> emitter.registryName.toString().equals("veil:basic_smoke")).forEach(emitter -> emitter.getEmitterModule().setMaxLifetime(5));
}
} else {
// ((EntityExtension) pEntity).getEmitters().stream().filter(emitter -> emitter.registryName.toString().equals("veil:basic_smoke")).forEach(p -> p.getEmitterModule().setLoop(false));
extension.veil$getEmitters().forEach(emitter -> {
if ("veil:basic_smoke".equals(String.valueOf(emitter.getRegistryName()))) {
emitter.remove();
}
});
extension.veil$getEmitters().removeIf(emitter -> "veil:basic_smoke".equals(String.valueOf(emitter.getRegistryName())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

public class VeilExampleBlocks {

public static final Block MAP = register("map", new MapBlock(BlockBehaviour.Properties.copy(Blocks.BEDROCK)
public static final Block MAP = register("map", new MapBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.BEDROCK)
.noOcclusion()
.isRedstoneConductor(Blocks::never)
.isSuffocating(Blocks::never)),
new Item.Properties());
public static final Block MIRROR = register("mirror", new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.BEDROCK)
public static final Block MIRROR = register("mirror", new MirrorBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.BEDROCK)
.noOcclusion()
.isRedstoneConductor(Blocks::never)
.isSuffocating(Blocks::never)),
Expand Down
Loading

0 comments on commit a31b7e6

Please sign in to comment.