Skip to content

Commit

Permalink
Update some mixins to use ME + enable back some that were wrongfully …
Browse files Browse the repository at this point in the history
…disabled
  • Loading branch information
thecatcore committed Nov 3, 2023
1 parent df7df52 commit 9ab46ef
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Random;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -145,17 +147,17 @@ public boolean handleBackgroundMusic() {
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "handleBackgroundMusic", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundMap;getRandomSound()Lnet/minecraft/client/sound/SoundEntry;"))
public SoundEntry handleBackgroundMusic(SoundMap instance) {
@WrapOperation(method = "handleBackgroundMusic", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundMap;getRandomSound()Lnet/minecraft/client/sound/SoundEntry;"))
public SoundEntry handleBackgroundMusic(SoundMap instance, Operation<SoundEntry> operation) {
if (this.client != null
&& this.client.player != null
&& !this.client
.player
.world
.isAboveGroundCached(MathHelper.floor(this.client.player.x), MathHelper.floor(this.client.player.y), MathHelper.floor(this.client.player.z))) {
return this.cave.getRandomSound();
return operation.call(this.cave);
} else {
return this.music.getRandomSound();
return operation.call(this.music);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class ClientInteractionManagerMixin {
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "useItemOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;useOnBlock(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;IIII)Z"))
private boolean forge$onDestroyCurrentItem(ItemStack instance, PlayerEntity arg2, World world, int j, int k, int l, int i) {
if (!instance.useOnBlock(arg2, world, j, k, l, i)) {
@WrapOperation(method = "useItemOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;useOnBlock(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;IIII)Z"))
private boolean forge$onDestroyCurrentItem(ItemStack instance, PlayerEntity arg2, World world, int j, int k, int l, int i, Operation<Boolean> operation) {
if (!operation.call(instance, arg2, world, j, k, l, i)) {
return false;
} else {
if (instance.count == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.betterthanupdates.forge.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import forge.ForgeHooksClient;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -16,17 +18,17 @@
@Environment(EnvType.CLIENT)
@Mixin(GameRenderer.class)
public abstract class GameRendererMixin {
@Redirect(method = "method_1841", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldEventRenderer;method_1547(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/HitResult;ILnet/minecraft/item/ItemStack;F)V"))
private void forge$method_1547(WorldEventRenderer instance, PlayerEntity arg2, HitResult i, int arg3, ItemStack f, float v) {
@WrapOperation(method = "method_1841", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldEventRenderer;method_1547(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/HitResult;ILnet/minecraft/item/ItemStack;F)V"))
private void forge$method_1547(WorldEventRenderer instance, PlayerEntity arg2, HitResult i, int arg3, ItemStack f, float v, Operation<Void> operation) {
if (!ForgeHooksClient.onBlockHighlight(instance, arg2, i, arg3, f, v)) {
instance.method_1547(arg2, i, arg3, f, v);
operation.call(instance, arg2, i, arg3, f, v);
}
}

@Redirect(method = "method_1841", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldEventRenderer;method_1554(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/HitResult;ILnet/minecraft/item/ItemStack;F)V"))
private void forge$method_1554(WorldEventRenderer instance, PlayerEntity arg2, HitResult i, int arg3, ItemStack f, float v) {
@WrapOperation(method = "method_1841", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldEventRenderer;method_1554(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/HitResult;ILnet/minecraft/item/ItemStack;F)V"))
private void forge$method_1554(WorldEventRenderer instance, PlayerEntity arg2, HitResult i, int arg3, ItemStack f, float v, Operation<Void> operation) {
if (!ForgeHooksClient.onBlockHighlight(instance, arg2, i, arg3, f, v)) {
instance.method_1554(arg2, i, arg3, f, v);
operation.call(instance, arg2, i, arg3, f, v);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.ArrayList;
import java.util.List;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import forge.BlockTextureParticles;
import forge.ITextureProvider;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -70,10 +73,10 @@ public abstract class ParticleManagerMixin implements ForgeParticleManager {
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "method_324", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/particle/ParticleEntity;method_2002(Lnet/minecraft/client/render/Tessellator;FFFFFF)V", ordinal = 0))
private void forge$method_2002(ParticleEntity entityfx, Tessellator tessellator, float f, float f1, float f5, float f2, float f3, float f4) {
@WrapOperation(method = "method_324", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/particle/ParticleEntity;method_2002(Lnet/minecraft/client/render/Tessellator;FFFFFF)V", ordinal = 0))
private void forge$method_2002(ParticleEntity entityfx, Tessellator tessellator, float f, float f1, float f5, float f2, float f3, float f4, Operation<Void> operation) {
if (!(entityfx instanceof DiggingParticleEntity)) {
entityfx.method_2002(tessellator, f, f1, f5, f2, f3, f4);
operation.call(entityfx, tessellator, f, f1, f5, f2, f3, f4);
}
}

Expand Down Expand Up @@ -117,50 +120,22 @@ public abstract class ParticleManagerMixin implements ForgeParticleManager {
this.effectList.clear();
}

Block cachedBlock;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "addBlockBreakParticles", at = @At("HEAD"))
private void forge$addBlockBreakParticles(int j, int k, int l, int m, int par5, CallbackInfo ci) {
if (m != 0) {
this.cachedBlock = Block.BY_ID[m];
}
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "addBlockBreakParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;addParticle(Lnet/minecraft/client/entity/particle/ParticleEntity;)V"))
private void forge$addBlockBreakParticles(ParticleManager instance, ParticleEntity particleEntity) {
((ForgeParticleManager) instance).addDigParticleEffect((DiggingParticleEntity) particleEntity, this.cachedBlock);
}

Block cachedBlock2;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "addBlockClickParticle", at = @At("HEAD"))
private void forge$addBlockClickParticle(int j, int k, int l, int par4, CallbackInfo ci) {
int id = this.world.getBlockId(j, k, l);

if (id != 0) {
this.cachedBlock2 = Block.BY_ID[id];
}
private void forge$addBlockBreakParticles(ParticleManager instance, ParticleEntity particleEntity, @Local(ordinal = 0) Block block) {
((ForgeParticleManager) instance).addDigParticleEffect((DiggingParticleEntity) particleEntity, block);
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "addBlockClickParticle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;addParticle(Lnet/minecraft/client/entity/particle/ParticleEntity;)V"))
private void forge$addBlockClickParticle(ParticleManager instance, ParticleEntity particleEntity) {
((ForgeParticleManager) instance).addDigParticleEffect((DiggingParticleEntity) particleEntity, this.cachedBlock2);
private void forge$addBlockClickParticle(ParticleManager instance, ParticleEntity particleEntity, @Local(ordinal = 0) Block block) {
((ForgeParticleManager) instance).addDigParticleEffect((DiggingParticleEntity) particleEntity, block);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package io.github.betterthanupdates.forge.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import forge.IArmorTextureProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.ArmorItem;
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.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.PlayerRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

@Environment(EnvType.CLIENT)
@Mixin(PlayerRenderer.class)
Expand All @@ -23,31 +21,16 @@ private PlayerRendererMixin(EntityModel entityModel, float f) {
super(entityModel, f);
}

Item cachedItem;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "render(Lnet/minecraft/entity/player/PlayerEntity;IF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;"))
private void forge$render(PlayerEntity entityplayer, int i, float f, CallbackInfoReturnable<Boolean> cir) {
ItemStack itemstack = entityplayer.inventory.getArmorItem(3 - i);

if (itemstack != null) {
this.cachedItem = itemstack.getItem();
}
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "render(Lnet/minecraft/entity/player/PlayerEntity;IF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/PlayerRenderer;bindTexture(Ljava/lang/String;)V"))
private void forge$bindTexture(PlayerRenderer instance, String s) {
if (this.cachedItem != null && this.cachedItem instanceof IArmorTextureProvider) {
instance.bindTexture(((IArmorTextureProvider) this.cachedItem).getArmorTextureFile());
@WrapOperation(method = "render(Lnet/minecraft/entity/player/PlayerEntity;IF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/PlayerRenderer;bindTexture(Ljava/lang/String;)V"))
private void forge$bindTexture(PlayerRenderer instance, String s, Operation<Void> operation, @Local(ordinal = 0)ArmorItem item) {
if (item instanceof IArmorTextureProvider) {
operation.call(instance, ((IArmorTextureProvider) item).getArmorTextureFile());
} else {
instance.bindTexture(s);
operation.call(instance, s);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.github.betterthanupdates.forge.mixin.client.nostation;

import com.llamalad7.mixinextras.sugar.Local;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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.CallbackInfo;

import net.minecraft.block.Block;
import net.minecraft.client.ClientInteractionManager;
Expand All @@ -23,47 +22,21 @@ public MultiplayerClientInteractionManagerMixin(Minecraft client) {
super(client);
}

int cachedI, cachedJ, cachedK;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "destroyFireAndBreakBlock", at = @At("HEAD"))
private void forge$method_1707(int j, int k, int l, int par4, CallbackInfo ci) {
this.cachedI = j;
this.cachedJ = k;
this.cachedK = l;
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "destroyFireAndBreakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getHardness(Lnet/minecraft/entity/player/PlayerEntity;)F"))
private float forge$method_1707(Block instance, PlayerEntity playerEntity) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, this.cachedI, this.cachedJ, this.cachedK);
}

int cachedI2, cachedJ2, cachedK2;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "dig", at = @At("HEAD"))
private void forge$method_1721(int j, int k, int l, int par4, CallbackInfo ci) {
this.cachedI2 = j;
this.cachedJ2 = k;
this.cachedK2 = l;
private float forge$method_1707(Block instance, PlayerEntity playerEntity, @Local(ordinal = 0) int i, @Local(ordinal = 1) int j, @Local(ordinal = 2) int k) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, i, j, k);
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "dig", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getHardness(Lnet/minecraft/entity/player/PlayerEntity;)F"))
private float forge$method_1721(Block instance, PlayerEntity playerEntity) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, this.cachedI2, this.cachedJ2, this.cachedK2);
private float forge$method_1721(Block instance, PlayerEntity playerEntity, @Local(ordinal = 0) int i, @Local(ordinal = 1) int j, @Local(ordinal = 2) int k) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, i, j, k);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.github.betterthanupdates.forge.mixin.client.nostation;

import com.llamalad7.mixinextras.sugar.Local;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.block.Block;
import net.minecraft.client.ClientInteractionManager;
Expand All @@ -26,69 +23,31 @@ public SinglePlayerInteractionManagerMixin(Minecraft client) {
super(client);
}

@Unique
int cachedMeta = 0;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "breakBlock", at = @At("HEAD"))
private void forge$method_1716(int i, int j, int k, int l, CallbackInfoReturnable<Boolean> cir) {
this.cachedMeta = this.client.world.getBlockMeta(i, j, k);
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "breakBlock", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/entity/player/AbstractClientPlayerEntity;canRemoveBlock(Lnet/minecraft/block/Block;)Z"))
private boolean forge$method_1716(AbstractClientPlayerEntity instance, Block block) {
return ((ForgeBlock) block).canHarvestBlock(instance, this.cachedMeta);
}

int cachedI, cachedJ, cachedK;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "destroyFireAndBreakBlock", at = @At("HEAD"))
private void forge$method_1707(int i, int j, int k, int l, CallbackInfo ci) {
this.cachedI = i;
this.cachedJ = j;
this.cachedK = k;
private boolean forge$method_1716(AbstractClientPlayerEntity instance, Block block, @Local(ordinal = 5) int meta) {
return ((ForgeBlock) block).canHarvestBlock(instance, meta);
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "destroyFireAndBreakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getHardness(Lnet/minecraft/entity/player/PlayerEntity;)F"))
private float forge$method_1707(Block instance, PlayerEntity playerEntity) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, this.cachedI, this.cachedJ, this.cachedK);
}

int cachedI2, cachedJ2, cachedK2;

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Inject(method = "dig", at = @At("HEAD"))
private void forge$method_1721(int i, int j, int k, int l, CallbackInfo ci) {
this.cachedI2 = i;
this.cachedJ2 = j;
this.cachedK2 = k;
private float forge$method_1707(Block instance, PlayerEntity playerEntity, @Local(ordinal = 0) int i, @Local(ordinal = 1) int j, @Local(ordinal = 2) int k) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, i, j, k);
}

/**
* @author Eloraam
* @reason implement Forge hooks
*/
@Redirect(method = "dig", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getHardness(Lnet/minecraft/entity/player/PlayerEntity;)F"))
private float forge$method_1721(Block instance, PlayerEntity playerEntity) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, this.cachedI2, this.cachedJ2, this.cachedK2);
private float forge$method_1721(Block instance, PlayerEntity playerEntity, @Local(ordinal = 0) int i, @Local(ordinal = 1) int j, @Local(ordinal = 2) int k) {
return ((ForgeBlock) instance).blockStrength(this.client.world, playerEntity, i, j, k);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.betterthanupdates.modloader.mixin;
package io.github.betterthanupdates.modloader.mixin.nostation;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.betterthanupdates.reforged.mixin.client;
package io.github.betterthanupdates.reforged.mixin.client.nostation;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
4 changes: 3 additions & 1 deletion apron/src/main/resources/forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"client.PlayerRendererMixin",
"client.TessellatorMixin",
"client.TextureManagerMixin",
"client.nostation.MultiplayerClientInteractionManagerMixin"
"client.VanillaTessellatorMixin",
"client.nostation.MultiplayerClientInteractionManagerMixin",
"client.nostation.SinglePlayerInteractionManagerMixin"
],
"server": [
"server.class_417Mixin",
Expand Down
Loading

0 comments on commit 9ab46ef

Please sign in to comment.