Skip to content

Commit

Permalink
port origins-fabric powers to new PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Nov 11, 2024
1 parent 1b63ebb commit 9ae4f46
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.github.dueris.originspaper.power.Power;
import io.github.dueris.originspaper.power.PowerManager;
import io.github.dueris.originspaper.power.type.PowerTypes;
import io.github.dueris.originspaper.power.type.origins.OriginsPowerTypes;
import io.github.dueris.originspaper.registry.ApoliClassData;
import io.github.dueris.originspaper.registry.ModBlocks;
import io.github.dueris.originspaper.registry.ModItems;
Expand Down Expand Up @@ -111,7 +112,7 @@ public static void initialize(@NotNull BootstrapContext context) {
BiEntityActionTypes.register();

PowerTypes.register();
// OriginsPowerTypes.register();
OriginsPowerTypes.register();
Origin.init();

ApoliDataHandlers.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.dueris.originspaper.power.Power;
import io.github.dueris.originspaper.power.type.ModifyPlayerSpawnPowerType;
import io.github.dueris.originspaper.power.type.PowerType;
import io.github.dueris.originspaper.power.type.origins.OriginsCallbackPowerType;
import io.github.dueris.originspaper.util.ProvidableComponentKey;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -28,7 +29,7 @@ static void onChosen(Player player, boolean hadOriginBefore) {
.ifPresent(ModifyPlayerSpawnPowerType::teleportToModifiedSpawn);
}

// PowerHolderComponent.withPowerTypes(player, OriginsCallbackPowerType.class, p -> true, p -> p.onChosen(hadOriginBefore)); // TODO
PowerHolderComponent.withPowerTypes(player, OriginsCallbackPowerType.class, p -> true, p -> p.onChosen(hadOriginBefore));

}

