Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

*.psd filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions psds/contaminated glints.psd
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.fzzyhmstrs.fzzy_config.api.RegisterType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.TexturedRenderLayers;

import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.thedeathlycow.thirstful.client;

import com.thedeathlycow.thirstful.Thirstful;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.BufferAllocator;
import net.minecraft.util.Identifier;

import java.util.Map;

public final class TRenderLayers {
private static final Identifier ITEM_CONTAMINATED_GLINT = Thirstful.id("textures/misc/contaminated_item_glint.png");

private static final RenderLayer CONTAMINATED_GLINT = RenderLayer.of(
"thirstful_glint",
VertexFormats.POSITION_TEXTURE,
VertexFormat.DrawMode.QUADS,
RenderLayer.DEFAULT_BUFFER_SIZE,
RenderLayer.MultiPhaseParameters.builder()
.program(RenderPhase.GLINT_PROGRAM)
.texture(new RenderPhase.Texture(ITEM_CONTAMINATED_GLINT, true, false))
.writeMaskState(RenderPhase.COLOR_MASK)
.cull(RenderPhase.DISABLE_CULLING)
.depthTest(RenderPhase.EQUAL_DEPTH_TEST)
.transparency(RenderPhase.GLINT_TRANSPARENCY)
.texturing(RenderPhase.GLINT_TEXTURING)
.build(false)
);

public static RenderLayer getDirectContaminatedGlint(boolean solid) {
return solid ? CONTAMINATED_GLINT : RenderLayer.getDirectEntityGlint();
}

public static RenderLayer getContaminatedGlint(boolean solid) {
return solid ? CONTAMINATED_GLINT : RenderLayer.getEntityGlint();
}

public static void buildMap(Map<RenderLayer, BufferAllocator> map) {
assignToAllocator(map, CONTAMINATED_GLINT);
}

private static void assignToAllocator(Map<RenderLayer, BufferAllocator> map, RenderLayer layer) {
map.put(layer, new BufferAllocator(layer.getExpectedBufferSize()));
}

private TRenderLayers() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.thedeathlycow.thirstful.mixin.client;

import com.thedeathlycow.thirstful.client.TRenderLayers;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.client.render.BufferBuilderStorage;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.BufferAllocator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BufferBuilderStorage.class)
public class BufferBuilderStorageMixin {
@Inject(
method = "assignBufferBuilder",
at = @At("RETURN")
)
private static void buildRenderLayers(
Object2ObjectLinkedOpenHashMap<RenderLayer, BufferAllocator> map,
RenderLayer layer,
CallbackInfo ci
) {
TRenderLayers.buildMap(map);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.thedeathlycow.thirstful.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.thedeathlycow.thirstful.client.TRenderLayers;
import com.thedeathlycow.thirstful.item.component.PollutantComponent;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexConsumers;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ItemRenderer.class)
public class ItemRendererMixin {
@WrapOperation(
method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/item/ItemRenderer;getDirectItemGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lnet/minecraft/client/render/VertexConsumer;"
)
)
private VertexConsumer getDirectConsumer(
VertexConsumerProvider provider,
RenderLayer layer,
boolean solid,
boolean glint,
Operation<VertexConsumer> original,
ItemStack stack
) {
if (!PollutantComponent.get(stack).clean()) {
return VertexConsumers.union(
provider.getBuffer(TRenderLayers.getDirectContaminatedGlint(solid)),
provider.getBuffer(layer)
);
}

return original.call(provider, layer, solid, glint);
}
}
17 changes: 9 additions & 8 deletions src/client/resources/thirstful.client.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"required": true,
"package": "com.thedeathlycow.thirstful.mixin.client",
"compatibilityLevel": "JAVA_21",
"client": [
"ExampleClientMixin"
],
"injectors": {
"defaultRequire": 1
"required": true,
"package": "com.thedeathlycow.thirstful.mixin.client",
"compatibilityLevel": "JAVA_21",
"client": [
"BufferBuilderStorageMixin",
"ItemRendererMixin"
],
"injectors": {
"defaultRequire": 1
}
}
1 change: 0 additions & 1 deletion src/main/java/com/thedeathlycow/thirstful/Thirstful.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static void initialize() {
TItems.initialize();
TStatusEffects.initialize();
TDataComponentTypes.initialize();
WaterPollution.initialize();
TPointsOfInterest.initialize();
if (ModIntegration.isScorchfulLoaded()) {
ScorchfulIntegration.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void polluteCollectedWater(ItemStack stack, World world, BlockPos
TDataComponentTypes.POLLUTANTS,
PollutantComponent.DEFAULT
);
PollutantComponent pollutants = WaterPollution.POLLUTANT_CONTAINER.find(world, sourcePos, null);
PollutantComponent pollutants = WaterPollution.findPollutants(world, sourcePos);
Objects.requireNonNull(pollutants);
stack.set(TDataComponentTypes.POLLUTANTS, current.mixWith(pollutants));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.thedeathlycow.thirstful.Thirstful;
import com.thedeathlycow.thirstful.config.common.WaterPollutionConfig;
import com.thedeathlycow.thirstful.registry.TDataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipAppender;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.network.RegistryByteBuf;
Expand All @@ -14,6 +16,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import javax.management.openmbean.TabularData;
import java.util.function.Consumer;

public record PollutantComponent(
Expand Down Expand Up @@ -96,6 +99,10 @@ public PollutantComponent mixWith(PollutantComponent other) {
);
}

public static PollutantComponent get(ItemStack stack) {
return stack.getOrDefault(TDataComponentTypes.POLLUTANTS, DEFAULT);
}

public boolean checkedDirty(WaterPollutionConfig config) {
return config.enableDirtiness() && this.dirty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.thedeathlycow.thirstful.item.ConsumeItemCallback;
import com.thedeathlycow.thirstful.item.ItemStackCreationCallback;
import com.thedeathlycow.thirstful.item.component.PollutantComponent;
import net.minecraft.component.ComponentHolder;
import net.minecraft.component.ComponentMapImpl;
import net.minecraft.component.DataComponentTypes;
Expand All @@ -17,6 +18,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ItemStack.class)
public abstract class ItemStackMixin implements ComponentHolder {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,20 @@
package com.thedeathlycow.thirstful.thirst;

import com.thedeathlycow.thirstful.Thirstful;
import com.thedeathlycow.thirstful.config.common.WaterPollutionConfig;
import com.thedeathlycow.thirstful.item.component.PollutantComponent;
import com.thedeathlycow.thirstful.registry.tag.TBiomeTags;
import com.thedeathlycow.thirstful.registry.tag.TItemTags;
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import org.jetbrains.annotations.Nullable;

public final class WaterPollution {
public static final PollutantComponent FALLBACK = new PollutantComponent(true, true, false);

public static final BlockApiLookup<PollutantComponent, Void> POLLUTANT_CONTAINER = BlockApiLookup.get(
Thirstful.id("water_pollutants"),
PollutantComponent.class,
Void.class
);

public static void initialize() {
Thirstful.LOGGER.debug("Initialized Thirstful pollutant lookup API");
POLLUTANT_CONTAINER.registerForBlocks(WaterPollution::waterSourceLookup, Blocks.WATER);
POLLUTANT_CONTAINER.registerFallback((world, pos, state, blockEntity, context) -> FALLBACK);
}

public static boolean canCarryPollutants(ItemStack stack) {
return stack.isIn(TItemTags.CAN_BE_POLLUTED) && !stack.isIn(TItemTags.CAN_NOT_BE_POLLUTED);
}

private static PollutantComponent waterSourceLookup(
World world,
BlockPos pos,
BlockState state,
@Nullable BlockEntity blockEntity,
Void context
) {
public static PollutantComponent findPollutants(World world, BlockPos pos) {
boolean dirty = true;
boolean contaminated = true;
boolean salty = false;
Expand Down
Binary file modified src/main/resources/assets/thirstful/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"texture": {
"blur": true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading