Skip to content

Commit

Permalink
Fix a bug where water would not have the proper color.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Jun 24, 2022
1 parent be4da43 commit 66cfe8f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public int getColor(

final BlockInformation blockInformation = ((BitItem) stack.getItem()).getBlockInformation(stack);
if(blockInformation.getBlockState().getBlock() instanceof LiquidBlock) {
if ((!Minecraft.getInstance().options.keyShift.isUnbound() && Minecraft.getInstance().options.keyShift.isDown()) || (Minecraft.getInstance().getWindow() != null && Screen.hasShiftDown())) {
return -1; //No coloring on liquids when pressing shifts -> Buckets
}

return IFluidManager.getInstance().getFluidColor(new FluidInformation(
blockInformation.getBlockState().getFluidState().getType(),
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public boolean isVisible(

if (a.getBlockState().getBlock() instanceof LiquidBlock && b.getBlockState().getBlock() instanceof LiquidBlock)
{
return a.getBlockState().getFluidState().getType().equals(b.getBlockState().getFluidState().getType()) &&
a.getVariant().equals(b.getVariant());
return !(a.getBlockState().getFluidState().getType().equals(b.getBlockState().getFluidState().getType()) &&
a.getVariant().equals(b.getVariant()));
}

if (a.isAir() && !b.isAir())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import mod.chiselsandbits.client.model.baked.face.FaceManager;
import mod.chiselsandbits.client.model.baked.face.FaceRegion;
import mod.chiselsandbits.client.model.baked.face.model.ModelQuadLayer;
import mod.chiselsandbits.client.util.FloatUtils;
import mod.chiselsandbits.platforms.core.util.constants.Constants;
import mod.chiselsandbits.profiling.ProfilingManager;
import mod.chiselsandbits.utils.ModelUtil;
Expand All @@ -28,25 +27,19 @@
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.IntStream;

@SuppressWarnings("deprecation")
public class ChiseledBlockBakedModel extends BaseBakedBlockModel {

private static final Logger LOGGER = LogManager.getLogger();

public static final ChiseledBlockBakedModel EMPTY = new ChiseledBlockBakedModel(
BlockInformation.AIR,
ChiselRenderType.SOLID,
Expand Down Expand Up @@ -270,6 +263,8 @@ public boolean isUvLocked() {
new ResourceLocation(Constants.MOD_ID, "block")
);

fixColorsInQuad(quad, pc.getColor());

// build it.
if (region.isEdge()) {
builder.getList(myFace).add(quad);
Expand All @@ -284,6 +279,18 @@ public boolean isUvLocked() {
}
}

private void fixColorsInQuad(final BakedQuad quad, final int color) {
final int alpha = (color >> 24) & 0xFF;
final int red = (color >> 16) & 0xFF;
final int green = (color >> 8) & 0xFF;
final int blue = color & 0xFF;
final int renderColor = (alpha << 24) | (blue << 16) | (green << 8) | red;

for (int i = 3; i < (4 * 8); i +=8) {
quad.getVertices()[i] = renderColor;
}
}

private Vector3f createFromVector(FaceRegion faceRegion) {
final Vector3f result = new Vector3f(faceRegion.getMinX(), faceRegion.getMinY(), faceRegion.getMinZ());
result.mul(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private ModelQuadLayer[] buildFaceQuadLayers(
mp[0].setUvs(new float[]{U, 0, 0, 0, U, V, 0, V});
}

mp[0].setTint(0);
mp[0].setLight(0);
return mp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static void renderModelLists(
final Random random = new Random();

// Initialize 3 reusable vectors to avoid needless creation of new ones
final Vector3f normal = new Vector3f(0,0,0);
final Vector3f normal = new Vector3f().copy();
final Vector4f shadedColor = new Vector4f(Vector3f.ZERO);
final Vector4f pos = new Vector4f(Vector3f.ZERO);

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project
modVersion=1.0.150-PATREON
modVersion=1.0.159-PATREON
group=mod.chiselsandbits

# Common
Expand Down

0 comments on commit 66cfe8f

Please sign in to comment.