Expand All @@ -42,9 +43,9 @@ static void partialOnChosen(Player player, boolean hadOriginBefore, @NotNull Ori

if (powerType instanceof ModifyPlayerSpawnPowerType mps && !hadOriginBefore) {
mps.teleportToModifiedSpawn();
} /* else if (powerType instanceof OriginsCallbackPowerType ocp) {
} else if (powerType instanceof OriginsCallbackPowerType ocp) {
ocp.onChosen(hadOriginBefore);
} */ // TODO
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import io.github.dueris.originspaper.component.PowerHolderComponent;
import io.github.dueris.originspaper.power.type.origins.ConduitPowerOnLandPowerType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,10 +12,10 @@
@Mixin(ConduitBlockEntity.class)
public abstract class ConduitBlockEntityMixin {

/* @ModifyExpressionValue(method = "applyEffects(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isInWaterOrRain()Z"))
@ModifyExpressionValue(method = "applyEffects(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isInWaterOrRain()Z"))
private static boolean origins$applyConduitPower(boolean original, @Local Player player) {
return original
|| PowerHolderComponent.hasPowerType(player, ConduitPowerOnLandPowerType.class);
} */ // TODO
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.dueris.originspaper.component.item.ItemPowersComponent;
import io.github.dueris.originspaper.data.ApoliDamageTypes;
import io.github.dueris.originspaper.power.type.*;
import io.github.dueris.originspaper.power.type.origins.WaterBreathingPowerType;
import io.github.dueris.originspaper.util.InventoryUtil;
import io.github.dueris.originspaper.util.modifier.ModifierUtil;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -520,7 +521,7 @@ private float modifySlipperiness(float original) {

}

/* @ModifyReturnValue(method = "canBreatheUnderwater", at = @At("RETURN"))
@ModifyReturnValue(method = "canBreatheUnderwater", at = @At("RETURN"))
private boolean origins$breatheUnderwater(boolean original) {
return original
|| PowerHolderComponent.hasPowerType(this, WaterBreathingPowerType.class);
Expand All @@ -529,5 +530,5 @@ private float modifySlipperiness(float original) {
@Inject(method = "baseTick", at = @At("TAIL"))
private void origins$waterBreathingTick(CallbackInfo ci) {
WaterBreathingPowerType.tick((LivingEntity) (Object) this);
} */ // TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import io.github.dueris.originspaper.power.type.ActionOnItemPickupPowerType;
import io.github.dueris.originspaper.power.type.PreventItemPickupPowerType;
import io.github.dueris.originspaper.power.type.origins.ScareCreepersPowerType;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected MobMixin(EntityType<? extends LivingEntity> entityType, Level world) {
private void origins$modifyGoals(EntityType<?> entityType, Level world, CallbackInfo ci) {

if ((Mob) (Object) this instanceof Creeper thisAsCreeper) {
// ScareCreepersPowerType.modifyGoals(thisAsCreeper); // TODO
ScareCreepersPowerType.modifyGoals(thisAsCreeper);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.github.dueris.originspaper.access.PlayerTiedAbilities;
import io.github.dueris.originspaper.component.PowerHolderComponent;
import io.github.dueris.originspaper.power.type.*;
import io.github.dueris.originspaper.power.type.origins.LikeWaterPowerType;
import io.github.dueris.originspaper.power.type.origins.WaterBreathingPowerType;
import io.github.dueris.originspaper.util.InventoryUtil;
import io.github.dueris.originspaper.util.PriorityPhase;
import io.github.dueris.originspaper.util.Util;
Expand Down Expand Up @@ -373,7 +375,7 @@ private float modifyExhaustion(float exhaustionIn) {
return original.call(instance) || (PowerHolderComponent.hasPowerType(this, PhasingPowerType.class) && ((PhasingEntity) this).apoli$isPhasing());
}

/* @Inject(method = "tick", at = @At("TAIL"))
@Inject(method = "tick", at = @At("TAIL"))
public void origins$likeWater(CallbackInfo ci) {
Player thisAsPlayer = (Player) (Object) this;
LikeWaterPowerType.tick(thisAsPlayer);
Expand All @@ -382,5 +384,5 @@ private float modifyExhaustion(float exhaustionIn) {
@ModifyExpressionValue(method = "turtleHelmetTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"))
private boolean origins$submergedProxy(boolean original) {
return PowerHolderComponent.hasPowerType(this, WaterBreathingPowerType.class) != original;
} */ // TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class ActionOnCallbackPowerType extends PowerType {
.set("entity_action_added", powerType.entityActionAdded)
);

private final Optional<EntityAction> entityActionRespawned;
private final Optional<EntityAction> entityActionRemoved;
private final Optional<EntityAction> entityActionGained;
private final Optional<EntityAction> entityActionLost;
private final Optional<EntityAction> entityActionAdded;
protected final Optional<EntityAction> entityActionRespawned;
protected final Optional<EntityAction> entityActionRemoved;
protected final Optional<EntityAction> entityActionGained;
protected final Optional<EntityAction> entityActionLost;
protected final Optional<EntityAction> entityActionAdded;

public ActionOnCallbackPowerType(Optional<EntityAction> entityActionRespawned, Optional<EntityAction> entityActionRemoved, Optional<EntityAction> entityActionGained, Optional<EntityAction> entityActionLost, Optional<EntityAction> entityActionAdded, Optional<EntityCondition> condition) {
super(condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ public boolean shouldRenderElytra() {
return renderElytra;
}

// TODO: Manually do vanilla elytra flight stuff using the API -eggohito
public static boolean integrateCustomCallback(LivingEntity entity, boolean tickElytra) {
return PowerHolderComponent.hasPowerType(entity, ElytraFlightPowerType.class);
}

@EventHandler
public void executeFlight(@NotNull PlayerToggleFlightEvent e) {
CraftPlayer p = (CraftPlayer) e.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.dueris.originspaper.power.type.origins;

import io.github.dueris.originspaper.power.PowerConfiguration;
import io.github.dueris.originspaper.power.type.PowerType;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class ConduitPowerOnLandPowerType extends PowerType {

public ConduitPowerOnLandPowerType() {
super(Optional.empty());
}

@Override
public @NotNull PowerConfiguration<?> getConfig() {
return OriginsPowerTypes.CONDUIT_POWER_ON_LAND;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.github.dueris.originspaper.power.type.origins;

import io.github.dueris.originspaper.OriginsPaper;
import io.github.dueris.originspaper.component.PowerHolderComponent;
import io.github.dueris.originspaper.power.PowerConfiguration;
import io.github.dueris.originspaper.power.type.PowerType;
import net.minecraft.world.entity.player.Player;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class LikeWaterPowerType extends PowerType {
private static final AttributeModifier modifier = new AttributeModifier(CraftNamespacedKey.fromMinecraft(OriginsPaper.identifier("likewater")), -1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);

public LikeWaterPowerType() {
super(Optional.empty());
}

public static void tick(@NotNull Player player) {
CraftPlayer p = (CraftPlayer) player.getBukkitEntity();

if (!PowerHolderComponent.hasPowerType(player, LikeWaterPowerType.class)) {
if (p.getAttribute(Attribute.GENERIC_GRAVITY).getModifiers().contains(modifier)) {
p.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(modifier);
}
return;
}
if (p.isInWaterOrBubbleColumn() && !p.isSneaking() && !p.isSwimming()) {
if (!p.getAttribute(Attribute.GENERIC_GRAVITY).getModifiers().contains(modifier)) {
p.getAttribute(Attribute.GENERIC_GRAVITY).addTransientModifier(modifier);
}
} else {
if (p.getAttribute(Attribute.GENERIC_GRAVITY).getModifiers().contains(modifier)) {
p.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(modifier);
}
}
}

@Override
public @NotNull PowerConfiguration<?> getConfig() {
return OriginsPowerTypes.LIKE_WATER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.github.dueris.originspaper.power.type.origins;

import io.github.dueris.calio.data.SerializableData;
import io.github.dueris.originspaper.action.EntityAction;
import io.github.dueris.originspaper.condition.EntityCondition;
import io.github.dueris.originspaper.data.TypedDataObjectFactory;
import io.github.dueris.originspaper.power.PowerConfiguration;
import io.github.dueris.originspaper.power.type.ActionOnCallbackPowerType;
import io.github.dueris.originspaper.power.type.PowerType;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class OriginsCallbackPowerType extends ActionOnCallbackPowerType {

public static final TypedDataObjectFactory<OriginsCallbackPowerType> DATA_FACTORY = PowerType.createConditionedDataFactory(
new SerializableData()
.add("entity_action_respawned", EntityAction.DATA_TYPE.optional(), Optional.empty())
.add("entity_action_removed", EntityAction.DATA_TYPE.optional(), Optional.empty())
.add("entity_action_gained", EntityAction.DATA_TYPE.optional(), Optional.empty())
.add("entity_action_lost", EntityAction.DATA_TYPE.optional(), Optional.empty())
.add("entity_action_added", EntityAction.DATA_TYPE.optional(), Optional.empty()),
(data, condition) -> new OriginsCallbackPowerType(
data.get("entity_action_respawned"),
data.get("entity_action_removed"),
data.get("entity_action_gained"),
data.get("entity_action_lost"),
data.get("entity_action_added"),
data.get("entity_action_chosen"),
data.getBoolean("execute_chosen_when_orb"),
condition
),
(powerType, serializableData) -> serializableData.instance()
.set("entity_action_respawned", powerType.entityActionRespawned)
.set("entity_action_removed", powerType.entityActionRemoved)
.set("entity_action_gained", powerType.entityActionGained)
.set("entity_action_lost", powerType.entityActionLost)
.set("entity_action_added", powerType.entityActionAdded)
.set("entity_action_chosen", powerType.entityActionChosen)
.set("execute_chosen_when_orb", powerType.executeChosenWhenOrb)
);

private final Optional<EntityAction> entityActionChosen;
private final boolean executeChosenWhenOrb;

public OriginsCallbackPowerType(Optional<EntityAction> entityActionRespawned, Optional<EntityAction> entityActionRemoved, Optional<EntityAction> entityActionGained, Optional<EntityAction> entityActionLost, Optional<EntityAction> entityActionAdded, Optional<EntityAction> entityActionChosen, boolean executeChosenWhenOrb, Optional<EntityCondition> condition) {
super(entityActionRespawned, entityActionRemoved, entityActionGained, entityActionLost, entityActionAdded, condition);
this.entityActionChosen = entityActionChosen;
this.executeChosenWhenOrb = executeChosenWhenOrb;
}

public void onChosen(boolean isOrbOfOrigins) {

if (this.isActive() && entityActionChosen.isPresent() && (!isOrbOfOrigins || executeChosenWhenOrb)) {
entityActionChosen.get().execute(getHolder());
}

}

@Override
public @NotNull PowerConfiguration<?> getConfig() {
return OriginsPowerTypes.ACTION_ON_CALLBACK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.dueris.originspaper.power.type.origins;

import io.github.dueris.originspaper.OriginsPaper;
import io.github.dueris.originspaper.power.PowerConfiguration;
import io.github.dueris.originspaper.power.type.PowerType;
import io.github.dueris.originspaper.registry.ApoliRegistries;
import net.minecraft.core.Registry;

public class OriginsPowerTypes {
public static final PowerConfiguration<ConduitPowerOnLandPowerType> CONDUIT_POWER_ON_LAND = register(PowerConfiguration.simple(OriginsPaper.identifier("conduit_power_on_land"), ConduitPowerOnLandPowerType::new));
public static final PowerConfiguration<LikeWaterPowerType> LIKE_WATER = register(PowerConfiguration.simple(OriginsPaper.identifier("like_water"), LikeWaterPowerType::new));
public static final PowerConfiguration<OriginsCallbackPowerType> ACTION_ON_CALLBACK = register(PowerConfiguration.dataFactory(OriginsPaper.identifier("action_on_callback"), OriginsCallbackPowerType.DATA_FACTORY));
public static final PowerConfiguration<ScareCreepersPowerType> SCARE_CREEPERS = register(PowerConfiguration.simple(OriginsPaper.identifier("scare_creepers"), ScareCreepersPowerType::new));
public static final PowerConfiguration<WaterBreathingPowerType> WATER_BREATHING = register(PowerConfiguration.simple(OriginsPaper.identifier("water_breathing"), WaterBreathingPowerType::new));

public static void register() {
}

public static <T extends PowerType> PowerConfiguration<T> register(PowerConfiguration<T> configuration) {

PowerConfiguration<PowerType> casted = (PowerConfiguration<PowerType>) configuration;
Registry.register(ApoliRegistries.POWER_TYPE, casted.id(), casted);

return configuration;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.github.dueris.originspaper.power.type.origins;

import io.github.dueris.originspaper.component.PowerHolderComponent;
import io.github.dueris.originspaper.mixin.MobEntityAccessor;
import io.github.dueris.originspaper.mixin.NearestAttackableTargetGoalAccessor;
import io.github.dueris.originspaper.mixin.TargetingConditionsAccessor;
import io.github.dueris.originspaper.power.PowerConfiguration;
import io.github.dueris.originspaper.power.type.PowerType;
import io.github.dueris.originspaper.util.Util;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

public class ScareCreepersPowerType extends PowerType {

public ScareCreepersPowerType() {
super(Optional.empty());
}

public static void modifyGoals(PathfinderMob pathAwareEntity) {

GoalSelector targetSelector = ((MobEntityAccessor) pathAwareEntity).getTargetSelector();
GoalSelector goalSelector = ((MobEntityAccessor) pathAwareEntity).getGoalSelector();

Iterator<WrappedGoal> oldTargetPrioGoals = targetSelector.getAvailableGoals().iterator();
Set<WrappedGoal> newTargetPrioGoals = new HashSet<>();

while (oldTargetPrioGoals.hasNext()) {

WrappedGoal oldTargetPrioGoal = oldTargetPrioGoals.next();
if (!(oldTargetPrioGoal.getGoal() instanceof NearestAttackableTargetGoalAccessor oldTargetGoal)) {
continue;
}

Predicate<LivingEntity> targetCondition = Util.combineAnd(((TargetingConditionsAccessor) oldTargetGoal.getTargetConditions()).getSelector(), e -> !PowerHolderComponent.hasPowerType(e, ScareCreepersPowerType.class));
WrappedGoal newTargetPrioGoal = new WrappedGoal(oldTargetPrioGoal.getPriority(), new NearestAttackableTargetGoal<>(pathAwareEntity, oldTargetGoal.getTargetType(), oldTargetGoal.getRandomInterval(), oldTargetGoal.getMustSee(), oldTargetGoal.getMustReach(), targetCondition));

newTargetPrioGoals.add(newTargetPrioGoal);
oldTargetPrioGoals.remove();

}

goalSelector.addGoal(3, new AvoidEntityGoal<>(pathAwareEntity, LivingEntity.class, e -> PowerHolderComponent.hasPowerType(e, ScareCreepersPowerType.class), 6.0F, 1.0D, 1.2D, EntitySelector.NO_CREATIVE_OR_SPECTATOR::test));
newTargetPrioGoals.forEach(pg -> targetSelector.addGoal(pg.getPriority(), pg.getGoal()));

}

@Override
public @NotNull PowerConfiguration<?> getConfig() {
return OriginsPowerTypes.SCARE_CREEPERS;
}
}
Loading

0 comments on commit 9ae4f46

Please sign in to comment.