Skip to content

Commit

Permalink
Added a layer of jukeboxes and raised the end by two chunks . also se…
Browse files Browse the repository at this point in the history
…t up for custom render types (currently useless)
  • Loading branch information
FloofHips committed Oct 7, 2024
1 parent 980c28a commit 56c87ae
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/thebeyond/TheBeyond.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thebeyond;

import com.thebeyond.common.registry.*;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;

import com.mojang.logging.LogUtils;
Expand Down Expand Up @@ -47,5 +48,4 @@ public TheBeyond(IEventBus modEventBus, ModContainer modContainer) {
private void commonSetup(final FMLCommonSetupEvent event) {
// Some common setup code
}

}
41 changes: 41 additions & 0 deletions src/main/java/com/thebeyond/client/BeyondRenderTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.thebeyond.client;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.serialization.MapCodec;
import com.thebeyond.TheBeyond;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceProvider;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterNamedRenderTypesEvent;
import net.neoforged.neoforge.registries.DeferredRegister;

import static net.minecraft.client.renderer.RenderStateShard.*;

@EventBusSubscriber(modid = TheBeyond.MODID, bus = EventBusSubscriber.Bus.MOD)
public class BeyondRenderTypes {
public static final RenderStateShard.ShaderStateShard TRANSLUCENT_PROXIMITY_SHADER = new RenderStateShard.ShaderStateShard(() -> BeyondShaders.translucentProximityShader);

@SubscribeEvent
public static void onRegisterNamedRenderTypes(RegisterNamedRenderTypesEvent event) {

RenderType TRANSLUCENT_PROXIMITY = RenderType.create(TheBeyond.MODID + ":" +"translucent_proximity", DefaultVertexFormat.NEW_ENTITY,
VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_SOLID_SHADER)
.setTextureState(BLOCK_SHEET)
.setTransparencyState(ADDITIVE_TRANSPARENCY)
.setCullState(NO_CULL)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));

event.register(ResourceLocation.fromNamespaceAndPath(TheBeyond.MODID, "translucent_proximity"), RenderType.translucent(), TRANSLUCENT_PROXIMITY);

}

}
23 changes: 23 additions & 0 deletions src/main/java/com/thebeyond/client/BeyondShaders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.thebeyond.client;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.thebeyond.TheBeyond;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceProvider;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterShadersEvent;

import java.io.IOException;

