Skip to content

Commit

Permalink
refactor stuff and slow player but needs smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
CammiePone committed Jan 19, 2025
1 parent f466b6e commit 8de1864
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.cammiescorner.arcanuscontinuum.mixin.client;

import com.mojang.authlib.GameProfile;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
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(AbstractClientPlayer.class)
public abstract class AbstractClientPlayerMixin extends Player {
@Shadow protected Vec3 deltaMovementOnPreviousTick;

public AbstractClientPlayerMixin(Level level, BlockPos pos, float yRot, GameProfile gameProfile) { super(level, pos, yRot, gameProfile); }

@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void timeSlow(CallbackInfo info) {
// TODO figure out how to smooth this
if(level().getGameTime() % 2 == 0) {
deltaMovementOnPreviousTick = getDeltaMovement();
setOldPosAndRot();
tickCount++;
info.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.function.Supplier;

@Mixin(ClientLevel.class)
public abstract class ClientWorldMixin extends Level {
protected ClientWorldMixin(WritableLevelData worldProperties, ResourceKey<Level> registryKey, RegistryAccess registryManager, Holder<DimensionType> dimension, Supplier<ProfilerFiller> profiler, boolean client, boolean debug, long seed, int maxChainedNeighborUpdates) {
public abstract class ClientLevelMixin extends Level {
protected ClientLevelMixin(WritableLevelData worldProperties, ResourceKey<Level> registryKey, RegistryAccess registryManager, Holder<DimensionType> dimension, Supplier<ProfilerFiller> profiler, boolean client, boolean debug, long seed, int maxChainedNeighborUpdates) {
super(worldProperties, registryKey, registryManager, dimension, profiler, client, debug, seed, maxChainedNeighborUpdates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.spongepowered.asm.mixin.injection.At;

@Mixin(Gui.class)
public class InGameHudMixin {
public class GuiMixin {
@Shadow private int screenWidth;
@Shadow private int screenHeight;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HumanoidModel.class)
public abstract class BipedEntityModelMixin<T extends LivingEntity> extends AgeableListModel<T> implements ArmedModel, HeadedModel {
public abstract class HumanoidModelMixin<T extends LivingEntity> extends AgeableListModel<T> implements ArmedModel, HeadedModel {
@Shadow @Final public ModelPart rightArm;
@Shadow @Final public ModelPart leftArm;
@Shadow @Final public ModelPart head;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemInHandLayer.class)
public class HeldItemFeatureRendererMixin {
public class ItemInHandLayerMixin {
@Inject(method = "renderArmWithItem", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderItem(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemDisplayContext;ZLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemInHandRenderer.class)
public abstract class HeldItemRendererMixin {
public abstract class ItemInHandRendererMixin {
@Shadow @Final private Minecraft minecraft;
@Shadow private ItemStack mainHandItem;
@Shadow private float oMainHandHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.spongepowered.asm.mixin.injection.At;

@Mixin(LevelRenderer.class)
public class WorldRendererMixin {
public class LevelRendererMixin {
@ModifyExpressionValue(method = "renderLevel", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/ClientLevel;entitiesForRendering()Ljava/lang/Iterable;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.UUID;

@Mixin(Minecraft.class)
public abstract class MinecraftClientMixin implements ClientUtils {
public abstract class MinecraftMixin implements ClientUtils {
@Unique private boolean isCasting = false;
@Unique private int timer = 0;
@Unique private int mouseDownTimer = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,40 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(MouseHandler.class)
public class MouseMixin {
public class MouseHandlerMixin {
@Shadow @Final private Minecraft minecraft;

@ModifyArg(method = "turnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"), index = 0)
public double arcanuscontinuum$invertMouseX(double x) {
if(minecraft.player != null && minecraft.player.hasEffect(ArcanusMobEffects.DISCOMBOBULATE.get()))
return -x;

return x;
@ModifyArgs(method = "turnPlayer", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"
))
private void slowMouse(Args args) {
double x = args.get(0);
double y = args.get(1);
args.setAll(x * 0.5, y * 0.5);
}

@ModifyArg(method = "turnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"), index = 1)
public double arcanuscontinuum$invertMouseY(double y) {
if(minecraft.player != null && minecraft.player.hasEffect(ArcanusMobEffects.DISCOMBOBULATE.get()))
return -y;

return y;
@ModifyArgs(method = "turnPlayer", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"
))
public void invertMouseMovements(Args args) {
if(minecraft.player != null && minecraft.player.hasEffect(ArcanusMobEffects.DISCOMBOBULATE.get())) {
double x = args.get(0);
double y = args.get(1);
args.setAll(-x, -y);
}
}

@ModifyArg(method = "onPress", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/InputConstants$Type;getOrCreate(I)Lcom/mojang/blaze3d/platform/InputConstants$Key;"), index = 0)
public int arcanuscontinuum$invertMouseButtons(int i) {
@ModifyArg(method = "onPress", at = @At(
value = "INVOKE",
target = "Lcom/mojang/blaze3d/platform/InputConstants$Type;getOrCreate(I)Lcom/mojang/blaze3d/platform/InputConstants$Key;"
), index = 0)
public int invertMouseButtons(int i) {
if(minecraft.player != null && minecraft.player.hasEffect(ArcanusMobEffects.DISCOMBOBULATE.get())) {
return switch(i) {
case 0 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerRenderer.class)
public abstract class PlayerEntityRendererMixin extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> {
public PlayerEntityRendererMixin(EntityRendererProvider.Context ctx, PlayerModel<AbstractClientPlayer> model, float shadowRadius) {
public abstract class PlayerRendererMixin extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> {
public PlayerRendererMixin(EntityRendererProvider.Context ctx, PlayerModel<AbstractClientPlayer> model, float shadowRadius) {
super(ctx, model, shadowRadius);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Objects;

@Mixin(RenderTarget.class)
public abstract class FramebufferMixin implements StencilBuffer {
public abstract class RenderTargetMixin implements StencilBuffer {
@Unique private boolean isStencilBufferEnabled;

@Shadow public int width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private boolean slowTime(ServerLevel instance, Consumer<?> consumer, Entity enti
// TODO tie to being in a time dilation entity
if(getGameTime() % 2 == 0) {
entity.setOldPosAndRot();
entity.tickCount++;
return false;
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/resources/arcanuscontinuum.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@
"datagen.RegistrySetBuilderMixin"
],
"client": [
"client.BipedEntityModelMixin",
"client.ClientWorldMixin",
"client.AbstractClientPlayerMixin",
"client.ClientLevelMixin",
"client.CraftingScreenMixin",
"client.FramebufferMixin",
"client.HeldItemFeatureRendererMixin",
"client.HeldItemRendererMixin",
"client.InGameHudMixin",
"client.GuiMixin",
"client.HumanoidModelMixin",
"client.ItemInHandLayerMixin",
"client.ItemInHandRendererMixin",
"client.ItemRendererMixin",
"client.LevelRendererMixin",
"client.LivingEntityRendererMixin",
"client.MinecraftClientMixin",
"client.MouseMixin",
"client.PlayerEntityRendererMixin",
"client.WorldRendererMixin"
"client.MinecraftMixin",
"client.MouseHandlerMixin",
"client.PlayerRendererMixin",
"client.RenderTargetMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 8de1864

Please sign in to comment.