Skip to content

Commit

Permalink
Water progress
Browse files Browse the repository at this point in the history
* Return a block instead of a BlockMatch (at least for now) for populating mc_entity
  • Loading branch information
mitchej123 committed Dec 10, 2023
1 parent 8b3fffd commit 1e32eb0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink;
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.shaderpack.materialmap.BlockMatch;
import net.coderbot.iris.sodium.block_context.BlockContextHolder;
import net.coderbot.iris.sodium.block_context.ChunkBuildBuffersExt;
import net.coderbot.iris.sodium.block_context.ContextAwareVertexWriter;
Expand Down Expand Up @@ -54,17 +53,17 @@ public ChunkBuildBuffers(ChunkVertexType vertexType) {
this.offset = new ChunkModelOffset();

for (BlockRenderPass pass : BlockRenderPass.VALUES) {
int passId = pass.ordinal();
final int passId = pass.ordinal();

VertexBufferBuilder[] buffers = this.buffersByLayer[passId];
final VertexBufferBuilder[] buffers = this.buffersByLayer[passId];

for (ModelQuadFacing facing : ModelQuadFacing.VALUES) {
buffers[facing.ordinal()] = new VertexBufferBuilder(vertexType.getBufferVertexFormat(), EXPECTED_BUFFER_SIZE / ModelQuadFacing.COUNT);
}
}

if(AngelicaConfig.enableIris) {
Object2IntMap<BlockMatch> blockMatches = BlockRenderingSettings.INSTANCE.getBlockMatches();
final Object2IntMap<Block> blockMatches = BlockRenderingSettings.INSTANCE.getBlockMatches();

if (blockMatches != null) {
this.iris$contextHolder = new BlockContextHolder(blockMatches);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.coderbot.iris.shaderpack.materialmap.BlockEntry;
import net.coderbot.iris.shaderpack.materialmap.BlockMatch;
import net.coderbot.iris.shaderpack.materialmap.BlockRenderType;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.minecraft.block.Block;
Expand All @@ -15,11 +14,10 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

public class BlockMaterialMapping {
public static Object2IntMap<BlockMatch> createBlockStateIdMap(Int2ObjectMap<List<BlockEntry>> blockPropertiesMap) {
Object2IntMap<BlockMatch> blockMatches = new Object2IntOpenHashMap<>();
public static Object2IntMap<Block> createBlockStateIdMap(Int2ObjectMap<List<BlockEntry>> blockPropertiesMap) {
Object2IntMap<Block> blockMatches = new Object2IntOpenHashMap<>();

blockPropertiesMap.forEach((intId, entries) -> {
for (BlockEntry entry : entries) {
Expand Down Expand Up @@ -59,30 +57,31 @@ private static RenderLayer convertBlockToRenderType(BlockRenderType type) {
};
}

private static void addBlock(BlockEntry entry, Object2IntMap<BlockMatch> idMap, int intId) {
private static void addBlock(BlockEntry entry, Object2IntMap<Block> idMap, int intId) {
final NamespacedId id = entry.getId();
final ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName());

Block block = (Block) Block.blockRegistry.getObject(resourceLocation.toString());
final Block block = (Block) Block.blockRegistry.getObject(resourceLocation.toString());

// If the block doesn't exist, by default the registry will return AIR. That probably isn't what we want.
// TODO: Assuming that Registry.BLOCK.getDefaultId() == "minecraft:air" here
if (block == null || block == Blocks.air) {
return;
}

Set<Integer> metas = entry.getMetas();
idMap.put(block, intId);

// All metas match
if (metas.isEmpty()) {
idMap.putIfAbsent(new BlockMatch(block, null), intId);
return;
}

// A subset of metas match
for(int meta : metas) {
idMap.putIfAbsent(new BlockMatch(block, meta), intId);
}
// Set<Integer> metas = entry.getMetas();
// // All metas match
// if (metas.isEmpty()) {
// idMap.putIfAbsent(new BlockMatch(block, null), intId);
// return;
// }
//
// // A subset of metas match
// for(int meta : metas) {
// idMap.putIfAbsent(new BlockMatch(block, meta), intId);
// }
}

// We ignore generics here, the actual types don't matter because we just convert
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package net.coderbot.iris.block_rendering;

import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
import lombok.Getter;
import net.coderbot.iris.shaderpack.materialmap.BlockMatch;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.minecraft.block.Block;
import org.jetbrains.annotations.Nullable;
Expand All @@ -16,7 +15,7 @@ public class BlockRenderingSettings {

@Getter
private boolean reloadRequired;
private Object2IntMap<BlockMatch> blockMatches;
private Object2IntMap<Block> blockMatches;
private Map<Block, RenderLayer> blockTypeIds;
private Object2IntFunction<NamespacedId> entityIds;
private float ambientOcclusionLevel;
Expand All @@ -39,7 +38,7 @@ public void clearReloadRequired() {
}

@Nullable
public Object2IntMap<BlockMatch> getBlockMatches() {
public Object2IntMap<Block> getBlockMatches() {
return blockMatches;
}

Expand All @@ -53,7 +52,7 @@ public Object2IntFunction<NamespacedId> getEntityIds() {
return entityIds;
}

public void setBlockMatches(Object2IntMap<BlockMatch> blockIds) {
public void setBlockMatches(Object2IntMap<Block> blockIds) {
if (this.blockMatches != null && this.blockMatches.equals(blockIds)) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/coderbot/iris/shaderpack/IdMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ private static Int2ObjectMap<List<BlockEntry>> parseBlockMap(Properties properti
Int2ObjectMap<List<BlockEntry>> entriesById = new Int2ObjectOpenHashMap<>();

properties.forEach((keyObject, valueObject) -> {
String key = (String) keyObject;
String value = (String) valueObject;
final String key = (String) keyObject;
final String value = (String) valueObject;

if (!key.startsWith(keyPrefix)) {
// Not a valid line, ignore it
return;
}

int intId;
final int intId;

try {
intId = Integer.parseInt(key.substring(keyPrefix.length()));
Expand All @@ -193,7 +193,7 @@ private static Int2ObjectMap<List<BlockEntry>> parseBlockMap(Properties properti
return;
}

List<BlockEntry> entries = new ArrayList<>();
final List<BlockEntry> entries = new ArrayList<>();

// Split on whitespace groups, not just single spaces
for (String part : value.split("\\s+")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.coderbot.iris.shaderpack.materialmap;

import lombok.Getter;
import net.coderbot.iris.Iris;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -9,6 +10,7 @@
import java.util.Objects;
import java.util.Set;

@Getter
public class BlockEntry {
private final NamespacedId id;
private final Set<Integer> metas;
Expand All @@ -30,7 +32,7 @@ public static BlockEntry parse(@NotNull String entry) {
}

// We can assume that this array is of at least array length because the input string is non-empty.
String[] splitStates = entry.split(":");
final String[] splitStates = entry.split(":");

// Trivial case: no states, no namespace
if (splitStates.length == 1) {
Expand Down Expand Up @@ -61,8 +63,8 @@ public static BlockEntry parse(@NotNull String entry) {
}

// Complex case: One or more states involved...
int statesStart;
NamespacedId id;
final int statesStart;
final NamespacedId id;

if (StringUtils.isNumeric(splitStates[1].substring(0, 1))) {
// We have an entry of the form "stone:0"
Expand All @@ -74,11 +76,11 @@ public static BlockEntry parse(@NotNull String entry) {
id = new NamespacedId(splitStates[0], splitStates[1]);
}

Set<Integer> metas = new HashSet<>();
final Set<Integer> metas = new HashSet<>();

for (int index = statesStart; index < splitStates.length; index++) {
// Parse out one or more metadata ids
String[] metaParts = splitStates[index].split(", ");
final String[] metaParts = splitStates[index].split(", ");

for (String metaPart : metaParts) {
try {
Expand All @@ -93,19 +95,11 @@ public static BlockEntry parse(@NotNull String entry) {
return new BlockEntry(id, metas);
}

public NamespacedId getId() {
return id;
}

public Set<Integer> getMetas() {
return metas;
}

@Override
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockEntry that = (BlockEntry) o;
final BlockEntry that = (BlockEntry) o;
return Objects.equals(id, that.id) && Objects.equals(metas, that.metas);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import net.coderbot.iris.shaderpack.materialmap.BlockMatch;
import net.minecraft.block.Block;

public class BlockContextHolder {
private final Object2IntMap<BlockMatch> blockMatches;
private final Object2IntMap<Block> blockMatches;

public int localPosX;
public int localPosY;
Expand All @@ -21,7 +20,7 @@ public BlockContextHolder() {
this.renderType = -1;
}

public BlockContextHolder(Object2IntMap<BlockMatch> idMap) {
public BlockContextHolder(Object2IntMap<Block> idMap) {
this.blockMatches = idMap;
this.blockId = -1;
this.renderType = -1;
Expand Down

0 comments on commit 1e32eb0

Please sign in to comment.