Skip to content

Commit

Permalink
fix mixin targets
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 18, 2024
1 parent 50a1c9a commit 84a4926
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import folk.sisby.starcaller.item.StardustItem;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.DyeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.ArmorDyeRecipe;
import net.minecraft.recipe.input.CraftingRecipeInput;
import net.minecraft.util.DyeColor;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,11 +15,11 @@

@Mixin(ArmorDyeRecipe.class)
public class MixinArmorDyeRecipe {
@ModifyReturnValue(method = "matches(Lnet/minecraft/inventory/RecipeInputInventory;Lnet/minecraft/world/World;)Z", at = @At("RETURN"))
public boolean dontMatchBadStardust(boolean original, RecipeInputInventory inventory, World world) {
@ModifyReturnValue(method = "matches(Lnet/minecraft/recipe/input/CraftingRecipeInput;Lnet/minecraft/world/World;)Z", at = @At("RETURN"))
public boolean dontMatchBadStardust(boolean original, CraftingRecipeInput input, World world) {
if (original) {
for (int i = 0; i < inventory.size(); ++i) {
ItemStack stack = inventory.getStack(i);
for (int i = 0; i < input.getSize(); ++i) {
ItemStack stack = input.getStackInSlot(i);
if (!stack.isEmpty()) {
if (stack.getItem() instanceof StardustItem) {
Long remainingTicks = StardustItem.getRemainingTicks(stack, world);
Expand All @@ -31,13 +31,13 @@ public boolean dontMatchBadStardust(boolean original, RecipeInputInventory inven
return original;
}

@ModifyReturnValue(method = "matches(Lnet/minecraft/inventory/RecipeInputInventory;Lnet/minecraft/world/World;)Z", at = @At("RETURN"))
public boolean dontMatchDarkDyes(boolean original, RecipeInputInventory inventory, World world) {
@ModifyReturnValue(method = "matches(Lnet/minecraft/recipe/input/CraftingRecipeInput;Lnet/minecraft/world/World;)Z", at = @At("RETURN"))
public boolean dontMatchDarkDyes(boolean original, CraftingRecipeInput input, World world) {
if (original) {
boolean hasStardust = false;
boolean hasDarkDye = false;
for (int i = 0; i < inventory.size(); ++i) {
ItemStack stack = inventory.getStack(i);
for (int i = 0; i < input.getSize(); ++i) {
ItemStack stack = input.getStackInSlot(i);
if (!stack.isEmpty()) {
if (stack.getItem() instanceof StardustItem) {
hasStardust = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(CraftingScreenHandler.class)
public class MixinCraftingScreenHandler {
@ModifyVariable(method = "updateResult", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/inventory/CraftingResultInventory;setStack(ILnet/minecraft/item/ItemStack;)V"), ordinal = 1)
private static ItemStack applyStardustEditor(ItemStack stack, ScreenHandler handler, World world, PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInventory) {
@ModifyArgs(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/CraftingResultInventory;setStack(ILnet/minecraft/item/ItemStack;)V"))
private static void applyStardustEditor(Args args, ScreenHandler handler, World world, PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInventory, @Nullable RecipeEntry<CraftingRecipe> recipe) {
ItemStack stack = args.get(1);
if (stack.contains(Starcaller.STAR) && stack.getItem() instanceof StardustItem) {
Text name = player.getDisplayName();
if (name != null) {
TextColor nameColor = name.getStyle().getColor();
stack.apply(Starcaller.STAR, null, s -> s.withEditor(player.getDisplayName().getString(), nameColor != null ? nameColor.getRgb() : 0xFFFFFF));
}
}
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class MixinClientWorld implements StarcallerWorld {
@Unique private int starcaller$iterations = 1500;
@Unique private List<Star> starcaller$stars = StarUtil.generateStars(starcaller$seed, starcaller$iterations);

@Inject(method = "method_23787", at = @At("HEAD"), cancellable = true)
@Inject(method = "getStarBrightness", at = @At("HEAD"), cancellable = true)
public void fullBrightStarsWithSpear(float f, CallbackInfoReturnable<Float> cir) {
if (MinecraftClient.getInstance().player != null && (MinecraftClient.getInstance().player.getMainHandStack().isOf(Starcaller.SPEAR) || MinecraftClient.getInstance().player.getOffHandStack().isOf(Starcaller.SPEAR))) {
cir.setReturnValue(1.0F);
Expand All @@ -35,7 +35,6 @@ public void fullBrightStarsWithSpear(float f, CallbackInfoReturnable<Float> cir)
StarcallerClient.groundStar(((ClientWorld) (Object) this), star);
}


@Override
public void starcaller$freeStar(PlayerEntity cause, Star star) {
StarcallerClient.freeStar(((ClientWorld) (Object) this), star);
Expand Down

0 comments on commit 84a4926

Please sign in to comment.