Skip to content

Commit

Permalink
Update 4.0.2
Browse files Browse the repository at this point in the history
- Hook for Dimension Music
- Fix Level Storage
- Maze Chunk Generator
- Post Processing Shader Hook
  • Loading branch information
LudoCrypt committed Jan 30, 2022
1 parent 9221e08 commit 5176b5a
Show file tree
Hide file tree
Showing 15 changed files with 651 additions and 87 deletions.
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
maven {
url 'https://ladysnake.jfrog.io/artifactory/mods'
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

def includeMod(String dep) {
dependencies.modImplementation(dep)
dependencies.include(dep)
modImplementation "io.github.ladysnake:satin:${satin_version}"
}

processResources {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ minecraft_version=1.18.1
yarn_mappings=1.18.1+build.18
loader_version=0.12.12
fabric_version=0.45.2+1.18
satin_version=1.7.2

mod_version = 4.0.1
mod_version = 4.0.2
maven_group = net.ludocrypt
archives_base_name = limlib
archives_base_name = limlib
11 changes: 11 additions & 0 deletions src/main/java/net/ludocrypt/limlib/api/LimLibClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package net.ludocrypt.limlib.api;

import ladysnake.satin.api.event.ShaderEffectRenderCallback;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.ludocrypt.limlib.api.render.LiminalShader;
import net.ludocrypt.limlib.api.sound.RandomSoundEmitter;
import net.ludocrypt.limlib.impl.render.LiminalShaderRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -16,6 +19,14 @@ public class LimLibClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ShaderEffectRenderCallback.EVENT.register(tickDelta -> {
MinecraftClient client = MinecraftClient.getInstance();
LiminalShader shader = LiminalShaderRegistry.getCurrent(client);
if (shader.shouldRender(client, tickDelta)) {
shader.getShader(client, tickDelta).render(tickDelta);
}
});

ClientTickEvents.START_WORLD_TICK.register((world) -> {
MinecraftClient client = MinecraftClient.getInstance();
ClientPlayerEntity player = client.player;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/net/ludocrypt/limlib/api/render/LiminalShader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.ludocrypt.limlib.api.render;

import ladysnake.satin.api.managed.ManagedShaderEffect;
import ladysnake.satin.api.managed.ShaderEffectManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;

public abstract class LiminalShader {

public abstract boolean shouldRender(MinecraftClient client, float tickdelta);

public abstract ManagedShaderEffect getShader(MinecraftClient client, float tickdelta);

public static class SimpleShader extends LiminalShader {

private final ManagedShaderEffect shader;

public SimpleShader(Identifier shader) {
this(ShaderEffectManager.getInstance().manage(shader));
}

public SimpleShader(ManagedShaderEffect shader) {
this.shader = shader;
}

@Override
public boolean shouldRender(MinecraftClient client, float tickdelta) {
return true;
}

@Override
public ManagedShaderEffect getShader(MinecraftClient client, float tickdelta) {
return shader;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package net.ludocrypt.limlib.api.world;

import java.util.HashMap;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.server.world.ServerLightingProvider;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructureManager;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.gen.GenerationStep.Carver;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.Blender;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import net.minecraft.world.gen.feature.StructureFeature;

public abstract class LiminalChunkGenerator extends ChunkGenerator {

public final long worldSeed;
public final MultiNoiseSampler multiNoiseSampler;

public LiminalChunkGenerator(BiomeSource biomeSource, long worldSeed) {
this(biomeSource, new FlatMultiNoiseSampler(0.0F), worldSeed);
}

public LiminalChunkGenerator(BiomeSource biomeSource, MultiNoiseSampler multiNoiseSampler, long worldSeed) {
super(biomeSource, biomeSource, new StructuresConfig(Optional.empty(), new HashMap<StructureFeature<?>, StructureConfig>()), worldSeed);
this.multiNoiseSampler = multiNoiseSampler;
this.worldSeed = worldSeed;
}

@Override
public MultiNoiseSampler getMultiNoiseSampler() {
return this.multiNoiseSampler;
}

@Override
public void carve(ChunkRegion var1, long var2, BiomeAccess var4, StructureAccessor var5, Chunk var6, Carver var7) {
}

@Override
public void buildSurface(ChunkRegion var1, StructureAccessor var2, Chunk var3) {
}

@Override
public void populateEntities(ChunkRegion var1) {
}

@Override
public CompletableFuture<Chunk> populateNoise(Executor var1, Blender var2, StructureAccessor var3, Chunk var4) {
throw new UnsupportedOperationException("populateNoise should never be called in " + this.getClass());
}

@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
BlockState[] states = new BlockState[world.getHeight()];
for (int i = 0; i < states.length; i++) {
states[i] = Blocks.AIR.getDefaultState();
}
return new VerticalBlockSample(0, states);
}

// impl

public abstract CompletableFuture<Chunk> populateNoise(Executor executor, Chunk chunk, ChunkStatus targetStatus, ServerWorld world, ChunkRegion chunkRegion, StructureManager structureManager, ServerLightingProvider lightingProvider);

public int getChunkRadius() {
return 0;
}

}
108 changes: 30 additions & 78 deletions src/main/java/net/ludocrypt/limlib/api/world/NbtChunkGenerator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package net.ludocrypt.limlib.api.world;

import java.util.HashMap;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

import net.ludocrypt.limlib.mixin.BlockEntityAccessor;
import net.minecraft.block.Block;
Expand All @@ -12,69 +9,31 @@
import net.minecraft.block.entity.BarrelBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.loot.LootTables;
import net.minecraft.server.world.ServerLightingProvider;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.gen.GenerationStep.Carver;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.Blender;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import net.minecraft.world.gen.feature.StructureFeature;

public abstract class NbtChunkGenerator extends ChunkGenerator {

public final HashMap<String, NbtPlacerUtil> structures = new HashMap<String, NbtPlacerUtil>(30);
public abstract class NbtChunkGenerator extends LiminalChunkGenerator {

public final long worldSeed;
public final HashMap<String, NbtPlacerUtil> structures = new HashMap<String, NbtPlacerUtil>(30);
public final Identifier nbtId;
public final MultiNoiseSampler multiNoiseSampler;

public NbtChunkGenerator(BiomeSource biomeSource, MultiNoiseSampler multiNoiseSampler, long worldSeed, Identifier nbtId) {
super(biomeSource, biomeSource, new StructuresConfig(Optional.empty(), new HashMap<StructureFeature<?>, StructureConfig>()), worldSeed);
this.multiNoiseSampler = multiNoiseSampler;
this.worldSeed = worldSeed;
public NbtChunkGenerator(BiomeSource biomeSource, long worldSeed, Identifier nbtId) {
super(biomeSource, worldSeed);
this.nbtId = nbtId;
}

@Override
public MultiNoiseSampler getMultiNoiseSampler() {
return multiNoiseSampler;
}

@Override
public void carve(ChunkRegion var1, long var2, BiomeAccess var4, StructureAccessor var5, Chunk var6, Carver var7) {
}

@Override
public void buildSurface(ChunkRegion var1, StructureAccessor var2, Chunk var3) {
}

@Override
public void populateEntities(ChunkRegion var1) {

}

@Override
public CompletableFuture<Chunk> populateNoise(Executor var1, Blender var2, StructureAccessor var3, Chunk var4) {
throw new UnsupportedOperationException("populateNoise should never be called in " + this.getClass());
public NbtChunkGenerator(BiomeSource biomeSource, MultiNoiseSampler multiNoiseSampler, long worldSeed, Identifier nbtId) {
super(biomeSource, multiNoiseSampler, worldSeed);
this.nbtId = nbtId;
}

public abstract CompletableFuture<Chunk> populateNoise(Executor executor, Chunk chunk, ChunkStatus targetStatus, ServerWorld world, ChunkRegion chunkRegion, StructureManager structureManager, ServerLightingProvider lightingProvider);

@Override
public int getSeaLevel() {
return 0;
Expand All @@ -85,14 +44,9 @@ public int getMinimumY() {
return 0;
}

@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
BlockState[] states = new BlockState[world.getHeight()];
for (int i = 0; i < states.length; i++) {
states[i] = Blocks.AIR.getDefaultState();
}
return new VerticalBlockSample(0, states);
}
// impl

public abstract void storeStructures(ServerWorld world);

protected void store(String id, ServerWorld world) {
structures.put(id, NbtPlacerUtil.load(world.getServer().getResourceManager(), new Identifier(this.nbtId.getNamespace(), "nbt/" + this.nbtId.getPath() + "/" + id + ".nbt")).get());
Expand All @@ -109,34 +63,32 @@ protected void generateNbt(ChunkRegion region, BlockPos at, String id) {
}

protected void generateNbt(ChunkRegion region, BlockPos at, String id, BlockRotation rotation) {
structures.get(id).rotate(rotation).generateNbt(region, at, (pos, state, nbt) -> {
if (!state.isAir()) {
if (state.isOf(Blocks.BARREL)) {
region.setBlockState(pos, state, Block.NOTIFY_ALL, 1);
if (region.getBlockEntity(pos)instanceof BarrelBlockEntity barrel) {
barrel.setLootTable(this.getBarrelLootTable(), region.getSeed() + MathHelper.hashCode(pos));
}
} else if (state.isOf(Blocks.BARRIER)) {
region.setBlockState(pos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL, 1);
} else {
region.setBlockState(pos, state, Block.NOTIFY_ALL, 1);
structures.get(id).rotate(rotation).generateNbt(region, at, (pos, state, nbt) -> this.modifyStructure(region, pos, state, nbt)).spawnEntities(region, at, rotation);
}

protected void modifyStructure(ChunkRegion region, BlockPos pos, BlockState state, NbtCompound nbt) {
if (!state.isAir()) {
if (state.isOf(Blocks.BARREL)) {
region.setBlockState(pos, state, Block.NOTIFY_ALL, 1);
if (region.getBlockEntity(pos)instanceof BarrelBlockEntity barrel) {
barrel.setLootTable(this.getBarrelLootTable(), region.getSeed() + MathHelper.hashCode(pos));
}
BlockEntity blockEntity = region.getBlockEntity(pos);
if (blockEntity != null) {
if (state.isOf(blockEntity.getCachedState().getBlock())) {
((BlockEntityAccessor) blockEntity).callWriteNbt(nbt);
}
} else if (state.isOf(Blocks.BARRIER)) {
region.setBlockState(pos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL, 1);
} else {
region.setBlockState(pos, state, Block.NOTIFY_ALL, 1);
}
BlockEntity blockEntity = region.getBlockEntity(pos);
if (blockEntity != null) {
if (state.isOf(blockEntity.getCachedState().getBlock())) {
((BlockEntityAccessor) blockEntity).callWriteNbt(nbt);
}
}
}).spawnEntities(region, at, rotation);
}
}

protected Identifier getBarrelLootTable() {
return LootTables.SIMPLE_DUNGEON_CHEST;
}

public int getChunkRadius() {
return 1;
}

}
Loading

0 comments on commit 5176b5a

Please sign in to comment.