-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port origins-fabric powers to new PR
- Loading branch information
Showing
14 changed files
with
319 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...in/java/io/github/dueris/originspaper/power/type/origins/ConduitPowerOnLandPowerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ns/src/main/java/io/github/dueris/originspaper/power/type/origins/LikeWaterPowerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../main/java/io/github/dueris/originspaper/power/type/origins/OriginsCallbackPowerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ins/src/main/java/io/github/dueris/originspaper/power/type/origins/OriginsPowerTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...rc/main/java/io/github/dueris/originspaper/power/type/origins/ScareCreepersPowerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.