Skip to content

Commit

Permalink
♻️ 重构
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Apr 29, 2024
1 parent c5802bc commit f1a59ef
Show file tree
Hide file tree
Showing 96 changed files with 1,555 additions and 99 deletions.
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
# AnimatedFreeze
# AnimatedFreeze - 动画冻结

**中文**| [**English**](README_en.md)

## 简介
- 这个模组增加了一个内置的资源包,可以禁用海灯、海带和海草的动画效果。
- 这个模组增加了一些内置资源包,用于禁用一些材质的动画效果亦或是改变其渲染方式来提高游戏的性能。



- 可能和部分资源包不兼容且关于这方面的问题将不会被处理。



## 材质包

- **af_mod/chest_optimization(箱子优化)**

改变了箱子的渲染方式,大幅提升FPS(使用时请将该材质放在第一位)。

该实现方式与 [FastChest](https://github.com/FakeDomi/FastChest) 模组基本相同,因此有关于此材质的问题可以参考 [FastChest README](https://github.com/FakeDomi/FastChest/blob/master/README.md)



- **af_mod/kelp_freeze(静止海带)**

移除了海带的摇晃动画。



- **af_mod/sea_lantern_freeze(静止海晶灯)**

移除了海晶灯的动画。


- 可能和部分资源包不兼容,具体表现为动画依然存在。

## Intro
- This mod has added a built-in resource pack to disable the animation effects of s1ea lanterns, kelp, and seagrass.
- **af_mod/seagrass_freeze(静止海草)**

- May be incompatible with some resource packages, specifically manifested as the animation still exists.
移除了海草的摇晃动画。
39 changes: 39 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# AnimatedFreeze

[**中文**](README.md) **|** [**English**]

## Into

- This module adds some built-in resource packs designed to disable certain texture animations or change their rendering approach to improve game performance.



- It may be incompatible with some resource packs, and issues related to these incompatibilities will not be addressed.



## Resource Packs

- **af_mod/chest_optimization**

Changes the rendering method for chests, significantly boosting FPS (when using this, place this resource pack first in the list).

This implementation is essentially the same as the [FastChest](https://github.com/FakeDomi/FastChest) mod, so any issues related to this resource pack can refer to the [FastChest README](https://github.com/FakeDomi/FastChest/blob/master/README.md).



- **af_mod/kelp_freeze**

Removes the swaying animation of kelp.



- **af_mod/sea_lantern_freeze**

Removes the animation from sea lanterns.



- **af_mod/seagrass_freeze**

Removes the swaying animation of seagrass.
24 changes: 1 addition & 23 deletions src/main/java/top/byteeeee/AnimatedFreeze/AnimatedFreeze.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,8 @@
package top.byteeeee.AnimatedFreeze;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;

import net.minecraft.util.Identifier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AnimatedFreeze implements ModInitializer {
public static final String modName = "AnimatedFreeze";
public static final Logger LOGGER = LogManager.getLogger(modName);

@Override
public void onInitialize() {
LOGGER.info(modName + " " + "loaded!");

FabricLoader.getInstance().getModContainer("animatedfreeze").ifPresent(
modContainer ->
ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier("animatedfreeze:animatedfreeze"),
modContainer,
ResourcePackActivationType.DEFAULT_ENABLED
)
);
}
public void onInitialize() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze;

import net.fabricmc.api.ClientModInitializer;

import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.ResourcePackManager;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import top.byteeeee.AnimatedFreeze.utils.BuiltinResourcesPackAdder;

public class AnimatedFreezeClient implements ClientModInitializer {
public static final String modName = "AnimatedFreeze";
public static final Logger LOGGER = LogManager.getLogger(modName);
public static MinecraftClient minecraftClient = MinecraftClient.getInstance();
public static ResourcePackManager resourcePackManager = minecraftClient.getResourcePackManager();

@Override
public void onInitializeClient() {
LOGGER.info(modName + " " + "loaded!");
BuiltinResourcesPackAdder.add();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze;

import top.byteeeee.AnimatedFreeze.helpers.NeedReloadResources;

public class AnimatedFreezeSetting {
public static boolean chestOptimization;

public static void changeValue() {
AnimatedFreezeClient.resourcePackManager.getEnabledProfiles().forEach(
chestProfile -> AnimatedFreezeSetting.chestOptimization = NeedReloadResources.isOf(chestProfile.getName())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze.helpers;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.EnderChestBlockEntity;
import net.minecraft.block.entity.TrappedChestBlockEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

@Environment(EnvType.CLIENT)
public class EntityRenderBlock {
private static final List<Predicate<Class<?>>> entityRenderBlockPredicates = new ArrayList<>();

public static boolean isOf(Class<?> blockEntity) {
return entityRenderBlockPredicates.stream().anyMatch(predicate -> predicate.test(blockEntity));
}

static {
entityRenderBlockPredicates.add(blockEntity -> blockEntity.equals(ChestBlockEntity.class));
entityRenderBlockPredicates.add(blockEntity -> blockEntity.equals(TrappedChestBlockEntity.class));
entityRenderBlockPredicates.add(blockEntity -> blockEntity.equals(EnderChestBlockEntity.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze.helpers;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import top.byteeeee.AnimatedFreeze.utils.RegexTools;

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

@Environment(EnvType.CLIENT)
public class NeedReloadResources {
private static final List<String> needReload = new ArrayList<>();

public static boolean isOf(String profileName) {
return needReload.contains(profileName);
}

@SuppressWarnings("SameParameterValue")
private static String setCompatName(String sourceName) {
return RegexTools.createCompatProfileName(sourceName);
}

static {
needReload.add(setCompatName("af_mod:chest_optimization"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze.mixin.changeSettingsValue;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

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.CallbackInfoReturnable;

import top.byteeeee.AnimatedFreeze.AnimatedFreezeSetting;

import java.util.concurrent.CompletableFuture;

@Environment(EnvType.CLIENT)
@Mixin(value = MinecraftClient.class, priority = 1688)
public abstract class MinecraftClientMixin {
@Inject(
//#if MC>=12002
//$$ method = "reloadResources(ZLnet/minecraft/client/MinecraftClient$LoadingContext;)Ljava/util/concurrent/CompletableFuture;",
//#elseif MC>=11800
//$$ method = "reloadResources(Z)Ljava/util/concurrent/CompletableFuture;",
//#else
method = "reloadResources",
//#endif
at = @At("HEAD")
)
private void reloadResources(CallbackInfoReturnable<CompletableFuture<Void>> cir) {
AnimatedFreezeSetting.changeValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of the AnimatedFreeze project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 1024_byteeeee and contributors
*
* AnimatedFreeze 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.
*
* AnimatedFreeze 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 AnimatedFreeze. If not, see <https://www.gnu.org/licenses/>.
*/

package top.byteeeee.AnimatedFreeze.mixin.chestOptimization;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import top.byteeeee.AnimatedFreeze.helpers.EntityRenderBlock;
import top.byteeeee.AnimatedFreeze.AnimatedFreezeSetting;

@Environment(EnvType.CLIENT)
@Mixin(BlockEntityRenderDispatcher.class)
public abstract class BlockEntityRenderDispatcherMixin {
@ModifyReturnValue(method = "get", at = @At("RETURN"))
private <E extends BlockEntity> BlockEntityRenderer<E> get(BlockEntityRenderer<E> original, E blockEntity) {
return EntityRenderBlock.isOf(blockEntity.getClass()) && AnimatedFreezeSetting.chestOptimization ? null : original;
}
}
Loading

0 comments on commit f1a59ef

Please sign in to comment.