Skip to content

Commit

Permalink
Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Dec 30, 2023
1 parent ae87abc commit 6d69a3f
Show file tree
Hide file tree
Showing 23 changed files with 622 additions and 85 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

version = b12.0.3
version = b12.0.4
maven_group = net.ludocrypt
archives_base_name = limlib
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public abstract class PostEffect {

public abstract Codec<? extends PostEffect> getCodec();

public static void init() {
Registry.register(PostEffect.POST_EFFECT_CODEC, new Identifier("limlib", "static"), StaticPostEffect.CODEC);
Registry.register(PostEffect.POST_EFFECT_CODEC, new Identifier("limlib", "empty"), EmptyPostEffect.CODEC);
}

public abstract boolean shouldRender();

public abstract void beforeRender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;

import org.quiltmc.loader.api.ModInternal;
import org.quiltmc.loader.api.minecraft.ClientOnly;

import com.mojang.serialization.Codec;
Expand Down Expand Up @@ -30,10 +31,20 @@ public abstract class DimensionEffects {
public static final RegistryKey<Registry<DimensionEffects>> DIMENSION_EFFECTS_KEY = RegistryKey
.ofRegistry(new Identifier("limlib/dimension_effects"));

@ModInternal
public static final AtomicReference<HolderLookup<DimensionEffects>> MIXIN_WORLD_LOOKUP = new AtomicReference<HolderLookup<DimensionEffects>>();

public abstract Codec<? extends DimensionEffects> getCodec();

public static void init() {
Registry
.register(DimensionEffects.DIMENSION_EFFECTS_CODEC, new Identifier("limlib", "static"),
StaticDimensionEffects.CODEC);
Registry
.register(DimensionEffects.DIMENSION_EFFECTS_CODEC, new Identifier("limlib", "empty"),
EmptyDimensionEffects.CODEC);
}

@ClientOnly
public abstract DimensionVisualEffects getDimensionEffects();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public abstract class DistortionEffect {

public abstract Codec<? extends DistortionEffect> getCodec();

public static void init() {
Registry
.register(DistortionEffect.DISTORTION_EFFECT_CODEC, new Identifier("limlib", "static"),
StaticDistortionEffect.CODEC);
}

/**
* Whether or not a Sound Event should be ignored
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public abstract class ReverbEffect {

public abstract Codec<? extends ReverbEffect> getCodec();

public static void init() {
Registry.register(ReverbEffect.REVERB_EFFECT_CODEC, new Identifier("limlib", "static"), StaticReverbEffect.CODEC);
}

/**
* Whether or not a Sound Event should be ignored
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/ludocrypt/limlib/api/skybox/Skybox.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public abstract class Skybox {

public abstract Codec<? extends Skybox> getCodec();

public static void init() {
Registry.register(Skybox.SKYBOX_CODEC, new Identifier("limlib", "empty"), EmptySkybox.CODEC);
Registry.register(Skybox.SKYBOX_CODEC, new Identifier("limlib", "textured"), TexturedSkybox.CODEC);
}

@ClientOnly
public abstract void renderSky(WorldRenderer worldRenderer, MinecraftClient client, MatrixStack matrices,
Matrix4f projectionMatrix, float tickDelta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import java.util.Optional;

import net.ludocrypt.limlib.api.world.FunctionMap;
import net.ludocrypt.limlib.api.world.LimlibHelper;
import net.ludocrypt.limlib.api.world.Manipulation;
import net.ludocrypt.limlib.api.world.NbtGroup;
import net.ludocrypt.limlib.api.world.NbtPlacerUtil;
import net.ludocrypt.limlib.api.world.nbt.FunctionMap;
import net.ludocrypt.limlib.api.world.nbt.NbtGroup;
import net.ludocrypt.limlib.api.world.nbt.NbtPlacerUtil;
import net.ludocrypt.limlib.api.world.nbt.NbtTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.loot.LootTables;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.resource.ResourceManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;
Expand All @@ -24,6 +26,7 @@ public abstract class AbstractNbtChunkGenerator extends LiminalChunkGenerator {

public final NbtGroup nbtGroup;
public final FunctionMap<Identifier, NbtPlacerUtil, ResourceManager> structures;
public NbtTags tags;

public AbstractNbtChunkGenerator(BiomeSource biomeSource, NbtGroup nbtGroup) {
this(biomeSource, nbtGroup, new FunctionMap<Identifier, NbtPlacerUtil, ResourceManager>(NbtPlacerUtil::load));
Expand All @@ -37,6 +40,14 @@ public AbstractNbtChunkGenerator(BiomeSource biomeSource, NbtGroup nbtGroup,
this.nbtGroup.fill(structures);
}

public void loadTags(ServerWorld world) {

if (this.tags == null) {
this.tags = NbtTags.parse(this.nbtGroup, world.getServer().getResourceManager());
}

}

public void generateNbt(ChunkRegion region, BlockPos at, Identifier id) {
generateNbt(region, at, id, Manipulation.NONE);
}
Expand Down Expand Up @@ -78,36 +89,32 @@ public void generateNbt(ChunkRegion region, BlockPos offset, BlockPos from, Bloc

protected void modifyStructure(ChunkRegion region, BlockPos pos, BlockState state,
Optional<NbtCompound> blockEntityNbt) {
this.modifyStructure(region, pos, state, blockEntityNbt, Block.NOTIFY_ALL);
this.modifyStructure(region, pos, state, blockEntityNbt, Block.NOTIFY_ALL, 1);
}

protected void modifyStructure(ChunkRegion region, BlockPos pos, BlockState state, Optional<NbtCompound> blockEntityNbt,
int update) {
int update, int depth) {

if (!state.isAir()) {

if (state.isOf(Blocks.BARRIER)) {
region.setBlockState(pos, Blocks.AIR.getDefaultState(), update, 1);
} else {
region.setBlockState(pos, state, update, 1);
}
if (state.isOf(Blocks.STRUCTURE_VOID)) {
return;
}

if (blockEntityNbt.isPresent()) {
BlockEntity blockEntity = region.getBlockEntity(pos);
region.setBlockState(pos, state, update, depth);

if (blockEntity != null) {
if (blockEntityNbt.isPresent()) {
BlockEntity blockEntity = region.getBlockEntity(pos);

if (state.isOf(blockEntity.getCachedState().getBlock())) {
blockEntity.readNbt(blockEntityNbt.get());
}
if (blockEntity != null) {

if (state.isOf(blockEntity.getCachedState().getBlock())) {
blockEntity.readNbt(blockEntityNbt.get());
}

if (blockEntity instanceof LootableContainerBlockEntity lootTable) {
lootTable
.setLootTable(this.getContainerLootTable(lootTable), region.getSeed() + LimlibHelper.blockSeed(pos));
}
}

if (blockEntity instanceof LootableContainerBlockEntity lootTable) {
lootTable
.setLootTable(this.getContainerLootTable(lootTable), region.getSeed() + LimlibHelper.blockSeed(pos));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import com.google.common.collect.Maps;

import net.ludocrypt.limlib.api.world.maze.storage.NbtSerializer;
import net.ludocrypt.limlib.api.world.nbt.ImmutableNbtCompound;
import net.ludocrypt.limlib.api.world.nbt.NbtSerializer;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
Expand Down Expand Up @@ -56,7 +57,6 @@ public String toString() {

for (int y = 0; y < height; y++) {
row.append(cellState(width - x, y).toString());

}

row.append("\n");
Expand All @@ -66,21 +66,22 @@ public String toString() {
}

@Override
public NbtCompound write(NbtCompound nbt) {
public ImmutableNbtCompound write() {
NbtCompound nbt = new NbtCompound();

for (int x = 0; x < width; x++) {

for (int y = 0; y < height; y++) {
nbt.put(x + "." + y, this.cellState(x, y).write(new NbtCompound()));
nbt.put(x + "." + y, this.cellState(x, y).write());
}

}

return nbt;
return new ImmutableNbtCompound(nbt);
}

@Override
public MazeComponent read(NbtCompound nbt) {
public MazeComponent read(ImmutableNbtCompound nbt) {

for (int x = 0; x < width; x++) {

Expand Down Expand Up @@ -264,12 +265,14 @@ public String toString() {
}

@Override
public NbtCompound write(NbtCompound nbt) {
public ImmutableNbtCompound write() {
NbtCompound nbt = new NbtCompound();

nbt.putBoolean("up", up);
nbt.putBoolean("down", down);
nbt.putBoolean("left", left);
nbt.putBoolean("right", right);
nbt.put("pos", this.position.write(new NbtCompound()));
nbt.put("pos", this.position.write());

NbtCompound extraData = new NbtCompound();

Expand All @@ -279,11 +282,11 @@ public NbtCompound write(NbtCompound nbt) {

nbt.put("extra", extraData);

return nbt;
return new ImmutableNbtCompound(nbt);
}

@Override
public CellState read(NbtCompound nbt) {
public CellState read(ImmutableNbtCompound nbt) {
this.up = nbt.getBoolean("up");
this.down = nbt.getBoolean("down");
this.left = nbt.getBoolean("left");
Expand Down Expand Up @@ -425,15 +428,17 @@ public String toString() {
}

@Override
public NbtCompound write(NbtCompound nbt) {
public ImmutableNbtCompound write() {
NbtCompound nbt = new NbtCompound();

nbt.putInt("x", x);
nbt.putInt("y", y);

return nbt;
return new ImmutableNbtCompound(nbt);
}

@Override
public Vec2i read(NbtCompound nbt) {
public Vec2i read(ImmutableNbtCompound nbt) {
this.x = nbt.getInt("x");
this.y = nbt.getInt("y");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.ludocrypt.limlib.api.world.maze.MazeComponent;
import net.ludocrypt.limlib.api.world.maze.MazeComponent.Vec2i;
import net.ludocrypt.limlib.api.world.maze.MazeGenerator;
import net.ludocrypt.limlib.api.world.nbt.ImmutableNbtCompound;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void read() {
.get(id)
.getMazes()
.put(regionPos.add(pos), new MazeComponent(mazeRaw.getInt("width"), mazeRaw.getInt("height"))
.read(mazeRaw.getCompound("maze")));
.read(new ImmutableNbtCompound(mazeRaw.getCompound("maze"))));
}

} catch (IOException | NullPointerException e) {
Expand Down Expand Up @@ -99,7 +100,7 @@ public void serialize(String mazeId, Vec2i pos, MazeComponent maze) {
}

NbtCompound compound = new NbtCompound();
NbtCompound mazeCompound = maze.write(new NbtCompound());
NbtCompound mazeCompound = maze.write();

compound.put("maze", mazeCompound);
compound.putInt("width", maze.width);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.api.world;
package net.ludocrypt.limlib.api.world.nbt;

import java.util.Map;
import java.util.Optional;
Expand Down
Loading

0 comments on commit 6d69a3f

Please sign in to comment.