Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.github.axolotlclient.oldanimations.OldAnimations;
import lombok.Getter;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.ornithemc.osl.lifecycle.api.client.MinecraftClientEvents;

public class OldAnimationsConfig {
Expand Down Expand Up @@ -99,8 +98,7 @@ public class OldAnimationsConfig {
public final BooleanOption zombieVillagerHelmetOffset = new BooleanOption("zombieVillagerHelmetOffset", true);
public final BooleanOption framedItemRotationOffset = new BooleanOption("framedItemRotationOffset", true);

/* toggling these two rebuilds cached game state, so their previous values are tracked */
private boolean previousTrapDoorItemPosition = trapDoorItemPosition();
/* Potion colors are cached; trapdoor models are selected at render time. */
private boolean previousOldJumpBoostPotionColor = oldJumpBoostPotionColor();

/**
Expand All @@ -111,10 +109,6 @@ public static boolean isEnabled() {
return instance.enabled.get();
}

private boolean trapDoorItemPosition() {
return enabled.get() && trapDoorItemPosition.get();
}

private boolean oldJumpBoostPotionColor() {
return enabled.get() && oldJumpBoostPotionColor.get();
}
Expand Down Expand Up @@ -190,30 +184,23 @@ public void initConfig() {
AxolotlClientConfig.getInstance().register(configManager);
configManager.load();

/* attempt to prevent calling resourcereload during game init */
previousTrapDoorItemPosition = trapDoorItemPosition();
/* Seed the effective color setting after the configuration is loaded. */
previousOldJumpBoostPotionColor = oldJumpBoostPotionColor();

/* reload the resources upon toggling certain options */
reloadResources();
trackPotionColors();
}

/**
* The trapdoor item model is baked at resource load, and potion colors are
* cached separately, so both need a nudge when their option is toggled.
* The master switch counts as toggling both of them.
* Both trapdoor variants are always baked by ModelBakeryMixin and selected
* by ItemModelShaperMixin. Toggling them (or the master switch) must not
* reload every resource and rebuild the world. Only potion colors need
* their cache invalidated when the effective option changes.
*/
private void reloadResources() {
private void trackPotionColors() {
MinecraftClientEvents.TICK_END.register(client -> {
if (trapDoorItemPosition() != previousTrapDoorItemPosition) {
previousTrapDoorItemPosition = trapDoorItemPosition();
previousOldJumpBoostPotionColor = oldJumpBoostPotionColor();
Minecraft.getInstance().reloadResources();
reloadPotionColors = true;
return;
}
if (oldJumpBoostPotionColor() != previousOldJumpBoostPotionColor) {
previousOldJumpBoostPotionColor = oldJumpBoostPotionColor();
boolean current = oldJumpBoostPotionColor();
if (current != previousOldJumpBoostPotionColor) {
previousOldJumpBoostPotionColor = current;
reloadPotionColors = true;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* For more information, see the LICENSE file.
*/

package io.github.axolotlclient.oldanimations.mixin;

import java.util.List;

import io.github.axolotlclient.oldanimations.util.SpriteQuadProvider;
import net.minecraft.client.resource.model.BakedQuad;
import net.minecraft.client.resource.model.BasicBakedModel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(BasicBakedModel.class)
public abstract class BasicBakedModelMixin implements SpriteQuadProvider {
@Unique
private List<BakedQuad> axolotlclient$spriteSourceQuads;

@Unique
private List<BakedQuad> axolotlclient$spriteQuads;

@Override
public List<BakedQuad> axolotlclient$getSpriteQuads(List<BakedQuad> quads) {
// The cache belongs to the baked model, so resource reloads replace it
// along with the geometry. Glint passes reuse it without scanning or
// allocating another list on every item render.
if (axolotlclient$spriteSourceQuads != quads) {
axolotlclient$spriteQuads = SpriteQuadProvider.filter(quads);
axolotlclient$spriteSourceQuads = quads;
}
return axolotlclient$spriteQuads;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,41 @@
import com.llamalad7.mixinextras.sugar.Local;
import io.github.axolotlclient.oldanimations.config.OldAnimationsConfig;
import io.github.axolotlclient.oldanimations.util.ItemUtil;
import io.github.axolotlclient.oldanimations.util.GuiGlintRenderer;
import io.github.axolotlclient.oldanimations.util.SpriteQuadProvider;
import net.minecraft.client.render.entity.ItemRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.render.model.block.ModelTransformations;
import net.minecraft.client.render.platform.GlStateManager;
import net.minecraft.client.resource.model.BakedModel;
import net.minecraft.client.resource.model.BakedQuad;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import net.minecraft.client.render.texture.TextureManager;
import net.minecraft.resource.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import java.util.ArrayList;
import java.util.List;

@Mixin(ItemRenderer.class /* C_6823239 */)
public abstract class ItemRendererMixin {

@Shadow
@Final
private static Identifier ENCHANTMENT_GLINT_LOCATION;

@Shadow
@Final
private TextureManager textureManager;

@Shadow
public abstract boolean isGui3d(ItemStack stack);

@Unique
private BakedModel axolotlclient$model = null;

Expand Down Expand Up @@ -92,30 +108,31 @@ public abstract class ItemRendererMixin {
}

if (!model.isGui3d() && (axolotlclient$transform == ModelTransformations.Type.GUI || axolotlclient$shouldBeSpriteOrSwapNormal(false))) {
/* this is the easiest way to have fast items with the 1.8 model system */
/* even forge does this xD */
List<BakedQuad> filtered = new ArrayList<>(quads.size());
for (BakedQuad quad : quads) {
if (quad.getFace() == Direction.SOUTH) {
filtered.add(quad);
}
}
return filtered;
return SpriteQuadProvider.get(model, quads);
}
return quads;
}

@Inject(method = "renderEnchantmentGlint", at = @At("HEAD"), cancellable = true)
private void axolotlclient$disableDefaultGlint(CallbackInfo ci) {
private void axolotlclient$disableDefaultGlint(BakedModel model, CallbackInfo ci) {
if (!OldAnimationsConfig.isEnabled()) {
return;
}

if (axolotlclient$shouldBeSpriteOrSwapNormal(false)) {
// Keep the pre-refactor fast paths: no two extra geometry passes on
// blocks, and a flat overlay for GUI items. Master-off remains vanilla.
if (model.isGui3d() || axolotlclient$transform == ModelTransformations.Type.GUI || axolotlclient$shouldBeSpriteOrSwapNormal(false)) {
ci.cancel();
}
}

@Inject(method = "renderGuiItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/ItemRenderer;renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resource/model/BakedModel;)V", shift = At.Shift.AFTER))
private void axolotlclient$renderGuiGlint(ItemStack stack, int x, int y, CallbackInfo ci) {
if (OldAnimationsConfig.isEnabled() && stack.hasEnchantmentGlint() && !isGui3d(stack)) {
GuiGlintRenderer.render(textureManager, ENCHANTMENT_GLINT_LOCATION, Minecraft.getTime());
}
}

@Inject(method = "renderItemInHand(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/block/ModelTransformations$Type;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/ItemRenderer;renderItemInHand(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resource/model/BakedModel;Lnet/minecraft/client/render/model/block/ModelTransformations$Type;)V"))
private void axolotlclient$fastItemOffset(ItemStack stack, ModelTransformations.Type transformationType, CallbackInfo ci) {
//todo: is this really needed? im not so sure anymore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* For more information, see the LICENSE file.
*/

package io.github.axolotlclient.oldanimations.util;

import net.minecraft.client.render.platform.GlStateManager;
import net.minecraft.client.render.texture.TextureAtlas;
import net.minecraft.client.render.texture.TextureManager;
import net.minecraft.client.render.vertex.BufferBuilder;
import net.minecraft.client.render.vertex.DefaultVertexFormat;
import net.minecraft.client.render.vertex.Tesselator;
import net.minecraft.resource.Identifier;

/** The previous 1.7 GUI overlay, with both quads submitted in one draw. */
public final class GuiGlintRenderer {
private GuiGlintRenderer() {
}

public static void render(TextureManager textures, Identifier glint, long time) {
GlStateManager.depthMask(false);
GlStateManager.depthFunc(518);
GlStateManager.disableLighting();
GlStateManager.blendFuncSeparate(772, 1, 0, 0);
textures.bind(glint);
GlStateManager.pushMatrix();
try {
GlStateManager.scalef(0.5F, 0.5F, 0.5F);
GlStateManager.translatef(0.0F, -0.25F, 0.0F);
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder buffer = tesselator.getBuffer();
buffer.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR);
appendQuad(buffer, (float) (time % 3000L) / 3000.0F, 4.0F);
appendQuad(buffer, (float) (time % 4873L) / 4873.0F, -1.0F);
tesselator.end();
} finally {
GlStateManager.popMatrix();
GlStateManager.blendFuncSeparate(770, 771, 1, 0);
GlStateManager.enableLighting();
GlStateManager.depthFunc(515);
GlStateManager.depthMask(true);
textures.bind(TextureAtlas.BLOCKS_LOCATION);
}
}

private static void appendQuad(BufferBuilder buffer, float speed, float skew) {
// Same positions, UVs and color as the removed GlintQuadModel, without
// allocating a model, vertex arrays or lists for each overlay pass.
float dimension = 20.0F / 256.0F;
vertex(buffer, -0.5F, -0.25F, speed + dimension * skew, dimension);
vertex(buffer, 0.5F, -0.25F, speed + dimension + dimension * skew, dimension);
vertex(buffer, 0.5F, 0.75F, speed + dimension, 0.0F);
vertex(buffer, -0.5F, 0.75F, speed, 0.0F);
}

private static void vertex(BufferBuilder buffer, float x, float y, float u, float v) {
buffer.vertex(x, y, 0.0F).texture(u, v).color(128, 64, 204, 255).nextVertex();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* For more information, see the LICENSE file.
*/

package io.github.axolotlclient.oldanimations.util;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.resource.model.BakedModel;
import net.minecraft.client.resource.model.BakedQuad;
import net.minecraft.client.resource.model.BasicBakedModel;
import net.minecraft.util.math.Direction;

/** The south-facing quads used by the flat item renderer. */
public interface SpriteQuadProvider {
List<BakedQuad> axolotlclient$getSpriteQuads(List<BakedQuad> quads);

static List<BakedQuad> get(BakedModel model, List<BakedQuad> quads) {
// Vanilla baked models keep the same quad list for their lifetime. Do not
// cache custom models or subclasses: they may return dynamic geometry.
if (model.getClass() == BasicBakedModel.class) {
return ((SpriteQuadProvider) model).axolotlclient$getSpriteQuads(quads);
}
return filter(quads);
}

static List<BakedQuad> filter(List<BakedQuad> quads) {
List<BakedQuad> filtered = new ArrayList<>();
for (BakedQuad quad : quads) {
if (quad.getFace() == Direction.SOUTH) {
filtered.add(quad);
}
}
return List.copyOf(filtered);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"thirdPersonPositions": "Third Person Item Positions",
"thirdPersonPositions.tooltip": "Reverts third person item transformations to match 1.7. Currently, this feature will disable the ability for resource packs to alter item positions, however, this is subject to change in the future.",
"trapDoorItemPosition": "Trapdoor Item Position",
"trapDoorItemPosition.tooltip": "Reverts the trapdoor item model position when viewed in the inventory, while held, or dropped to match 1.7. Toggling this will reload the game resources!",
"trapDoorItemPosition.tooltip": "Reverts the trapdoor item model position when viewed in the inventory, while held, or dropped to match 1.7.",
"useAndMineSound": "Use and Mine Sound",
"useAndMineSound.tooltip": "Plays block mining sounds while using and item and mining to imiate block breaking.",
"framedItemRotationOffset": "Framed Item Rotation Offset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"minVersion": "0.5.0"
},
"client": [
"BasicBakedModelMixin",
"ClientPlayNetworkHandlerMixin",
"ClientPlayerInteractionManagerAccessor",
"ClientPlayerInteractionManagerMixin",
Expand Down
Loading
Loading