diff --git a/.gitattributes b/.gitattributes index 097f9f9..73e4133 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/psds/contaminated glints.psd b/psds/contaminated glints.psd new file mode 100644 index 0000000..6fe40d6 --- /dev/null +++ b/psds/contaminated glints.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af00b6e9865cafd23d1bc0810647e2f007ecbe689c4b7d186b929d0f6254503f +size 182216 diff --git a/src/client/java/com/thedeathlycow/thirstful/ThirstfulClient.java b/src/client/java/com/thedeathlycow/thirstful/ThirstfulClient.java index 5b6d226..22f40f4 100644 --- a/src/client/java/com/thedeathlycow/thirstful/ThirstfulClient.java +++ b/src/client/java/com/thedeathlycow/thirstful/ThirstfulClient.java @@ -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; diff --git a/src/client/java/com/thedeathlycow/thirstful/block/TBlockColors.java b/src/client/java/com/thedeathlycow/thirstful/block/TBlockColors.java index 4b364ef..d9983e9 100644 --- a/src/client/java/com/thedeathlycow/thirstful/block/TBlockColors.java +++ b/src/client/java/com/thedeathlycow/thirstful/block/TBlockColors.java @@ -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; diff --git a/src/client/java/com/thedeathlycow/thirstful/client/TRenderLayers.java b/src/client/java/com/thedeathlycow/thirstful/client/TRenderLayers.java new file mode 100644 index 0000000..b0939eb --- /dev/null +++ b/src/client/java/com/thedeathlycow/thirstful/client/TRenderLayers.java @@ -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 map) { + assignToAllocator(map, CONTAMINATED_GLINT); + } + + private static void assignToAllocator(Map map, RenderLayer layer) { + map.put(layer, new BufferAllocator(layer.getExpectedBufferSize())); + } + + private TRenderLayers() { + + } +} \ No newline at end of file diff --git a/src/client/java/com/thedeathlycow/thirstful/mixin/client/BufferBuilderStorageMixin.java b/src/client/java/com/thedeathlycow/thirstful/mixin/client/BufferBuilderStorageMixin.java new file mode 100644 index 0000000..7952dc6 --- /dev/null +++ b/src/client/java/com/thedeathlycow/thirstful/mixin/client/BufferBuilderStorageMixin.java @@ -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 map, + RenderLayer layer, + CallbackInfo ci + ) { + TRenderLayers.buildMap(map); + } +} \ No newline at end of file diff --git a/src/client/java/com/thedeathlycow/thirstful/mixin/client/ExampleClientMixin.java b/src/client/java/com/thedeathlycow/thirstful/mixin/client/ExampleClientMixin.java deleted file mode 100644 index 157cdab..0000000 --- a/src/client/java/com/thedeathlycow/thirstful/mixin/client/ExampleClientMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.thedeathlycow.thirstful.mixin.client; - -import net.minecraft.client.MinecraftClient; -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(MinecraftClient.class) -public class ExampleClientMixin { - @Inject(at = @At("HEAD"), method = "run") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftClient.run()V - } -} \ No newline at end of file diff --git a/src/client/java/com/thedeathlycow/thirstful/mixin/client/ItemRendererMixin.java b/src/client/java/com/thedeathlycow/thirstful/mixin/client/ItemRendererMixin.java new file mode 100644 index 0000000..ee5ca3e --- /dev/null +++ b/src/client/java/com/thedeathlycow/thirstful/mixin/client/ItemRendererMixin.java @@ -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 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); + } +} \ No newline at end of file diff --git a/src/client/resources/thirstful.client.mixins.json b/src/client/resources/thirstful.client.mixins.json index 66a6329..c853114 100644 --- a/src/client/resources/thirstful.client.mixins.json +++ b/src/client/resources/thirstful.client.mixins.json @@ -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 } } \ No newline at end of file diff --git a/src/main/java/com/thedeathlycow/thirstful/Thirstful.java b/src/main/java/com/thedeathlycow/thirstful/Thirstful.java index 0f94a0a..d1747d7 100644 --- a/src/main/java/com/thedeathlycow/thirstful/Thirstful.java +++ b/src/main/java/com/thedeathlycow/thirstful/Thirstful.java @@ -38,7 +38,6 @@ public static void initialize() { TItems.initialize(); TStatusEffects.initialize(); TDataComponentTypes.initialize(); - WaterPollution.initialize(); TPointsOfInterest.initialize(); if (ModIntegration.isScorchfulLoaded()) { ScorchfulIntegration.initialize(); diff --git a/src/main/java/com/thedeathlycow/thirstful/item/WaterCollection.java b/src/main/java/com/thedeathlycow/thirstful/item/WaterCollection.java index 26bdefc..b17089f 100644 --- a/src/main/java/com/thedeathlycow/thirstful/item/WaterCollection.java +++ b/src/main/java/com/thedeathlycow/thirstful/item/WaterCollection.java @@ -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)); } diff --git a/src/main/java/com/thedeathlycow/thirstful/item/component/PollutantComponent.java b/src/main/java/com/thedeathlycow/thirstful/item/component/PollutantComponent.java index 996d5b6..c57f379 100644 --- a/src/main/java/com/thedeathlycow/thirstful/item/component/PollutantComponent.java +++ b/src/main/java/com/thedeathlycow/thirstful/item/component/PollutantComponent.java @@ -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; @@ -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( @@ -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; } diff --git a/src/main/java/com/thedeathlycow/thirstful/mixin/common/item/ItemStackMixin.java b/src/main/java/com/thedeathlycow/thirstful/mixin/common/item/ItemStackMixin.java index e472fc6..78a38e4 100644 --- a/src/main/java/com/thedeathlycow/thirstful/mixin/common/item/ItemStackMixin.java +++ b/src/main/java/com/thedeathlycow/thirstful/mixin/common/item/ItemStackMixin.java @@ -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; @@ -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 { diff --git a/src/main/java/com/thedeathlycow/thirstful/thirst/WaterPollution.java b/src/main/java/com/thedeathlycow/thirstful/thirst/WaterPollution.java index 6965f23..b2743ba 100644 --- a/src/main/java/com/thedeathlycow/thirstful/thirst/WaterPollution.java +++ b/src/main/java/com/thedeathlycow/thirstful/thirst/WaterPollution.java @@ -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 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; diff --git a/src/main/resources/assets/thirstful/icon.png b/src/main/resources/assets/thirstful/icon.png index 57e96de..57425cb 100644 Binary files a/src/main/resources/assets/thirstful/icon.png and b/src/main/resources/assets/thirstful/icon.png differ diff --git a/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png b/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png new file mode 100644 index 0000000..4143a6a --- /dev/null +++ b/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3e5725b241a65b9062b3da93cccc8f0e350dc127affadb9d055a71491fbbbbb +size 15366 diff --git a/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png.mcmeta b/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png.mcmeta new file mode 100644 index 0000000..e38a5ad --- /dev/null +++ b/src/main/resources/assets/thirstful/textures/misc/contaminated_item_glint.png.mcmeta @@ -0,0 +1,5 @@ +{ + "texture": { + "blur": true + } +} diff --git a/src/main/resources/assets/thirstful/textures/misc/contaminted_entity_glint.png b/src/main/resources/assets/thirstful/textures/misc/contaminted_entity_glint.png new file mode 100644 index 0000000..cb22cec --- /dev/null +++ b/src/main/resources/assets/thirstful/textures/misc/contaminted_entity_glint.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b73535af59679c9f9d90684767d5314ab82632acd8f5df70447ca4de9ed38575 +size 12811