@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
public class BeyondShaders {
public static ShaderInstance translucentProximityShader;
@SubscribeEvent
public static void onRegisterShaders(RegisterShadersEvent event) throws IOException {
ResourceProvider resourceProvider = event.getResourceProvider();
event.registerShader(new ShaderInstance(resourceProvider, ResourceLocation.fromNamespaceAndPath(TheBeyond.MODID,"translucent_proximity_shader"), DefaultVertexFormat.NEW_ENTITY), shader -> translucentProximityShader = shader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BeyondEndChunkGenerator extends NoiseBasedChunkGenerator {
private final PerlinSimplexNoise globalHOffsetNoise;
private final PerlinSimplexNoise globalVOffsetNoise;
private final PerlinSimplexNoise globalCOffsetNoise;
private final double worldHeight = 160;
private final double worldHeight = 192;

public BeyondEndChunkGenerator(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> settings) {
super(biomeSource, settings);
Expand All @@ -63,8 +63,9 @@ public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState
int startX = chunkPos.getMinBlockX();
int startZ = chunkPos.getMinBlockZ();
int sizeX = 16;
int sizeY = 160;
int sizeY = 160; // Original height before shifting
int sizeZ = 16;
int terrainYOffset = 32; // Raise terrain by 32 blocks

// Octave stuff, don't touch this. PLEASE!
int numOctaves = 4;
Expand All @@ -76,17 +77,31 @@ public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState
double verticalBaseScale;
double threshold;
double cycleHeight;

for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
for (int y = 0; y < sizeY; y++) {
int globalX = startX + x;
int globalZ = startZ + z;
int globalX = startX + x;
int globalZ = startZ + z;

// 2D noise for y=0 layer with noteblocks
double noteBlockNoise = simplexNoise.getValue(globalX * 0.1, globalZ * 0.1); // Generate 2D noise

// Layer at y=0
if (noteBlockNoise > 0.0) {
chunk.setBlockState(new BlockPos(globalX, 0, globalZ), Blocks.JUKEBOX.defaultBlockState(), false);
chunk.setBlockState(new BlockPos(globalX, 1, globalZ), Blocks.JUKEBOX.defaultBlockState(), false);

}

// Continue generating terrain noise for other Y levels, starting from y=32
for (int y = 1; y < sizeY; y++) { // Skip y=0 and y=1 since they're handled separately
int shiftedY = y + terrainYOffset; // Shift terrain by 32 blocks upwards

//min = 0.005, max = 0.015
horizontalBaseScale = globalNoiseOffset(0.005, 0.015,globalX * 0.000001,globalZ * 0.000001, globalHOffsetNoise);
verticalBaseScale = globalNoiseOffset(0.005, 0.015,globalX * 0.00001,globalZ * 0.00001, globalVOffsetNoise);
cycleHeight = globalNoiseOffset(10, 100, globalX * 0.0001,globalZ * 0.0001, globalCOffsetNoise);
threshold = globalNoiseOffset(0.01, 0.6, globalX * 0.0002,globalZ * 0.0002, globalCOffsetNoise);
horizontalBaseScale = globalNoiseOffset(0.005, 0.015, globalX * 0.000001, globalZ * 0.000001, globalHOffsetNoise);
verticalBaseScale = globalNoiseOffset(0.005, 0.015, globalX * 0.00001, globalZ * 0.00001, globalVOffsetNoise);
cycleHeight = globalNoiseOffset(10, 100, globalX * 0.0001, globalZ * 0.0001, globalCOffsetNoise);
threshold = globalNoiseOffset(0.01, 0.6, globalX * 0.0002, globalZ * 0.0002, globalCOffsetNoise);

double noiseValue = 0.0;
double amplitude = 1.0;
Expand All @@ -97,7 +112,7 @@ public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState
for (int octave = 0; octave < numOctaves; octave++) {
double hScale = horizontalBaseScale * frequency;
double vScale = verticalBaseScale * frequency;
double octaveNoise = simplexNoise.getValue(globalX * hScale, y * vScale, globalZ * hScale);
double octaveNoise = simplexNoise.getValue(globalX * hScale, shiftedY * vScale, globalZ * hScale);

noiseValue += octaveNoise * amplitude;
maxAmplitude += amplitude;
Expand All @@ -110,10 +125,10 @@ public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState
noiseValue /= maxAmplitude;

// Apply sine wave gaps
double densityModifier = cyclicDensity(y, cycleHeight);
double densityModifier = cyclicDensity(shiftedY, cycleHeight);
noiseValue *= densityModifier;

BlockPos blockPos = new BlockPos(globalX, y, globalZ);
BlockPos blockPos = new BlockPos(globalX, shiftedY, globalZ);
double finalValue = edgeGradient(blockPos.getY(), worldHeight, noiseValue);
if (finalValue > threshold) {
chunk.setBlockState(blockPos, Blocks.END_STONE.defaultBlockState(), false);
Expand All @@ -125,6 +140,8 @@ public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState
return chunk;
});
}


private double cyclicDensity(int y, double cycleHeight) {
double normalizedY = (y % cycleHeight) / cycleHeight;
if (normalizedY < 0.8) {
Expand All @@ -138,14 +155,17 @@ private double edgeGradient(double y, double worldHeight, double noiseValue) {
double gradientBottom = 1.0;
double gradientTop = 1.0;

// Bottom up gradient density.. deleter thing... from 0 to 32
if (y <= 32) {
gradientBottom = y / 32.0;
// Adjust the bottom gradient to start at y=32 and go up to y=64
if (y <= 64) { // Adjust the gradient range to be between 32 and 64
gradientBottom = (y - 32) / 32.0; // Normalize the value to a range of 0 to 1 from y=32 to y=64
if (y < 32) {
gradientBottom = 0.0; // Below y=32, the gradient should be 0
}
}

// Same thing from the top
if (y >= (worldHeight - 64)) {
gradientTop = (worldHeight - y) / 64;
gradientTop = (worldHeight - y) / 64.0;
}

return gradientBottom * gradientTop * noiseValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 150

uniform vec2 iResolution; // Resolution of the screen
uniform sampler2D Sampler0; // The texture to which the highlight mask will be applied

in vec2 texCoord0; // Texture coordinates input
out vec4 fragColor; // Final fragment color output

// Hash function to create a pseudo-random value
float Hash(vec2 p) {
vec3 p2 = vec3(p.xy, 1.0);
return fract(sin(dot(p2, vec3(37.1, 61.7, 12.4))) * 758.5453123);
}

// 2D noise function using the hash function
float noise(in vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f *= f * (3.0 - 2.0 * f);

return mix(mix(Hash(i + vec2(0., 0.)), Hash(i + vec2(1., 0.)), f.x),
mix(Hash(i + vec2(0., 1.)), Hash(i + vec2(1., 1.)), f.x),
f.y);
}

// Fractal Brownian Motion function for more complexity in noise
float fbm(vec2 p) {
float v = 0.0;
v += noise(p * 1.0) * 0.1; // Frequency 1
v += noise(p * 2.0) * 0.025; // Frequency 2
v += noise(p * 4.0) * 0.125; // Frequency 3
v += noise(p * 8.0) * 0.0625; // Frequency 4
return v;
}

void main() {
// Normalize pixel coordinates
vec2 uv = texCoord0; // Use the incoming texture coordinates

// Calculate the distance from the center (0.5, 0.5)
float dist = distance(uv, vec2(0.5)); // Center of the texture

// Scale the distance for noise input (adjusted for a smaller highlight effect)
float scaledDist = dist * 15.0; // Increase the multiplier for a smaller effect

// Calculate the noise value based on the scaled distance
float k = clamp(fbm(vec2(scaledDist)), 0.1, 1.0) - 0.1; // Calculate noise value and clamp
k = k * 2.0; // Scale the noise down

// Generate a color based on the noise value
vec3 col = vec3(k, k, k); // Grayscale color for highlight

// Sample the original texture (optional)
vec4 textureColor = texture(Sampler0, uv);

// Output the highlight mask (you can blend this with the original texture if needed)
fragColor = vec4(textureColor.rgb + col * 0.5, 1.0); // Add highlight to the original texture color
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"vertex": "rendertype_cutout",
"fragment": "rendertype_cutout",
"samplers": [
{
"name": "Sampler0"
},
{
"name": "Sampler2"
}
],
"uniforms": [
{
"name": "ModelViewMat",
"type": "matrix4x4",
"count": 16,
"values": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
]
},
{
"name": "ProjMat",
"type": "matrix4x4",
"count": 16,
"values": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
]
},
{
"name": "ChunkOffset",
"type": "float",
"count": 3,
"values": [
0,
0,
0
]
},
{
"name": "ColorModulator",
"type": "float",
"count": 4,
"values": [
1,
1,
1,
1
]
},
{
"name": "FogStart",
"type": "float",
"count": 1,
"values": [
0
]
},
{
"name": "FogEnd",
"type": "float",
"count": 1,
"values": [
1
]
},
{
"name": "FogColor",
"type": "float",
"count": 4,
"values": [
0,
0,
0,
0
]
},
{
"name": "FogShape",
"type": "int",
"count": 1,
"values": [
0
]
}
]
}
Loading

0 comments on commit 56c87ae

Please sign in to comment.