diff --git a/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java b/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java index fae8e8f7..d4dd4e02 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java +++ b/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java @@ -20,6 +20,10 @@ public class BatEyesApplicator { return 0.6F; } return initial; + /*StatusEffectInstance statusEffectInstance = entity.getStatusEffect(StatusEffects.NIGHT_VISION); + return !statusEffectInstance.isDurationBelow(200) + ? 1.0F + : 0.7F + MathHelper.sin(((float)statusEffectInstance.getDuration() - tickDelta) * (float) Math.PI * 0.2F) * 0.3F;*/ } public void enable() { diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java b/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java index c0a69d71..5f2cf24b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java @@ -24,10 +24,12 @@ public final class LeavesAdditionsModel extends ForwardingBakedModel { ModelLoadingPlugin.register(ctx -> { ctx.modifyModelAfterBake().register(ModelModifier.WRAP_PHASE, (model, context) -> { Identifier id = context.resourceId(); - if (!id.getPath().endsWith("_flowering") || !(Registries.BLOCK.get(id.withPath(p -> p.replace("block/", "").replace("_flowering", ""))) instanceof FruitBearingBlock)) { + if (model == null || id == null + || !id.getPath().endsWith("_flowering") + || !(Registries.BLOCK.get(id.withPath(p -> p.replace("block/", "").replace("_flowering", ""))) instanceof FruitBearingBlock)) { return model; } - return model == null ? null : new LeavesAdditionsModel(model); + return new LeavesAdditionsModel(model); }); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java index 9d876127..53511d13 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java @@ -41,7 +41,7 @@ public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredica static Identifier getModelId(ItemConvertible item) { Identifier id = Registries.ITEM.getId(item.asItem()); - return id.withPath(p -> p + "_in_inventory"); + return id.withPath(p -> "item/" + p + "_in_inventory"); } public static TexturedModelData getTexturedModelData() { diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/shader/ViewportShader.java b/src/main/java/com/minelittlepony/unicopia/client/render/shader/ViewportShader.java index 68464ef2..d2da8c9e 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/shader/ViewportShader.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/shader/ViewportShader.java @@ -16,6 +16,7 @@ import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.*; +import net.minecraft.client.render.RenderTickCounter; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.SynchronousResourceReloader; import net.minecraft.util.Identifier; @@ -27,8 +28,8 @@ public class ViewportShader implements SynchronousResourceReloader, Identifiable public static final ViewportShader INSTANCE = new ViewportShader(); - public static final Identifier CREEPER_SHADER = Identifier.ofVanilla("shaders/post/invert.json"); - public static final Identifier DESATURATION_SHADER = Identifier.ofVanilla("shaders/post/desaturate.json"); + public static final Identifier CREEPER_SHADER = Identifier.ofVanilla("shaders/post/creeper.json"); + public static final Identifier DESATURATION_SHADER = Unicopia.id("shaders/post/desaturate.json"); private final MinecraftClient client = MinecraftClient.getInstance(); @@ -70,7 +71,7 @@ public class ViewportShader implements SynchronousResourceReloader, Identifiable } } - public void render(float tickDelta) { + public void render(RenderTickCounter tickCounter) { if (Unicopia.getConfig().disableShaders.get()) { return; } @@ -85,7 +86,7 @@ public class ViewportShader implements SynchronousResourceReloader, Identifiable corruption = 1 - corruption + 0.05F; shader.setUniformValue("color_convolve", "Saturation", corruption); - shader.render(tickDelta); + shader.render(tickCounter.getLastFrameDuration()); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java index 2d571ffb..d1eaedc3 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java @@ -348,8 +348,8 @@ public class SpellbookScreenHandler extends ScreenHandler { ItemStack current = slot.getStack(); if (current.isEmpty() && slot.canInsert(stack)) { - if (stack.getCount() > slot.getMaxItemCount()) { - slot.setStack(stack.split(slot.getMaxItemCount())); + if (stack.getCount() > slot.getMaxItemCount(stack)) { + slot.setStack(stack.split(slot.getMaxItemCount(stack))); } else { slot.setStack(stack.split(stack.getCount())); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantmentEffects.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantmentEffects.java index aad02e37..f2df4124 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantmentEffects.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantmentEffects.java @@ -16,6 +16,6 @@ public interface UEnchantmentEffects { } private static void register(String name, MapCodec codec) { - Registry.register(Registries.ENCHANTMENT_ENTITY_EFFECT_TYPE, Unicopia.id("name"), codec); + Registry.register(Registries.ENCHANTMENT_ENTITY_EFFECT_TYPE, Unicopia.id(name), codec); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java index 762b01d8..666316ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import com.minelittlepony.unicopia.Unicopia; import net.minecraft.enchantment.Enchantment; -import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; @@ -121,10 +120,6 @@ public interface UEnchantments { return key; } - static void register(Registry registry, RegistryKey key, Enchantment.Builder builder) { - Registry.register(registry, key, builder.build(key.getValue())); - } - static void bootstrap() { UEnchantmentEffects.bootstrap(); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java index dcc4e5f9..fa33b62e 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java @@ -4,8 +4,6 @@ import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.minelittlepony.unicopia.client.BatEyesApplicator; import com.minelittlepony.unicopia.client.UnicopiaClient; @@ -43,25 +41,19 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe } } - @Inject(method = "renderWorld", - at = @At("RETURN")) + @Inject(method = "renderWorld", at = @At("RETURN")) private void afterRenderWorld(RenderTickCounter counter, CallbackInfo info) { BatEyesApplicator.INSTANCE.disable(); } - @ModifyReturnValue(method = "getNightVisionStrength(Lnet/minecraft/entity/LivingEntity;F)F", at = @At("RETURN")) - private static float modifyWorldBrightness(float initial, LivingEntity entity, float tickDelta, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "getNightVisionStrength", at = @At("RETURN")) + private static float modifyNightVisionStrength(float initial, LivingEntity entity, float tickDelta) { return BatEyesApplicator.getWorldBrightness(initial, entity, tickDelta); } - @Inject(method = "render", - at = @At( - value = "INVOKE", - target = "net/minecraft/client/gl/Framebuffer.beginWrite(Z)V", - shift = Shift.BEFORE) - ) - private void onBeforeFrameEnd(float tickDelta, long startTime, boolean tick, CallbackInfo info) { - ViewportShader.INSTANCE.render(tickDelta); + @Inject(method = "render", at = @At(value = "INVOKE", target = "net/minecraft/client/gl/Framebuffer.beginWrite(Z)V", shift = Shift.BEFORE)) + private void onBeforeFrameEnd(RenderTickCounter tickCounter, boolean tick, CallbackInfo info) { + ViewportShader.INSTANCE.render(tickCounter); } @Inject(method = "onResized", at = @At("HEAD")) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java index 32484ca0..6ec915dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java @@ -3,63 +3,19 @@ package com.minelittlepony.unicopia.mixin.trinkets; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate; - +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; -import net.minecraft.util.collection.DefaultedList; // fixed shift-clicking (handles other 10%) @Mixin(ScreenHandler.class) abstract class MixinScreenHandler { - @Nullable - private Slot currentSlot; - - @Redirect(method = "insertItem", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/util/collection/DefaultedList;get(I)Ljava/lang/Object;" - ) + @ModifyExpressionValue( + method = "canInsertItemIntoSlot", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMaxCount()I") ) - // manual capture of the current slot since @Redirect doesn't support local captures - private Object onGetSlot(DefaultedList sender, int index) { - currentSlot = sender.get(index); - return currentSlot; - } - - @Redirect(method = "insertItem", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount()I" - ) - ) - // redirect slot.getMaxItemCount() to stack aware version - protected int onGetMaxItemCount(Slot sender, ItemStack stack) { - return TrinketsDelegate.getInstance(null).isTrinketSlot(sender) ? sender.getMaxItemCount(stack) : sender.getMaxItemCount(); - } - - @Redirect(method = "insertItem", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", - ordinal = 1 - ) - ) - // redirect "if (!itemStack.isEmpty() && ItemStack.canCombine(stack, itemStack))" -> "if (!canNotInsert(itemStack, slot) && ItemStack.canCombine(stack, itemStack))" - protected boolean canNotInsert(ItemStack sender) { - return sender.isEmpty() || (TrinketsDelegate.getInstance(null).isTrinketSlot(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender)); - } - - @Redirect(method = "canInsertItemIntoSlot", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/item/ItemStack;getMaxCount()I" - ) - ) - private static int onGetMaxCount(ItemStack sender, @Nullable Slot slot) { - return TrinketsDelegate.getInstance(null).isTrinketSlot(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount(); + private static int modifyMaxCount(int maxCount, @Nullable Slot slot, ItemStack stack, boolean allowOverflow) { + return slot.getMaxItemCount(stack); } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketInventory.java b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketInventory.java index 53bddf41..60d86c43 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketInventory.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketInventory.java @@ -16,7 +16,6 @@ abstract class MixinTrinketInventory implements Inventory { ItemStack existingStack = getStack(slot); SlotReference ref = new SlotReference((TrinketInventory)(Object)this, slot); - int max = Math.min( existingStack.isEmpty() ? 64 : TrinketsDelegateImpl.getMaxCount(existingStack, ref, existingStack.getMaxCount()), stack.isEmpty() ? 64 : TrinketsDelegateImpl.getMaxCount(stack, ref, stack.getMaxCount()) diff --git a/src/main/resources/assets/unicopia/shaders/post/desaturate.json b/src/main/resources/assets/unicopia/shaders/post/desaturate.json new file mode 100644 index 00000000..675018fa --- /dev/null +++ b/src/main/resources/assets/unicopia/shaders/post/desaturate.json @@ -0,0 +1,23 @@ +{ + "targets": [ + "swap" + ], + "passes": [ + { + "name": "color_convolve", + "intarget": "minecraft:main", + "outtarget": "swap", + "uniforms": [ + { + "name": "Saturation", + "values": [ 0.2 ] + } + ] + }, + { + "name": "blit", + "intarget": "swap", + "outtarget": "minecraft:main" + } + ] +}