Skip to content

Commit

Permalink
feat: Improve trinket setHolder calls
Browse files Browse the repository at this point in the history
Now trinkets link to their holders much more reliably, that also fixes a bug with empty trinket slot not working with `apoli:holder` actions
  • Loading branch information
shap-po committed Aug 30, 2024
1 parent 7d61264 commit 98a9ea5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.shap_po.shappoli.mixin.integration.trinkets;

import com.github.shap_po.shappoli.integration.trinkets.power.ActionOnTrinketChangePower;
import com.github.shap_po.shappoli.util.InventoryUtil;
import dev.emi.trinkets.api.SlotType;
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
Expand Down Expand Up @@ -47,8 +46,6 @@ private void tick(CallbackInfo info) {
ItemStack newStack = inventory.getStack(index);
ItemStack newStackCopy = newStack.copy(); // old stack is removed when unequipped

InventoryUtil.setHolder(newStack, entity); // link the stack to the player, so it can be used in powers

if (!ItemStack.areEqual(newStack, oldStack)) {
// Call unequip powers on old trinket
PowerHolderComponent.withPowers(entity, ActionOnTrinketChangePower.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.shap_po.shappoli.mixin.integration.trinkets;

import com.github.shap_po.shappoli.util.InventoryUtil;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.emi.trinkets.api.TrinketInventory;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(TrinketInventory.class)
public class TrinketInventoryMixin {
@ModifyReturnValue(method = "getStack", at = @At("RETURN"))
private ItemStack shappoli$modifyGetStack(ItemStack stack) {
LivingEntity entity = ((TrinketInventory) (Object) this).getComponent().getEntity();
InventoryUtil.setHolder(stack, entity);
return stack;
}
}
1 change: 1 addition & 0 deletions src/main/resources/shappoli.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"VillagerEntityMixin",
"integration.trinkets.LivingEntityMixin",
"integration.trinkets.SurvivalTrinketSlotMixin",
"integration.trinkets.TrinketInventoryMixin",
"integration.trinkets.TrinketSlotMixin",
"integration.wildfire_gender.GenderLayerMixin"
],
Expand Down

0 comments on commit 98a9ea5

Please sign in to comment.