Skip to content

Commit

Permalink
refactor: renamed ActionOnTrinketUpdatePower to ActionOnTrinketChange…
Browse files Browse the repository at this point in the history
…Power
  • Loading branch information
shap-po committed Aug 29, 2024
1 parent ad6500a commit b5fe571
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.apace100.apoli.data.ApoliDataTypes;
import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import io.github.apace100.apoli.power.factory.PowerFactories;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.calio.data.SerializableData;
import net.minecraft.entity.Entity;
Expand All @@ -21,15 +22,15 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

public class ActionOnTrinketUpdatePower extends Power {
public class ActionOnTrinketChangePower extends Power {
private final Consumer<Entity> entityActionOnEquip;
private final Consumer<Pair<World, StackReference>> itemActionOnEquip;
private final Consumer<Entity> entityActionOnUnequip;
private final Consumer<Pair<World, StackReference>> itemActionOnUnequip;
private final Predicate<Pair<World, ItemStack>> itemCondition;
private final List<TrinketSlotData> slots;

public ActionOnTrinketUpdatePower(
public ActionOnTrinketChangePower(
PowerType<?> type,
LivingEntity entity,
Consumer<Entity> entityActionOnEquip,
Expand Down Expand Up @@ -75,8 +76,8 @@ public void apply(LivingEntity actor, SlotReference slotReference, boolean isEqu
}

public static PowerFactory createFactory() {
return new PowerFactory<>(
Shappoli.identifier("action_on_trinket_update"),
PowerFactory<Power> factory = new PowerFactory<>(
Shappoli.identifier("action_on_trinket_change"),
new SerializableData()
.add("entity_action_on_equip", ApoliDataTypes.ENTITY_ACTION, null)
.add("item_action_on_equip", ApoliDataTypes.ITEM_ACTION, null)
Expand All @@ -86,7 +87,7 @@ public static PowerFactory createFactory() {
.add("slot", ShappoliTrinketsDataTypes.TRINKET_SLOT, null)
.add("slots", ShappoliTrinketsDataTypes.TRINKET_SLOTS, null)
,
data -> (type, player) -> new ActionOnTrinketUpdatePower(
data -> (type, player) -> new ActionOnTrinketChangePower(
type,
player,
data.get("entity_action_on_equip"),
Expand All @@ -97,5 +98,8 @@ public static PowerFactory createFactory() {
TrinketSlotData.getSlots(data)
)
).allowCondition();

PowerFactories.ALIASES.addPathAlias("action_on_trinket_update", factory.getSerializerId().getPath());
return factory;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.shap_po.shappoli.integration.trinkets.power.factory;

import com.github.shap_po.shappoli.integration.trinkets.power.ActionOnTrinketUpdatePower;
import com.github.shap_po.shappoli.integration.trinkets.power.ActionOnTrinketChangePower;
import com.github.shap_po.shappoli.integration.trinkets.power.PreventTrinketEquipPower;
import com.github.shap_po.shappoli.integration.trinkets.power.PreventTrinketUnequipPower;
import io.github.apace100.apoli.power.factory.PowerFactory;
Expand All @@ -10,7 +10,7 @@

public class PowerFactories {
public static void register() {
register(ActionOnTrinketUpdatePower::createFactory);
register(ActionOnTrinketChangePower::createFactory);
register(PreventTrinketEquipPower::createFactory);
register(PreventTrinketUnequipPower::createFactory);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.shap_po.shappoli.mixin.integration.trinkets;

import com.github.shap_po.shappoli.integration.trinkets.power.ActionOnTrinketUpdatePower;
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;
Expand Down Expand Up @@ -51,12 +51,12 @@ private void tick(CallbackInfo info) {

if (!ItemStack.areEqual(newStack, oldStack)) {
// Call unequip powers on old trinket
PowerHolderComponent.withPower(entity, ActionOnTrinketUpdatePower.class,
PowerHolderComponent.withPower(entity, ActionOnTrinketChangePower.class,
p -> p.doesApply(entity, ref, oldStack),
p -> p.apply(entity, ref, false)
);
// Call equip powers on new trinket
PowerHolderComponent.withPower(entity, ActionOnTrinketUpdatePower.class,
PowerHolderComponent.withPower(entity, ActionOnTrinketChangePower.class,
p -> p.doesApply(entity, ref, newStack),
p -> p.apply(entity, ref, true)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shappoli:action_on_trinket_update",
"type": "shappoli:action_on_trinket_change",
"slot": {
"group": "feet"
},
Expand Down

0 comments on commit b5fe571

Please sign in to comment.