Skip to content

Commit

Permalink
feat: batchdrawing & fullbright
Browse files Browse the repository at this point in the history
  • Loading branch information
Hankung7183 committed May 19, 2023
1 parent d1b2a12 commit 382e90c
Show file tree
Hide file tree
Showing 43 changed files with 1,145 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ loom {
defaultRefmapName = "${project.refmap_name}"
}

accessWidenerPath.set(file("src/main/resources/legacyenhance.accesswidener"))

}

configurations {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/me/hankung/legacyenhance/config/LegacyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class LegacyConfig extends ConfigHolder {
public final BooleanOption generalBetterKeybind = new BooleanOption("Better Keybind Handling", true);
public final BooleanOption generalBetterRomanNumerals = new BooleanOption("Better Roman Numerals", true);
public final BooleanOption generalCleanView = new BooleanOption("Clean View", false);
public final BooleanOption generalFullBright = new BooleanOption("FullBright", true);
public final BooleanOption generalNoAchievement = new BooleanOption("No Achievement Notifications", false);
public final BooleanOption generalNumericalEnchants = new BooleanOption("Numerical Enchantments", false);

Expand Down Expand Up @@ -52,6 +53,7 @@ public class LegacyConfig extends ConfigHolder {

// Performance
public final OptionCategory performance = new OptionCategory("Performance");
public final BooleanOption performanceBatchModel = new BooleanOption("Batch Model Rendering", true);
public final BooleanOption performanceDownscaleTexture = new BooleanOption("Downscale Texture", true);
// ----
public final OptionCategory performanceEntityCulling = new OptionCategory("Entity Culling", true);
Expand All @@ -61,6 +63,7 @@ public class LegacyConfig extends ConfigHolder {
public final BooleanOption performanceEntityCullingRNTW = new BooleanOption("Render Nametags Through Walls", true);
// ----
public final BooleanOption performanceFastWorldSwapping = new BooleanOption("Fast World Swapping", true);
public final BooleanOption performanceLowAnimationTick = new BooleanOption("Low Animation Tick", true);
public final BooleanOption performanceStaticParticleColor = new BooleanOption("Static Particle Color", true);

public final List<io.github.axolotlclient.AxolotlClientConfig.common.options.OptionCategory> config = new ArrayList<>();
Expand Down Expand Up @@ -96,6 +99,7 @@ public void init() {
generalBetterKeybind,
generalBetterRomanNumerals,
generalCleanView,
generalFullBright,
generalNoAchievement,
generalNumericalEnchants
);
Expand Down Expand Up @@ -131,7 +135,10 @@ public void init() {
oldanimateSmoothSneaking
);

performance.add(performanceDownscaleTexture);
performance.add(
performanceBatchModel,
performanceDownscaleTexture
);

performanceEntityCulling.add(
performanceEntityCullingEnabled,
Expand All @@ -142,6 +149,7 @@ public void init() {

performance.add(performanceEntityCulling);
performance.add(performanceFastWorldSwapping);
performance.add(performanceLowAnimationTick);
performance.add(performanceStaticParticleColor);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public class MixinConfigPlugin implements IMixinConfigPlugin {
private final boolean hasAxolotl = FabricLoader.getInstance().isModLoaded("axolotlclient");
private final boolean hasVanillaFix = FabricLoader.getInstance().isModLoaded("legacyvanillafix");
private final boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");

@Override
public void onLoad(String mixinPackage) {
Expand All @@ -28,9 +27,6 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (hasOptifine && containsAny(mixinClassName, new String[] { "banneranimationfix", "enableblending" })) {
return false;
}
if (hasAxolotl && mixinClassName.contains("fastworldswapping.MinecraftClientMixin")) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Mixin(BannerBlockEntityRenderer.class)
public class BannerBlockEntityRendererMixin {
@Redirect(method = "render(Lnet/minecraft/block/entity/BannerBlockEntity;DDDFI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getTime()J"))
@Redirect(method = "render(Lnet/minecraft/block/entity/BannerBlockEntity;DDDFI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getLastUpdateTime()J"))
private long legacy$resolveOverflow(World world) {
return world.getLastUpdateTime() % 100L;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.hankung.legacyenhance.mixin.batchdrawing;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import net.minecraft.client.render.BufferBuilder;

@Mixin(BufferBuilder.class)
public interface BufferBuilderAccessor {
@Accessor("building")
boolean isDrawing();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.hankung.legacyenhance.mixin.batchdrawing;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import me.hankung.legacyenhance.LegacyEnhance;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.model.ModelPart;

@Mixin(ModelPart.class)
public class ModelPartMixin {

@Shadow
private boolean compiledList;

private boolean legacy$compiledState;

@Inject(method = "render", at = @At("HEAD"))
private void legacy$resetCompiled(float j, CallbackInfo ci) {
if (legacy$compiledState != LegacyEnhance.CONFIG.performanceBatchModel.get()) {
this.compiledList = false;
}
}

@Inject(method = "compileList", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/render/Tessellator;getBuffer()Lnet/minecraft/client/render/BufferBuilder;"))
private void legacy$beginRendering(CallbackInfo ci) {
this.legacy$compiledState = LegacyEnhance.CONFIG.performanceBatchModel.get();
if (LegacyEnhance.CONFIG.performanceBatchModel.get()) {
Tessellator.getInstance().getBuffer().begin(7, VertexFormats.ENTITY);
}
}

@Inject(method = "compileList", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glEndList()V", remap = false))
private void legacy$draw(CallbackInfo ci) {
if (LegacyEnhance.CONFIG.performanceBatchModel.get()) {
Tessellator.getInstance().draw();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.hankung.legacyenhance.mixin.batchdrawing;

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

import me.hankung.legacyenhance.LegacyEnhance;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.TexturedQuad;

@Mixin(TexturedQuad.class)
public class TexturedQuadMixin {

@Unique
private boolean legacy$drawOnSelf;

@Redirect(method = "draw", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BufferBuilder;begin(ILnet/minecraft/client/render/VertexFormat;)V"))
private void legacy$beginDraw(BufferBuilder renderer, int glMode, VertexFormat format) {
this.legacy$drawOnSelf = !((BufferBuilderAccessor) renderer).isDrawing();
if (this.legacy$drawOnSelf || !LegacyEnhance.CONFIG.performanceBatchModel.get()) {
renderer.begin(glMode, VertexFormats.POSITION_TEXTURE_NORMAL);
}
}

@Redirect(method = "draw", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;draw()V"))
private void legacy$endDraw(Tessellator tessellator) {
if (this.legacy$drawOnSelf || !LegacyEnhance.CONFIG.performanceBatchModel.get()) {
tessellator.draw();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.hankung.legacyenhance.mixin.cachedisplayname;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.entity.Entity;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;

@Mixin(Entity.class)
public abstract class EntityMixin {

@Shadow
protected abstract HoverEvent getHoverEvent();

private long legacy$displayNameCachedAt;

private Text legacy$cachedDisplayName;

@Inject(method = "getName", at = @At("RETURN"))
protected void legacy$cacheDisplayName(CallbackInfoReturnable<Text> cir) {
legacy$cachedDisplayName = cir.getReturnValue();
legacy$displayNameCachedAt = System.currentTimeMillis();
}

@Inject(method = "getName", at = @At("HEAD"), cancellable = true)
protected void legacy$returnCachedDisplayName(CallbackInfoReturnable<Text> cir) {
if (System.currentTimeMillis() - legacy$displayNameCachedAt < 50L) {
cir.setReturnValue(legacy$cachedDisplayName);
}
}

@Redirect(method = "getName", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getHoverEvent()Lnet/minecraft/text/HoverEvent;"))
private HoverEvent legacy$doNotGetHoverEvent(Entity instance) {
return null;
}

@Redirect(method = "getName", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Style;setHoverEvent(Lnet/minecraft/text/HoverEvent;)Lnet/minecraft/text/Style;"))
private Style legacy$doNotSetHoverEvent(Style instance, HoverEvent event) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.hankung.legacyenhance.mixin.cachedisplayname;

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 net.minecraft.item.ItemStack;

@Mixin(ItemStack.class)
public class ItemStackMixin {

private String legacy$cachedDisplayName;

@Inject(method = "getCustomName", at = @At("HEAD"), cancellable = true)
private void legacy$returnCachedDisplayName(CallbackInfoReturnable<String> cir) {
if (legacy$cachedDisplayName != null) {
cir.setReturnValue(legacy$cachedDisplayName);
}
}

@Inject(method = "getCustomName", at = @At("RETURN"))
private void legacy$cacheDisplayName(CallbackInfoReturnable<String> cir) {
legacy$cachedDisplayName = cir.getReturnValue();
}

@Inject(method = "setCustomName", at = @At("HEAD"))
private void legacy$resetCachedDisplayName(String displayName, CallbackInfoReturnable<ItemStack> cir) {
legacy$cachedDisplayName = null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.hankung.legacyenhance.mixin.cachedisplayname;

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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends EntityMixin {

@Inject(method = "getName", at = @At("RETURN"))
private void legacy$cachePlayerDisplayName(CallbackInfoReturnable<Text> cir) {
super.legacy$cacheDisplayName(cir);
}

@Inject(method = "getName", at = @At("HEAD"), cancellable = true)
private void legacy$returnCachedPlayerDisplayName(CallbackInfoReturnable<Text> cir) {
super.legacy$returnCachedDisplayName(cir);
}

@Redirect(method = "getName", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getHoverEvent()Lnet/minecraft/text/HoverEvent;"))
private HoverEvent legacy$onlyGetHoverEventInSinglePlayer(PlayerEntity instance) {
// Only needed in single player
return MinecraftClient.getInstance().isIntegratedServerRunning()
? ((PlayerEntityMixin) (Object) instance).getHoverEvent()
: null;
}

@Redirect(method = "getName", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Style;setHoverEvent(Lnet/minecraft/text/HoverEvent;)Lnet/minecraft/text/Style;"))
private Style legacy$onlySetHoverEventInSinglePlayer(Style instance, HoverEvent event) {
return MinecraftClient.getInstance().isIntegratedServerRunning()
? instance.setHoverEvent(event)
: null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.hankung.legacyenhance.mixin.cancellightmap;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import me.hankung.legacyenhance.LegacyEnhance;
import net.minecraft.client.render.GameRenderer;

@Mixin(GameRenderer.class)
public class GameRendererMixin {

@Unique
private boolean legacy$createdLightmap;

@Inject(method = "updateLightmap", at = @At("HEAD"), cancellable = true)
private void legacy$cancelLightmapBuild(CallbackInfo ci) {
if (LegacyEnhance.CONFIG.generalFullBright.get() && this.legacy$createdLightmap) {
ci.cancel();
}
}

@Inject(method = "updateLightmap", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;pop()V"))
private void legacy$setCreatedLightmap(CallbackInfo ci) {
this.legacy$createdLightmap = true;
}

}
Loading

0 comments on commit 382e90c

Please sign in to comment.