Skip to content

Commit

Permalink
Prevent chest client ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeDomi committed Nov 6, 2023
1 parent bb13bf0 commit b2b1959
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 64 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ jobs:
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-2022]
os: [ubuntu-22.04, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- name: checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'microsoft'
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: build/libs/
path: build/libs/
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ bin/
# fabric

run/

# java

hs_err_*.log
replay_*.log
*.hprof
*.jfr
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021-2022 Domi
Copyright (c) 2021-2023 Domi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# FastChest

**Requires [Fabric API](https://github.com/FabricMC/fabric/releases).** If you have a lot of chests nearby, you have probably noticed how bad Minecraft is at rendering them. The more chests you place, the lower your FPS go.
If your storage room contains a lot of chests, you have probably noticed how bad Minecraft is at rendering them. The more chests are placed, the lower your FPS go.

This mod helps by removing dynamic models from chests and making them render as static chunk geometry like normal blocks. (This means they will lose their lid opening animation!)
FastChest helps by removing their dynamic models (aka BlockEntityRenderer) and making them render as static chunk geometry, like most normal blocks. (This means they will lose their lid opening animation! Check out [Enhanced Block Entities](https://modrinth.com/mod/ebe) if you care about that.)

Depending on how many chests you have around you'll see varying effectiveness. In large storage rooms this mod can easily double your FPS. Keep in mind this mod only focuses on chests, and there might be other things crippling your FPS.
Depending on how many chests you have around, you'll see varying effectiveness. In large storage rooms this mod can easily double your FPS, but keep in mind that chests aren't the only thing responsible for bad performance.

FastChest works with Sodium and Optifine and should be compatible with all other mods and resource packs that leave chests alone. One example that does not is the *Vanilla Tweaks Proper Break Particles* resource pack. It overwrites the chest blockstate definitions and is not compatible out of the box. You can however delete `chest.json`, `ender_chest.json` and `trapped_chest.json` from the `/assets/minecraft/blockstates` directory of your resource pack to make it work with the mod.
FastChest works with Sodium and Optifine and should be compatible with all other mods and resource packs that leave chests alone. For example, the *Vanilla Tweaks Proper Break Particles* resource pack doesn't. It overwrites the chest blockstate definitions and is not compatible out of the box. You can however delete `chest.json`, `ender_chest.json` and `trapped_chest.json` from the `/assets/minecraft/blockstates` directory of your resource pack to make it work with the mod.

A classic (full-block) chest resource pack can be downloaded from [here](https://up.domi.re/pa1f7rxa).
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand Down Expand Up @@ -47,7 +47,6 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}

Expand All @@ -56,6 +55,9 @@ java {
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

jar {
Expand Down
19 changes: 10 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
# check these on https://fabricmc.net/develop
minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.24

# Mod Properties
mod_version = 1.3+1.19
maven_group = re.domi
archives_base_name = fast-chest
mod_version=1.5+1.19
maven_group=re.domi
archives_base_name=fast-chest

# Dependencies
fabric_version=0.55.1+1.19
mod_menu_version=4.0.0
fabric_version=0.58.0+1.19
mod_menu_version=4.0.4
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
30 changes: 22 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +213,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
18 changes: 9 additions & 9 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
7 changes: 7 additions & 0 deletions src/main/java/re/domi/fastchest/config/ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package re.domi.fastchest.config;

import net.fabricmc.fabric.impl.event.lifecycle.LoadedChunksCache;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.world.chunk.WorldChunk;

public class ConfigScreen extends Screen
{
Expand Down Expand Up @@ -34,6 +36,11 @@ public void init()
if (this.client != null)
{
this.client.worldRenderer.reload();

if (this.client.world != null)
{
((LoadedChunksCache)this.client.world).fabric_getLoadedChunks().forEach(WorldChunk::updateAllBlockEntities);
}
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.block.entity.TrappedChestBlockEntity;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,7 +16,7 @@
public class BlockEntityRenderDispatcherMixin
{
@Inject(method = "get", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void fastchest_get(E blockEntity, CallbackInfoReturnable<@Nullable BlockEntityRenderer<E>> cir)
private <E extends BlockEntity> void removeBlockEntityRenderer(E blockEntity, CallbackInfoReturnable<BlockEntityRenderer<E>> cir)
{
if (Config.simplifiedChest)
{
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/re/domi/fastchest/mixin/ChestBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -13,11 +17,20 @@
public class ChestBlockMixin
{
@Inject(method = "getRenderType", at = @At("HEAD"), cancellable = true)
private void fastchest_getRenderType(BlockState state, CallbackInfoReturnable<BlockRenderType> cir)
private void replaceRenderType(BlockState state, CallbackInfoReturnable<BlockRenderType> cir)
{
if (Config.simplifiedChest)
{
cir.setReturnValue(BlockRenderType.MODEL);
}
}

@Inject(method = "getTicker", at = @At("HEAD"), cancellable = true)
private <T extends BlockEntity> void removeTicker(World world, BlockState state, BlockEntityType<T> type, CallbackInfoReturnable<BlockEntityTicker<T>> cir)
{
if (Config.simplifiedChest)
{
cir.setReturnValue(null);
}
}
}
15 changes: 14 additions & 1 deletion src/main/java/re/domi/fastchest/mixin/EnderChestBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.EnderChestBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -13,11 +17,20 @@
public class EnderChestBlockMixin
{
@Inject(method = "getRenderType", at = @At("HEAD"), cancellable = true)
private void fastchest_getRenderType(BlockState state, CallbackInfoReturnable<BlockRenderType> cir)
private void replaceRenderType(BlockState state, CallbackInfoReturnable<BlockRenderType> cir)
{
if (Config.simplifiedChest)
{
cir.setReturnValue(BlockRenderType.MODEL);
}
}

@Inject(method = "getTicker", at = @At("HEAD"), cancellable = true)
private <T extends BlockEntity> void removeTicker(World world, BlockState state, BlockEntityType<T> type, CallbackInfoReturnable<BlockEntityTicker<T>> cir)
{
if (Config.simplifiedChest)
{
cir.setReturnValue(null);
}
}
}
Loading

0 comments on commit b2b1959

Please sign in to comment.