Skip to content

Commit

Permalink
Merge branch 'main' into twoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Nov 21, 2024
2 parents 5e92851 + 3dd2fba commit 7a252c5
Show file tree
Hide file tree
Showing 38 changed files with 393 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
java-version: "21"

- uses: actions/cache@v4
with:
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This work, "PolyPatcher", is adapted from ["Patcher"](https://sk1er.club/mods/pa
- **Resource Exploit Fix** - Resolve an exploit in 1.8 allowing servers to look through directories. *default
- **Forge Chest Behavior** - Resolve forge changing vanilla chest behavior. *default
- **Vanilla Held Item Lighting** *(not in original)* - Amends a Forge bug causing item sides to have incorrect lighting compared to Vanilla 1.8. *default
- **OptiFine Custom Sky Fix** *(toggle not in original)* - Resolve OptiFine creating a "black box" effect at the bottom of the sky when using custom skies. Changes the rendering of the normal sky. *default
</details>
<details>
<summary>Experimental</summary>
Expand Down Expand Up @@ -228,6 +229,11 @@ This work, "PolyPatcher", is adapted from ["Patcher"](https://sk1er.club/mods/pa

# Changes from original mod

PolyPatcher 1.10.1:
- Add toggle for "OptiFine Custom Sky Fix"
- Fix compatibility with NormalASM
- Fix alpha not being set when rendering container slots

PolyPatcher 1.10.0:
- Boost performance by only rendering special tile entities once instead of twice per frame (e.g beacons)
- Boost performance by unloading tile entities quicker
Expand Down Expand Up @@ -349,8 +355,8 @@ This list may not always be up-to-date. To view an updated list, click [here](ht
<details>
<summary>License disclaimers</summary>

This work, "PolyPatcher", uses code from CaffeineMC's "lithium-fabric", licensed under the LGPL-3.0 license. The original license is included in the repository.
https://github.com/CaffeineMC/lithium-fabric/tree/develop
https://github.com/CaffeineMC/lithium-fabric/blob/develop/LICENSE.txt
PolyPatcher uses code from [CaffeineMC's lithium mod](https://github.com/CaffeineMC/lithium-fabric/tree/develop), licensed under the [LGPL-3.0 license](https://github.com/CaffeineMC/lithium-fabric/blob/develop/LICENSE.txt).

PolyPatcher uses code from [CaffeineMC's hydrogen mod](https://github.com/CaffeineMC/hydrogen-fabric/tree/develop), licensed under the [LGPL-3.0 license](https://github.com/CaffeineMC/hydrogen-fabric/blob/1.17.x/LICENSE.txt).

</details>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

preprocess {
strictExtraMappings.set(true)
"1.12.2-forge"(11202, "srg") {
"1.8.9-forge"(10809, "srg", file("versions/1.12.2-1.8.9.txt"))
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/club/sk1er/patcher/config/PatcherConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class PatcherConfig extends Config {
title = "Keyboard Layout",
description = "The layout of your keyboard, used to fix input bugs accordingly.",
category = "Bug Fixes", subcategory = "Linux",
options = {"QWERTY", "BE AZERTY", "FR AZERTY"}
options = {"QWERTY", "BE AZERTY", "FR AZERTY", "DE QWERTZ"}
)
public static int keyboardLayout = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@Mixin(EventBus.class)
public interface EventBusAccessor {
@Accessor
@Accessor(remap = false)
int getBusID();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Mixin(targets = "Config")
public interface ConfigAccessor {
@Dynamic("OptiFine")
@Invoker
@Invoker(remap = false)
static boolean invokeIsCustomColors() {
throw new AssertionError("Mixin did not inject");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Mixin(targets = "net.optifine.CustomColors")
public interface CustomColorsAccessor {
@Dynamic("OptiFine")
@Invoker
@Invoker(remap = false)
public static int invokeGetTextColor(int index, int color) {
throw new AssertionError("Mixin failed to inject into OptiFine");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import net.minecraft.client.gui.ServerListEntryNormal;
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.CallbackInfo;

import java.net.UnknownHostException;
import java.util.concurrent.*;
Expand Down Expand Up @@ -42,19 +44,23 @@ public class ServerListEntryNormalMixin_BufferFix {
// But it should be good enough still
// Can't bother to mixin onto some other classes just to change that (rn at least).
@Unique
private static final int patcher$serverCountCache;
static {
patcher$serverCountCache = new ServerList(Minecraft.getMinecraft()).countServers();
// Note: not even sure this reassignement works since the field is final
patcher$threadPoolExecutor = new ScheduledThreadPoolExecutor(Math.min(patcher$serverCountCache + 5, MAX_THREAD_COUNT_PINGER), (new ThreadFactoryBuilder()).setNameFormat("Patcher Server Pinger #%d").setDaemon(true).build());
field_148302_b = patcher$threadPoolExecutor;
}
private static int patcher$serverCountCache;
@Unique
private final ScheduledExecutorService patcher$timeoutExecutor = Executors.newScheduledThreadPool(Math.min(patcher$serverCountCache + 5, MAX_THREAD_COUNT_TIMEOUT));

@Unique
private static int patcher$runningTaskCount = 0;

@SuppressWarnings("AccessStaticViaInstance")
@Inject(method = "<init>", at = @At("RETURN"))
private void patcher$init(GuiMultiplayer p_i45048_1_, ServerData p_i45048_2_, CallbackInfo ci) {
if (patcher$threadPoolExecutor == null) {
patcher$serverCountCache = new ServerList(Minecraft.getMinecraft()).countServers();
patcher$threadPoolExecutor = new ScheduledThreadPoolExecutor(Math.min(patcher$serverCountCache + 5, MAX_THREAD_COUNT_PINGER), (new ThreadFactoryBuilder()).setNameFormat("Patcher Server Pinger #%d").setDaemon(true).build());
this.field_148302_b = patcher$threadPoolExecutor;
}
}

@Unique
private Runnable patcher$getPingTask() {
return new Thread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Mixin(BlockChest.class)
public class BlockChestMixin_VanillaSlabChests {
//#if MC<11200
@Redirect(method = "isBelowSolidBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isSideSolid(Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;Z)Z"))
@Redirect(method = "isBelowSolidBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isSideSolid(Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;Z)Z", remap = false), remap = true)
public boolean patcher$isBelowSolidBlock(World instance, BlockPos blockPos, EnumFacing enumFacing, boolean b) {
return ((BlockExt) instance.getBlockState(blockPos).getBlock()).patcher$doesSideBlockChestOpening(instance, blockPos, enumFacing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
@Mixin(Block.class)
public abstract class BlockMixin_VanillaSlabChests implements BlockExt {
//#if MC<11200
@Shadow
@Shadow(remap = false)
public abstract String getRegistryName();

@Shadow
public abstract boolean isNormalCube();

@Shadow
@Shadow(remap = false)
public abstract boolean isSideSolid(IBlockAccess par1, BlockPos par2, EnumFacing par3);

public boolean patcher$doesSideBlockChestOpening(IBlockAccess world, BlockPos pos, EnumFacing side) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Pseudo
@Mixin(targets = "club.sk1er.mods.levelhead.render.AboveHeadRender")
@Mixin(targets = "club.sk1er.mods.levelhead.render.AboveHeadRender", remap = false)
public class AboveHeadRender_ReFixNametagPerspective {

@Dynamic("Levelhead")
@ModifyArg(method = "renderName", at = @org.spongepowered.asm.mixin.injection.At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics$GL;rotate(FFFF)V", ordinal = 1), index = 0)
@ModifyArg(method = "renderName", at = @org.spongepowered.asm.mixin.injection.At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics$GL;rotate(FFFF)V", ordinal = 1), index = 0, remap = false)
private float patcher$fixNametagPerspective(float f) {
GameSettings gameSettings = Minecraft.getMinecraft().gameSettings;
if (gameSettings != null && gameSettings.thirdPersonView == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,54 @@

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
//#if MC==11202
//$$ import net.minecraft.inventory.ClickType;
//#endif
import net.minecraft.inventory.Slot;
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;

@Mixin(GuiContainer.class)
public abstract class GuiContainerMixin_MouseBindFix extends GuiScreen {
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
//#if MC==10809
@Shadow
private Slot theSlot;

@Shadow
protected abstract void handleMouseClick(Slot par1, int par2, int par3, int par4);
//#else
//$$ @Shadow
//$$ private Slot hoveredSlot;
//$$
//$$ @Shadow
//$$ protected abstract void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type);
//#endif

@Inject(method = "mouseClicked", at = @At("HEAD"))
private void patcher$checkCloseClick(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) {
if (mouseButton - 100 == mc.gameSettings.keyBindInventory.getKeyCode()) {
int keyCode = mouseButton - 100;
if (keyCode == mc.gameSettings.keyBindInventory.getKeyCode()) {
mc.thePlayer.closeScreen();
ci.cancel();
}
//#if MC==10809
if (theSlot != null && theSlot.getHasStack()) {
if (keyCode == mc.gameSettings.keyBindPickBlock.getKeyCode()) {
handleMouseClick(theSlot, theSlot.slotNumber, 0, 3);
} else if (keyCode == mc.gameSettings.keyBindDrop.getKeyCode()) {
handleMouseClick(theSlot, theSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, 4);
}
}
//#else
//$$ if (hoveredSlot != null && hoveredSlot.getHasStack()) {
//$$ if (mc.gameSettings.keyBindPickBlock.isActiveAndMatches(keyCode)) {
//$$ handleMouseClick(hoveredSlot, hoveredSlot.slotNumber, 0, ClickType.CLONE);
//$$ } else if (mc.gameSettings.keyBindDrop.isActiveAndMatches(keyCode)) {
//$$ handleMouseClick(hoveredSlot, hoveredSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, ClickType.THROW);
//$$ }
//$$ }
//#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class RenderGlobalMixin_FixSkyVBOs {

@Dynamic("OptiFine")
@Shadow
@Shadow(remap = false)
private int renderDistance;

@Dynamic("OptiFine")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Mixin(GuiModList.class)
public class GuiModListMixin_RemoveDummyPatcherMod {

@Shadow
@Shadow(remap = false)
private ArrayList<ModContainer> mods;

@Inject(method = "<init>", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ImageBufferDownload_EarsMod {

@Dynamic("Ears Mod")
@Redirect(method = "parseUserSkin", at = @At(value = "INVOKE", target = "Lcom/unascribed/ears/Ears;preprocessSkin(Lnet/minecraft/client/renderer/ImageBufferDownload;Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;)V"))
@Redirect(method = "parseUserSkin", at = @At(value = "INVOKE", target = "Lcom/unascribed/ears/Ears;preprocessSkin(Lnet/minecraft/client/renderer/ImageBufferDownload;Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;)V", remap = false), remap = true)
private void preprocessSkin(ImageBufferDownload subject, BufferedImage rawImg, BufferedImage img) {
// this will never work because the way they find the locals is really really fragile and doesn't work with this mixin
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package club.sk1er.patcher.mixins.features;

import club.sk1er.patcher.config.PatcherConfig;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
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 java.util.Set;

@Mixin(World.class)
public abstract class WorldMixin_CameraPerspective {
@Unique
private static final Set<Block> patcher$ignoredBlocks = Sets.newHashSet(
Blocks.glass,
Blocks.stained_glass,
Blocks.glass_pane,
Blocks.stained_glass_pane,
Blocks.iron_bars
);

@Redirect(method = "rayTraceBlocks(Lnet/minecraft/util/Vec3;Lnet/minecraft/util/Vec3;ZZZ)Lnet/minecraft/util/MovingObjectPosition;", at = @At(value = "INVOKE", target =
//#if MC<=10809
"Lnet/minecraft/block/Block;getCollisionBoundingBox(Lnet/minecraft/world/World;Lnet/minecraft/util/BlockPos;Lnet/minecraft/block/state/IBlockState;)Lnet/minecraft/util/AxisAlignedBB;"
//#else
//$$ "Lnet/minecraft/block/state/IBlockState;getCollisionBoundingBox(Lnet/minecraft/world/IBlockAccess;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/math/AxisAlignedBB;"
//#endif
, ordinal = 1))
private AxisAlignedBB patcher$shouldCancel(
//#if MC<=10809
Block instance, World world, BlockPos blockPos, IBlockState iBlockState
//#else
//$$ IBlockState iBlockState, net.minecraft.world.IBlockAccess iBlockAccess, BlockPos blockPos
//#endif
) {
if (PatcherConfig.betterCamera && patcher$ignoredBlocks.contains(iBlockState.getBlock())) return null;
return
//#if MC<=10809
instance.getCollisionBoundingBox(world, blockPos, iBlockState);
//#else
//$$ iBlockState.getCollisionBoundingBox(iBlockAccess, blockPos);
//#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class EntityRendererMixin_LeftHandedness {
@Dynamic("OptiFine adds its own version of renderHand")
@Inject(
method = {"renderHand(FI)V", "renderHand(FIZZZ)V", "func_78476_b"},
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;enableLightmap()V", shift = At.Shift.AFTER)
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;enableLightmap()V", shift = At.Shift.AFTER, remap = true),
remap = false
)
private void patcher$flipHandSide(CallbackInfo ci) {
ItemRendererHook.isRenderingItemInFirstPerson = true;
Expand All @@ -41,7 +42,8 @@ public class EntityRendererMixin_LeftHandedness {
@Dynamic("OptiFine adds its own version of renderHand")
@Inject(
method = {"renderHand(FI)V", "renderHand(FIZZZ)V", "func_78476_b"},
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;disableLightmap()V")
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;disableLightmap()V", remap = true),
remap = false
)
private void patcher$resetFrontFace(CallbackInfo ci) {
if (PatcherConfig.leftHandInFirstPerson) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package club.sk1er.patcher.mixins.features.lefthand;

import club.sk1er.patcher.config.PatcherConfig;
import net.minecraft.client.renderer.ItemRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(ItemRenderer.class)
public class ItemRendererMixin_LeftHandedness {
//#if MC==10809
@ModifyConstant(method = "rotateWithPlayerRotations", constant = @Constant(floatValue = 1f, ordinal = 1))
private float leftHandRotate(float constant) {
return PatcherConfig.leftHandInFirstPerson ? -constant : constant;
}
//#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

@Mixin(RenderFish.class)
public class RenderFishMixin_LeftHandedness {
//#if MC==10809
@ModifyVariable(method = "doRender(Lnet/minecraft/entity/projectile/EntityFishHook;DDDFF)V", at = @At(value = "STORE", ordinal = 0))
private Vec3 patcher$flipFishingLine(Vec3 original) {
if (PatcherConfig.leftHandInFirstPerson) {
return new Vec3(-original.xCoord, original.yCoord, original.zCoord);
}
return original;
}
//#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

import me.jellysquid.mods.lithium.common.util.math.CompactSineLUT;
import net.minecraft.util.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MathHelper.class)
public class MathHelperMixin_CompactLUT {
@Mutable
@Shadow
@Final
private static float[] SIN_TABLE;

@SuppressWarnings("InstantiationOfUtilityClass")
@Inject(method = "<clinit>", at = @At("RETURN"))
private static void clearSinTable(CallbackInfo ci) {
new CompactSineLUT(); // Force class initialisation
MathHelperMixin_CompactLUT.SIN_TABLE = null;
}

/**
* @author Wyvest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class RenderChunkMixin_OptimizeSpecialTileEntities {
*/
@Redirect(method = "rebuildChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/CompiledChunk;addTileEntity(Lnet/minecraft/tileentity/TileEntity;)V"))
private void patcher$renderSpecialTileEntitiesOnce(CompiledChunk instance, TileEntity tileEntityIn) {
if (!patcher$tileEntitySpecialRenderer.forceTileEntityRender()) instance.addTileEntity(tileEntityIn);
if (patcher$tileEntitySpecialRenderer != null && !patcher$tileEntitySpecialRenderer.forceTileEntityRender()) instance.addTileEntity(tileEntityIn);
}
//#endif
}
Expand Down
Loading

0 comments on commit 7a252c5

Please sign in to comment.