Skip to content

Commit

Permalink
Update Upstream (Apoli)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Dec 26, 2024
1 parent b1879df commit 284e50d
Show file tree
Hide file tree
Showing 68 changed files with 619 additions and 345 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ plugins {
}

version = "v1.3.0"
val apoli = "2.12.0-alpha.12+mc.1.21.x"
val calio = "1.14.0-alpha.7+mc.1.21.x"
val apoli = "2.12.0-alpha.14+mc.1.21.1"
val calio = "1.14.0-alpha.8+mc.1.21.x"
val mcMajor = "21"
val mcMinor = "1"
val paper: String = "1.$mcMajor-R0.1-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BiEntityActionTypes {
public static final ActionConfiguration<LeashBiEntityActionType> LEASH = register(ActionConfiguration.simple(OriginsPaper.apoliIdentifier("leash"), LeashBiEntityActionType::new));
public static final ActionConfiguration<MountBiEntityActionType> MOUNT = register(ActionConfiguration.simple(OriginsPaper.apoliIdentifier("mount"), MountBiEntityActionType::new));
public static final ActionConfiguration<RemoveFromEntitySetBiEntityActionType> REMOVE_FROM_ENTITY_SET = register(ActionConfiguration.of(OriginsPaper.apoliIdentifier("remove_from_entity_set"), RemoveFromEntitySetBiEntityActionType.DATA_FACTORY));
public static final ActionConfiguration<TameBiEntityActionType> TAME = ActionConfiguration.simple(OriginsPaper.apoliIdentifier("tame"), TameBiEntityActionType::new);
public static final ActionConfiguration<TameBiEntityActionType> TAME = register(ActionConfiguration.simple(OriginsPaper.apoliIdentifier("tame"), TameBiEntityActionType::new));
public static final ActionConfiguration<SetInLoveBiEntityActionType> SET_IN_LOVE = register(ActionConfiguration.simple(OriginsPaper.apoliIdentifier("set_in_love"), SetInLoveBiEntityActionType::new));

