Skip to content

Commit

Permalink
remap primitive to Nostalgia mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolij committed Jun 21, 2024
1 parent 6b37355 commit 5514dd2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 38 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ legacy_fabric_api_version = 1.9.1+1.7.10
## Primitive Fabric
# https://babric.github.io/develop/
primitive_minecraft_version = b1.7.3
primitive_mappings_version = a00e3b0
# https://maven.wispforest.io/#/releases/me/alphamode/nostalgia/
primitive_mappings_version = b1.7.3+build.19
babric_version = 0.15.6-babric.2

# https://maven.glass-launcher.net/#/releases/net/modificationstation/StationAPI
Expand Down
12 changes: 11 additions & 1 deletion primitive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ val mod: Configuration by configurations.creating {
configurations.runtimeClasspath.get().extendsFrom(this)
}

repositories {
maven("https://maven.wispforest.io")
}

unimined.minecraft {
side("client")

Expand All @@ -28,7 +32,13 @@ unimined.minecraft {

mappings {
babricIntermediary()
biny("primitive_mappings_version"())
@Suppress("UnstableApiUsage")
mapping("me.alphamode:nostalgia:${"primitive_mappings_version"()}:v2", "nostalgia") {
outputs("nostalgia", true) { listOf("intermediary") }
mapNamespace("named", "nostalgia")
sourceNamespace("intermediary")
renest()
}
devFallbackNamespace("intermediary")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package dev.nolij.zume.mixin.primitive;

import net.minecraft.class_555;
import net.minecraft.client.util.SmoothUtil;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.util.SmoothFloat;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(class_555.class)
@Mixin(GameRenderer.class)
public interface GameRendererAccessor {

@Accessor("field_2353")
void setCinematicYawSmoother(SmoothUtil value);
@Accessor("field_2354")
void setCinematicPitchSmoother(SmoothUtil value);
@Accessor("smoothTurnX")
void setSmoothTurnX(SmoothFloat value);
@Accessor("smoothTurnY")
void setSmoothTurnY(SmoothFloat value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.nolij.zume.impl.Zume;
import net.minecraft.class_555;
import net.minecraft.client.renderer.GameRenderer;
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.CallbackInfo;

@Mixin(class_555.class)
@Mixin(GameRenderer.class)
public abstract class GameRendererMixin {

@Inject(method = "method_1844", at = @At("HEAD"))
@Inject(method = "render(F)V", at = @At("HEAD"))
public void zume$render$HEAD(CallbackInfo ci) {
Zume.renderHook();
}

@ModifyReturnValue(method = "method_1848", at = @At("TAIL"))
@ModifyReturnValue(method = "getFov", at = @At("TAIL"))
public float zume$getFov$TAIL(float original) {
if (Zume.isFOVHookActive())
return (float) Zume.fovHook(original);

return original;
}

@ModifyExpressionValue(method = "method_1844", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;cinematicMode:Z"))
@ModifyExpressionValue(method = "render(F)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;smoothCamera:Z"))
public boolean zume$updateMouse$smoothCameraEnabled(boolean original) {
return Zume.cinematicCameraEnabledHook(original);
}

@ModifyExpressionValue(method = "method_1844", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;mouseSensitivity:F"))
@ModifyExpressionValue(method = "render(F)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;mouseSensitivity:F"))
public float zume$updateMouse$mouseSensitivity(float original) {
return (float) Zume.mouseSensitivityHook(original);
}

@ModifyExpressionValue(method = "method_1851", at = @At(value = "FIELD", target = "Lnet/minecraft/class_555;field_2359:F"))
@ModifyExpressionValue(method = "method_1851", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;field_2359:F"))
public float zume$transformCamera$thirdPersonDistance(float original) {
return (float) Zume.thirdPersonCameraHook(original);
}

@ModifyExpressionValue(method = "method_1851", at = @At(value = "FIELD", target = "Lnet/minecraft/class_555;field_2360:F"))
@ModifyExpressionValue(method = "method_1851", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;field_2360:F"))
public float zume$transformCamera$lastThirdPersonDistance(float original) {
return (float) Zume.thirdPersonCameraHook(original);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Mixin(Minecraft.class)
public interface MinecraftAccessor {

@Accessor("INSTANCE")
@Accessor("instance")
static Minecraft getInstance() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import dev.nolij.zume.impl.Zume;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.world.entity.player.Inventory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(value = Minecraft.class, priority = 500)
public abstract class MinecraftMixin {

@WrapWithCondition(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;method_692(I)V"))
public boolean onMouseScroll$scrollInHotbar(PlayerInventory instance, int scrollAmount) {
@WrapWithCondition(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;swapPaint(I)V"))
public boolean onMouseScroll$scrollInHotbar(Inventory instance, int scrollAmount) {
return !Zume.mouseScrollHook(scrollAmount);
}

Expand Down
26 changes: 14 additions & 12 deletions primitive/src/main/java/dev/nolij/zume/primitive/PrimitiveZume.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.mine_diver.unsafeevents.listener.EventListener;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.SmoothUtil;
import net.minecraft.client.Keybind;
import net.minecraft.util.SmoothFloat;
import net.modificationstation.stationapi.api.client.event.option.KeyBindingRegisterEvent;

import java.util.List;
Expand All @@ -30,8 +30,8 @@ public void onInitializeClient() {

@Override
public boolean isZoomPressed() {
//noinspection UnreachableCode
return MinecraftAccessor.getInstance().currentScreen == null && ZumeKeyBind.ZOOM.isPressed();
//noinspection UnreachableCode,DataFlowIssue
return MinecraftAccessor.getInstance().screen == null && ZumeKeyBind.ZOOM.isPressed();
}

@Override
Expand All @@ -46,24 +46,26 @@ public boolean isZoomOutPressed() {

@Override
public CameraPerspective getCameraPerspective() {
//noinspection UnreachableCode
return MinecraftAccessor.getInstance().options.thirdPerson ? CameraPerspective.THIRD_PERSON : CameraPerspective.FIRST_PERSON;
//noinspection UnreachableCode,DataFlowIssue
return MinecraftAccessor.getInstance().options.thirdPersonView
? CameraPerspective.THIRD_PERSON
: CameraPerspective.FIRST_PERSON;
}

@Override
public void onZoomActivate() {
//noinspection ConstantValue
if (Zume.config.enableCinematicZoom && !MinecraftAccessor.getInstance().options.cinematicMode) {
final GameRendererAccessor gameRenderer = (GameRendererAccessor) MinecraftAccessor.getInstance().field_2818;
gameRenderer.setCinematicYawSmoother(new SmoothUtil());
gameRenderer.setCinematicPitchSmoother(new SmoothUtil());
//noinspection DataFlowIssue
if (Zume.config.enableCinematicZoom && !MinecraftAccessor.getInstance().options.smoothCamera) {
final GameRendererAccessor gameRenderer = (GameRendererAccessor) MinecraftAccessor.getInstance().gameRenderer;
gameRenderer.setSmoothTurnX(new SmoothFloat());
gameRenderer.setSmoothTurnY(new SmoothFloat());
}
}

@ProGuardKeep.WithObfuscation
@EventListener
public static void registerKeyBindings(KeyBindingRegisterEvent event) {
final List<KeyBinding> binds = event.keyBindings;
final List<Keybind> binds = event.keyBindings;

for (final ZumeKeyBind keyBind : ZumeKeyBind.values()) {
binds.add(keyBind.value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.nolij.zume.primitive;

import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.Keybind;
import org.lwjgl.input.Keyboard;

public enum ZumeKeyBind {
Expand All @@ -11,14 +11,14 @@ public enum ZumeKeyBind {

;

public final KeyBinding value;
public final Keybind value;

public boolean isPressed() {
return Keyboard.isKeyDown(value.code);
return Keyboard.isKeyDown(value.keyId);
}

ZumeKeyBind(String translationKey, int code) {
this.value = new KeyBinding(translationKey, code);
ZumeKeyBind(String translationKey, int keyId) {
this.value = new Keybind(translationKey, keyId);
}

}

0 comments on commit 5514dd2

Please sign in to comment.