public static void register() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EntityActionTypes {
public static final ActionConfiguration<DelayEntityActionType> DELAY = register(DelayMetaActionType.createConfiguration(EntityAction.DATA_TYPE, DelayEntityActionType::new));
public static final ActionConfiguration<IfElseListEntityActionType> IF_ELSE_LIST = register(IfElseListMetaActionType.createConfiguration(EntityAction.DATA_TYPE, EntityCondition.DATA_TYPE, IfElseListEntityActionType::new));
public static final ActionConfiguration<IfElseEntityActionType> IF_ELSE = register(IfElseMetaActionType.createConfiguration(EntityAction.DATA_TYPE, EntityCondition.DATA_TYPE, IfElseEntityActionType::new));
public static final ActionConfiguration<NothingEntityActionType> NOTHING = register(NothingMetaActionType.createConfiguration(NothingEntityActionType::new));
public static final ActionConfiguration<SideEntityActionType> SIDE = register(SideMetaActionType.createConfiguration(EntityAction.DATA_TYPE, SideEntityActionType::new));

public static final ActionConfiguration<ActionOnEntitySetEntityActionType> ACTION_ON_ENTITY_SET = register(ActionConfiguration.of(OriginsPaper.apoliIdentifier("action_on_entity_set"), ActionOnEntitySetEntityActionType.DATA_FACTORY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AddToEntitySetBiEntityActionType(PowerReference set, Optional<Integer> ti
@Override
protected void execute(Entity actor, Entity target) {

if (set.getPowerTypeFrom(actor) instanceof EntitySetPowerType entitySet && entitySet.add(target, timeLimit)) {
if (set.getNullablePowerType(actor) instanceof EntitySetPowerType entitySet && entitySet.add(target, timeLimit)) {
PowerHolderComponent.syncPower(actor, set);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import io.github.dueris.calio.data.SerializableDataType;
import io.github.dueris.calio.data.SerializableDataTypes;
import io.github.dueris.originspaper.action.ActionConfiguration;
import io.github.dueris.originspaper.action.context.BiEntityActionContext;
import io.github.dueris.originspaper.action.type.BiEntityActionType;
import io.github.dueris.originspaper.action.type.BiEntityActionTypes;
import io.github.dueris.originspaper.data.ApoliDataTypes;
import io.github.dueris.originspaper.data.TypedDataObjectFactory;
import io.github.dueris.originspaper.util.Space;
import net.minecraft.util.Mth;
Expand All @@ -21,54 +23,58 @@ public class AddVelocityBiEntityActionType extends BiEntityActionType {

public static final TypedDataObjectFactory<AddVelocityBiEntityActionType> DATA_FACTORY = TypedDataObjectFactory.simple(
new SerializableData()
.add("reference", SerializableDataType.enumValue(Reference.class), Reference.POSITION)
.add("x", SerializableDataTypes.FLOAT, 0F)
.add("y", SerializableDataTypes.FLOAT, 0F)
.add("z", SerializableDataTypes.FLOAT, 0F)
.addFunctionedDefault("velocity", ApoliDataTypes.VECTOR_3_FLOAT, data -> new Vector3f(data.getFloat("x"), data.getFloat("y"), data.getFloat("z")))
.add("reference", SerializableDataType.enumValue(Reference.class), Reference.POSITION)
.add("set", SerializableDataTypes.BOOLEAN, false),
data -> new AddVelocityBiEntityActionType(
data.get("velocity"),
data.get("reference"),
new Vector3f(
data.get("x"),
data.get("y"),
data.get("z")
),
data.get("set")
),
(actionType, serializableData) -> serializableData.instance()
.set("velocity", actionType.velocity)
.set("reference", actionType.reference)
.set("x", actionType.velocity.x())
.set("y", actionType.velocity.y())
.set("z", actionType.velocity.z())
.set("set", actionType.set)
);

private final Reference reference;
private final Vector3f velocity;
private final Reference reference;

private final boolean set;

public AddVelocityBiEntityActionType(Reference reference, Vector3f velocity, boolean set) {
this.reference = reference;
public AddVelocityBiEntityActionType(Vector3f velocity, Reference reference, boolean set) {
this.velocity = velocity;
this.reference = reference;
this.set = set;
}

@Override
protected void execute(Entity actor, Entity target) {
public void accept(BiEntityActionContext context) {

Entity actor = context.actor();
Entity target = context.target();

if (actor == null || target == null) {
return;
if (actor != null && target != null) {
execute(actor, target);
}

}

@Override
protected void execute(Entity actor, Entity target) {

Vector3f velocityCopy = new Vector3f(velocity);
TriConsumer<Float, Float, Float> method = set
? target::setDeltaMovement
: target::push;

Vec3 referenceVec = reference.apply(actor, target);
Space.transformVectorToBase(referenceVec, velocity, actor.getYRot(), true); // Vector normalized by method
Space.transformVectorToBase(referenceVec, velocityCopy, actor.getYRot(), true); // Vector normalized by method

method.accept(velocity.x(), velocity.y(), velocity.z());
method.accept(velocityCopy.x(), velocityCopy.y(), velocityCopy.z());
target.hurtMarked = true;

}
Expand All @@ -78,32 +84,35 @@ protected void execute(Entity actor, Entity target) {
return BiEntityActionTypes.ADD_VELOCITY;
}

public enum Reference {
public enum Reference implements BiFunction<Entity, Entity, Vec3> {

POSITION((actor, target) -> target.position().subtract(actor.position())),
ROTATION((actor, target) -> {
POSITION {

float pitch = actor.getXRot();
float yaw = actor.getYRot();
@Override
public Vec3 apply(Entity actor, Entity target) {
return target.position().subtract(actor.position());
}

float i = 0.017453292F;
},

float j = -Mth.sin(yaw * i) * Mth.cos(pitch * i);
float k = -Mth.sin(pitch * i);
float l = Mth.cos(yaw * i) * Mth.cos(pitch * i);
ROTATION {

return new Vec3(j, k, l);
@Override
public Vec3 apply(Entity actor, Entity target) {

});
float pitch = actor.getXRot();
float yaw = actor.getYRot();

final BiFunction<Entity, Entity, Vec3> refFunction;
float i = 0.017453292F;

Reference(BiFunction<Entity, Entity, Vec3> refFunction) {
this.refFunction = refFunction;
}
float j = -Mth.sin(yaw * i) * Mth.cos(pitch * i);
float k = -Mth.sin(pitch * i);
float l = Mth.cos(yaw * i) * Mth.cos(pitch * i);

return new Vec3(j, k, l);

}

public Vec3 apply(Entity actor, Entity target) {
return refFunction.apply(actor, target);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RemoveFromEntitySetBiEntityActionType(PowerReference set) {
@Override
protected void execute(Entity actor, Entity target) {

if (set.getPowerTypeFrom(actor) instanceof EntitySetPowerType entitySet && entitySet.remove(target)) {
if (set.getNullablePowerType(actor) instanceof EntitySetPowerType entitySet && entitySet.remove(target)) {
PowerHolderComponent.syncPower(actor, set);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AreaOfEffectBlockActionType extends BlockActionType {
.add("block_action", BlockAction.DATA_TYPE)
.add("block_condition", BlockCondition.DATA_TYPE.optional(), Optional.empty())
.add("shape", SerializableDataType.enumValue(Shape.class), Shape.CUBE)
.add("radius", SerializableDataTypes.POSITIVE_INT, 16),
.add("radius", SerializableDataTypes.NON_NEGATIVE_INT, 16),
data -> new AreaOfEffectBlockActionType(
data.get("block_action"),
data.get("block_condition"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ActionOnEntitySetEntityActionType(PowerReference set, BiEntityAction biEn
@Override
protected void execute(Entity entity) {

if (!(set.getPowerTypeFrom(entity) instanceof EntitySetPowerType entitySet)) {
if (!(set.getNullablePowerType(entity) instanceof EntitySetPowerType entitySet)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@ public class AddVelocityEntityActionType extends EntityActionType {
.add("x", SerializableDataTypes.FLOAT, 0F)
.add("y", SerializableDataTypes.FLOAT, 0F)
.add("z", SerializableDataTypes.FLOAT, 0F)
.addFunctionedDefault("velocity", ApoliDataTypes.VECTOR_3_FLOAT, data -> new Vector3f(data.getFloat("x"), data.getFloat("y"), data.getFloat("z")))
.add("space", ApoliDataTypes.SPACE, Space.WORLD)
.add("set", SerializableDataTypes.BOOLEAN, false),
data -> new AddVelocityEntityActionType(
new Vector3f(
data.get("x"),
data.get("y"),
data.get("z")
),
data.get("velocity"),
data.get("space"),
data.get("set")
),
(actionType, serializableData) -> serializableData.instance()
.set("x", actionType.velocity.x())
.set("y", actionType.velocity.y())
.set("z", actionType.velocity.z())
.set("velocity", actionType.velocity)
.set("space", actionType.space)
.set("set", actionType.set)
);
Expand All @@ -53,12 +48,13 @@ public AddVelocityEntityActionType(Vector3f velocity, Space space, boolean set)
@Override
protected void execute(Entity entity) {

Vector3f velocityCopy = new Vector3f(velocity);
TriConsumer<Float, Float, Float> method = set
? entity::setDeltaMovement
: entity::push;

space.toGlobal(velocity, entity);
method.accept(velocity.x(), velocity.y(), velocity.z());
space.toGlobal(velocityCopy, entity);
method.accept(velocityCopy.x(), velocityCopy.y(), velocityCopy.z());

entity.hurtMarked = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AreaOfEffectEntityActionType extends EntityActionType {
.add("bientity_action", BiEntityAction.DATA_TYPE)
.add("bientity_condition", BiEntityCondition.DATA_TYPE.optional(), Optional.empty())
.add("shape", SerializableDataType.enumValue(Shape.class), Shape.CUBE)
.add("radius", SerializableDataTypes.POSITIVE_DOUBLE, 16.0D)
.add("radius", SerializableDataTypes.NON_NEGATIVE_DOUBLE, 16.0D)
.add("include_actor", SerializableDataTypes.BOOLEAN, false),
data -> new AreaOfEffectEntityActionType(
data.get("bientity_action"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ChangeResourceEntityActionType(PowerReference resource, ResourceOperation
@Override
protected void execute(Entity entity) {

PowerType powerType = resource.getPowerTypeFrom(entity);
PowerType powerType = resource.getNullablePowerType(entity);
boolean modified = switch (operation) {
case ADD -> PowerUtil.changeResourceValue(powerType, change);
case SET -> PowerUtil.setResourceValue(powerType, change);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void execute(Entity entity) {

Optional<InventoryPowerType> inventoryPowerType = power
.filter(ivp -> inventoryType == InventoryType.POWER)
.map(p -> p.getPowerTypeFrom(entity))
.flatMap(p -> p.getOptionalPowerType(entity))
.filter(InventoryPowerType.class::isInstance)
.map(InventoryPowerType.class::cast);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void execute(Entity entity) {
return;
}

SlotAccess stackReference = InventoryUtil.createStackReference(stack);
SlotAccess stackReference = InventoryUtil.createStackReference(stack.copy());
itemAction.ifPresent(action -> action.execute(entity.level(), stackReference));

ItemStack stackToGive = stackReference.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GrantPowerEntityActionType(PowerReference power, ResourceLocation source)

@Override
protected void execute(Entity entity) {
PowerHolderComponent.grantPower(entity, power.getStrictReference(), source, true);
PowerHolderComponent.grantPower(entity, power.getPower(), source, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void execute(Entity entity) {

Optional<InventoryPowerType> inventoryPowerType = power
.filter(ipt -> inventoryType == InventoryType.POWER)
.map(p -> p.getPowerTypeFrom(entity))
.flatMap(p -> p.getOptionalPowerType(entity))
.filter(InventoryPowerType.class::isInstance)
.map(InventoryPowerType.class::cast);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ModifyResourceEntityActionType(PowerReference resource, Modifier modifier
@Override
protected void execute(Entity entity) {

if (PowerUtil.modifyResourceValue(resource.getPowerTypeFrom(entity), List.of(modifier))) {
if (PowerUtil.modifyResourceValue(resource.getNullablePowerType(entity), List.of(modifier))) {
PowerHolderComponent.syncPower(entity, resource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void execute(Entity entity) {

Optional<InventoryPowerType> inventoryPowerType = power
.filter(p -> inventoryType == InventoryType.POWER)
.map(p -> p.getPowerTypeFrom(entity))
.flatMap(p -> p.getOptionalPowerType(entity))
.filter(InventoryPowerType.class::isInstance)
.map(InventoryPowerType.class::cast);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public RevokePowerEntityActionType(PowerReference power, ResourceLocation source

@Override
protected void execute(Entity entity) {
PowerHolderComponent.revokePower(entity, power.getStrictReference(), source, true);
PowerHolderComponent.revokePower(entity, power.getPower(), source, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SetResourceEntityActionType(PowerReference resource, int value) {
@Override
protected void execute(Entity entity) {

if (PowerUtil.setResourceValue(resource.getPowerTypeFrom(entity), value)) {
if (PowerUtil.setResourceValue(resource.getNullablePowerType(entity), value)) {
PowerHolderComponent.syncPower(entity, resource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,27 @@ public class SpawnParticlesEntityActionType extends EntityActionType {
new SerializableData()
.add("bientity_condition", BiEntityCondition.DATA_TYPE.optional(), Optional.empty())
.add("particle", SerializableDataTypes.PARTICLE_EFFECT_OR_TYPE)
.add("offset_x", SerializableDataTypes.DOUBLE, 0.5D)
.add("offset_x", SerializableDataTypes.DOUBLE, 0.0D)
.add("offset_y", SerializableDataTypes.DOUBLE, 0.5D)
.add("offset_z", SerializableDataTypes.DOUBLE, 0.5D)
.add("offset_z", SerializableDataTypes.DOUBLE, 0.0D)
.addFunctionedDefault("offset", SerializableDataTypes.VECTOR, data -> new Vec3(data.getDouble("offset_x"), data.getDouble("offset_y"), data.getDouble("offset_z")))
.add("spread", SerializableDataTypes.VECTOR, new Vec3(0.5D, 0.5D, 0.5D))
.add("force", SerializableDataTypes.BOOLEAN, false)
.add("speed", SerializableDataTypes.FLOAT, 0.0F)
.add("count", SerializableDataTypes.INT, 1),
data -> new SpawnParticlesEntityActionType(
data.get("bientity_condition"),
data.get("particle"),
new Vec3(
data.get("offset_x"),
data.get("offset_y"),
data.get("offset_z")
),
data.get("offset"),
data.get("spread"),
data.get("force"),
data.get("speed"),
data.get("count")
),
(actionType, serializableData) -> serializableData.instance()
.set("bientity_condition", actionType.biEntityCondition)
.set("particle", actionType.particle)
.set("offset_x", actionType.offset.x)
.set("offset_y", actionType.offset.y)
.set("offset_z", actionType.offset.z)
.set("particle", actionType.particle) // TODO - eggo response
.set("offset", actionType.offset)
.set("spread", actionType.spread)
.set("force", actionType.force)
.set("speed", actionType.speed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ToggleEntityActionType(PowerReference power) {
@Override
protected void execute(Entity entity) {

if (power.getPowerTypeFrom(entity) instanceof TogglePowerType togglePowerType) {
if (power.getNullablePowerType(entity) instanceof TogglePowerType togglePowerType) {
togglePowerType.onUse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TriggerCooldownEntityActionType(PowerReference power) {
@Override
protected void execute(Entity entity) {

if (power.getPowerTypeFrom(entity) instanceof CooldownPowerType cooldownPowerType) {
if (power.getNullablePowerType(entity) instanceof CooldownPowerType cooldownPowerType) {
cooldownPowerType.use();
}

Expand Down
Loading

0 comments on commit 284e50d

Please sign in to comment.