Skip to content

Commit

Permalink
Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Aug 22, 2024
1 parent 9c3d882 commit 192ddae
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 384 deletions.
29 changes: 14 additions & 15 deletions API-DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public class ApoliExamplePower extends PowerType {
```

In Calio/Apoli, a PowerType is an object that defines the main logic and handling of powers for the players it has assigned to it.
To create an instance of any class inside Calio during parsing, it reads the InstanceDefiner, which is defined by the
method ``static InstanceDefiner buildFactory()``. InstanceDefiners are definition of a Constructor for the FactoryHolder. The first instance
To create an instance of any class inside Calio during parsing, it reads the SerializableData, which is defined by the
method ``static SerializableData buildFactory()``. SerializableDatas are definition of a Constructor for the FactoryHolder. The first instance
added is the first arg, the second being the second arg, etc. It also provides the key for the `"type"` field. However, in Calio, there
is a required argument of a ResourceLocation at the beginning of the constructor your InstanceDefiner is creating, which is the `"key"` argument.
is a required argument of a ResourceLocation at the beginning of the constructor your SerializableData is creating, which is the `"key"` argument.
The key argument is the argument assigned to the instance upon instance creation, named after the Namesace and Key of the json.
With adding the constructor, it becomes:

Expand All @@ -77,7 +77,7 @@ public class ApoliExamplePower extends PowerType {
}
```

Adding the method to create the InstanceDefiner:
Adding the method to create the SerializableData:

```java
public class ApoliExamplePower extends PowerType {
Expand All @@ -89,7 +89,7 @@ public class ApoliExamplePower extends PowerType {
// from the base instead of Copy/Pasting its buildFactory method and adding to it.
// By default, the PowerType class does not contain a Namespace, which is why ofNamespace needs to be added.
// The way this is made allows for creating easy extensions of any power without too much struggle.
public static InstanceDefiner buildFactory() {
public static SerializableData buildFactory() {
return PowerType.buildFactory().typedRegistry(ResourceLocation.fromNamespaceAndPath("example", "apoli"));
}
}
Expand All @@ -102,9 +102,9 @@ create your own!

| Method Name | Description |
|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| required(String key, SerializableDataBuilder<T> dataType) | Adds a required field to the InstanceDefiner |
| add(String key, SerializableDataBuilder<T> dataType) | Adds a nullable field to the InstanceDefiner, when the field is not present, it returns null |
| add(String key, SerializableDataBuilder<T> dataType, T defaultValue) | Adds a field to the InstanceDefiner with a default value that is provided when the field is not present |
| required(String key, SerializableDataBuilder<T> dataType) | Adds a required field to the SerializableData |
| add(String key, SerializableDataBuilder<T> dataType) | Adds a nullable field to the SerializableData, when the field is not present, it returns null |
| add(String key, SerializableDataBuilder<T> dataType, T defaultValue) | Adds a field to the SerializableData with a default value that is provided when the field is not present |

```java
public class ApoliExamplePower extends PowerType {
Expand All @@ -114,7 +114,7 @@ public class ApoliExamplePower extends PowerType {
super(key, type, name, description, hidden, condition, loadingPriority);
}
public static InstanceDefiner buildFactory() {
public static SerializableData buildFactory() {
return PowerType.buildFactory().typedRegistry(ResourceLocation.fromNamespaceAndPath("example", "apoli"))
/* | Field name | SerializableDataType instance | Default value | */
.add("welcome_message", SerializableDataTypes.STRING, "Hello World!");
Expand Down Expand Up @@ -157,7 +157,7 @@ public class ApoliExamplePower extends PowerType {
super(key, type, name, description, hidden, condition, loadingPriority);
}
public static InstanceDefiner buildFactory() {
public static SerializableData buildFactory() {
return PowerType.buildFactory().typedRegistry(ResourceLocation.fromNamespaceAndPath("example", "apoli"))
.add("welcome_message", SerializableDataTypes.STRING, "Hello World!");
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public class ApoliExamplePower extends PowerType {
super(key, type, name, description, hidden, condition, loadingPriority);
}
public static InstanceDefiner buildFactory() {
public static SerializableData buildFactory() {
return PowerType.buildFactory().typedRegistry(ResourceLocation.fromNamespaceAndPath("example", "apoli"))
.add("welcome_message", SerializableDataTypes.STRING, "Hello World!");
}
Expand Down Expand Up @@ -235,14 +235,13 @@ Now, we are going to add our `"type"` param, which defines the type associated i
register(new ConditionFactory<>(ResourceLocation.fromNamespaceAndPath("test", "example")));
```

The 2nd arg is an InstanceDefiner, which functions exactly how the PowerType instance definer works for building! The 3rd
and final arg is a `BiPredicate<DeserializedFactoryJson, T>`. A DeserializedFactoryJson is similar to the Apoli SerializableData.Instance
class, which acts as an accessor for getting values defined in the InstanceDefiner.
The 2nd arg is an SerializableData, which functions exactly how the PowerType instance definer works for building! The 3rd
and final arg is a `BiPredicate<SerializableData.Instance, T>`. A SerializableData.Instance acts as an accessor for getting values defined in the SerializableData.

```java
register(new ConditionFactory<>(
ResourceLocation.fromNamespaceAndPath("test", "example"),
InstanceDefiner.instanceDefiner(),
SerializableData.serializableData(),
(data, entity) -> {
return entity.isAlive();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import io.github.dueris.originspaper.power.CreativeFlightPower;
import io.github.dueris.originspaper.power.PowerType;
import io.github.dueris.originspaper.power.provider.OriginSimpleContainer;
import io.github.dueris.originspaper.power.provider.PowerProvider;
import io.github.dueris.originspaper.registry.Registries;
import io.github.dueris.originspaper.storage.PowerHolderComponent;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -71,14 +69,6 @@ public void run() {
}
}
}

for (PowerProvider provider : OriginSimpleContainer.location2PowerMap.values()) {
provider.tick();

for (org.bukkit.entity.Player p : Bukkit.getOnlinePlayers()) {
provider.tick(p);
}
}
}

public void tickAsyncScheduler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.github.dueris.originspaper.origin.OriginLayer;
import io.github.dueris.originspaper.power.PowerType;
import io.github.dueris.originspaper.power.RecipePower;
import io.github.dueris.originspaper.power.provider.origins.WaterBreathe;
import io.github.dueris.originspaper.registry.BuiltinRegistry;
import io.github.dueris.originspaper.registry.Registries;
import io.github.dueris.originspaper.screen.ChoosingPage;
Expand Down Expand Up @@ -88,6 +87,18 @@ public final class OriginsPaper extends JavaPlugin implements Listener {
private static OriginsPaper plugin;
public IRegistry registry;

public OriginsPaper() {
if (!Bootstrap.BOOTSTRAPPED.get()) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.bootstrap(null);
}

Bootstrap.BOOTSTRAPPED.set(false);

plugin = this;
OriginsMixins.init(Bootstrap.MIXIN_LOADER.get());
}

public static OriginScheduler.MainTickerThread getScheduler() {
return scheduler;
}
Expand Down Expand Up @@ -159,18 +170,6 @@ public void finalizePreboot() {
}
}

@Override
public void onLoad() {
if (!Bootstrap.BOOTSTRAPPED.get()) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.bootstrap(null);
}

Bootstrap.BOOTSTRAPPED.set(false);
plugin = this;
OriginsMixins.init(Bootstrap.MIXIN_LOADER.get());
}

@Override
public void onEnable() {
Getter<Boolean> startup = () -> {
Expand Down Expand Up @@ -327,7 +326,6 @@ private void start() {
}
});
BukkitRunnable[] independentTickers = new BukkitRunnable[]{new GuiTicker(), new OriginCommand()};
WaterBreathe.start();

for (BukkitRunnable runnable : independentTickers) {
runnable.runTaskTimerAsynchronously(getPlugin(), 0L, 1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
ResourcePower.getDisplayedBar(player, resourcePower.getTag())
.ifPresentOrElse(
bar -> {
System.out.println(bar.getMappedProgress() + setTo);
bar.change(setTo, "add");
context.getSource()
.sendSystemMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.dueris.calio.parser.SerializableData;
import io.github.dueris.originspaper.OriginsPaper;
import io.github.dueris.originspaper.condition.ConditionFactory;
import io.github.dueris.originspaper.power.ElytraFlightPower;
import io.github.dueris.originspaper.storage.PowerHolderComponent;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,7 +16,8 @@ public class FallFlyingCondition {
OriginsPaper.apoliIdentifier("fall_flying"),
SerializableData.serializableData(),
(data, entity) -> {
return entity instanceof LivingEntity && ((LivingEntity) entity).isFallFlying();
return entity instanceof LivingEntity && (((LivingEntity) entity).isFallFlying() ||
PowerHolderComponent.doesHaveConditionedPower(entity.getBukkitEntity(), ElytraFlightPower.class, (p) -> p.getGlidingPlayers().contains(entity.getBukkitEntity().getUniqueId())));
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.item.ItemEntity;
Expand Down Expand Up @@ -86,6 +87,13 @@ public enum Value {
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}).get()),
IN_WATER_OR_RAIN_CHECK(((ObjectProvider<HLocatorMethodInvoke>) () -> {
try {
return new HLocatorMethodInvoke(Entity.class.getDeclaredMethod("isInWaterOrRain"), PostPreState.PRE, (i) -> i == 0);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}).get());

private final HookLocator locator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.dueris.originspaper.mixin;

import com.dragoncommissions.mixbukkit.api.shellcode.impl.api.CallbackInfo;
import io.github.dueris.originspaper.power.origins.ScareCreepersPower;
import net.minecraft.world.entity.monster.Creeper;

@Mixin(Creeper.class)
public class CreeperMixin {

@Inject(method = "registerGoals", locator = At.Value.RETURN)
public static void origins$scareCreepers(Creeper creeper, CallbackInfo info) {
ScareCreepersPower.modifyGoals(creeper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class ItemEnchantmentsMixin {

public static void mark(ItemEnchantments itemEnchantments, ModifyEnchantmentLevelPower power) {
TO_MODIFY.put(itemEnchantments, power);
System.out.println(itemEnchantments.toString());
}

public static void unmark(ItemEnchantments itemEnchantments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.dragoncommissions.mixbukkit.api.shellcode.impl.api.CallbackInfo;
import io.github.dueris.originspaper.data.types.modifier.ModifierUtil;
import io.github.dueris.originspaper.power.*;
import io.github.dueris.originspaper.power.origins.WaterBreathingPower;
import io.github.dueris.originspaper.storage.PowerHolderComponent;
import net.minecraft.core.Holder;
import net.minecraft.tags.EntityTypeTags;
Expand Down Expand Up @@ -132,4 +133,16 @@ public class LivingEntityMixin {
info.setReturned(true);
}

@Inject(method = "canBreatheUnderwater", locator = At.Value.RETURN)
public static void origins$waterBreathing(@NotNull LivingEntity instance, @NotNull CallbackInfo info) {
info.setReturned(true);
boolean original = instance.getType().is(EntityTypeTags.CAN_BREATHE_UNDER_WATER);
info.setReturnValue(original || PowerHolderComponent.hasPower(instance.getBukkitEntity(), "origins:water_breathing"));
}

@Inject(method = "baseTick", locator = At.Value.RETURN)
public static void origins$waterBreathingTick(LivingEntity instance, CallbackInfo info) {
WaterBreathingPower.tick(instance);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.dueris.originspaper.mixin;

import com.dragoncommissions.mixbukkit.api.shellcode.impl.api.CallbackInfo;
import io.github.dueris.originspaper.power.origins.LikeWaterPower;
import io.github.dueris.originspaper.storage.PowerHolderComponent;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.jetbrains.annotations.NotNull;

@Mixin(Player.class)
public class PlayerMixin {

@Inject(method = "tick", locator = At.Value.HEAD)
public static void apoli$likeWater(Player instance, CallbackInfo info) {
LikeWaterPower.tick((org.bukkit.entity.Player) instance.getBukkitEntity());
}

@Inject(method = "turtleHelmetTick", locator = At.Value.HEAD)
public static void apoli$turtleHelmetTick(@NotNull Player instance, CallbackInfo info) {
ItemStack itemstack = instance.getItemBySlot(EquipmentSlot.HEAD);

if (itemstack.is(Items.TURTLE_HELMET) && PowerHolderComponent.hasPower(instance.getBukkitEntity(), "origins:water_breathing") == instance.isEyeInFluid(FluidTags.WATER)) {
instance.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true), EntityPotionEffectEvent.Cause.TURTLE_HELMET);
}

info.setReturned(true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.UUID;

public class ElytraFlightPower extends PowerType {
public static ArrayList<UUID> glidingPlayers = new ArrayList<>();
private final ArrayList<UUID> glidingPlayers = new ArrayList<>();

public ElytraFlightPower(@NotNull ResourceLocation key, @NotNull ResourceLocation type, Component name, Component description, boolean hidden, ConditionFactory<Entity> condition, int loadingPriority) {
super(key, type, name, description, hidden, condition, loadingPriority);
Expand All @@ -45,7 +45,7 @@ public static SerializableData buildFactory() {
return PowerType.buildFactory().typedRegistry(OriginsPaper.apoliIdentifier("elytra_flight"));
}

public static ArrayList<UUID> getGlidingPlayers() {
public ArrayList<UUID> getGlidingPlayers() {
return glidingPlayers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import io.github.dueris.originspaper.OriginsPaper;
import io.github.dueris.originspaper.condition.ConditionFactory;
import io.github.dueris.originspaper.data.ApoliDataTypes;
import io.github.dueris.originspaper.power.provider.OriginSimpleContainer;
import io.github.dueris.originspaper.power.provider.origins.LikeWater;
import io.github.dueris.originspaper.power.provider.origins.ScareCreepers;
import io.github.dueris.originspaper.power.provider.origins.WaterBreathe;
import io.github.dueris.originspaper.util.LangFile;
import net.kyori.adventure.text.TextComponent;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -118,9 +114,6 @@ public boolean addAll(@NotNull Collection<? extends Class<? extends PowerType>>
}

INSTANCE_TYPES.addAll(holders);
OriginSimpleContainer.registerPower(LikeWater.class);
OriginSimpleContainer.registerPower(ScareCreepers.class);
OriginSimpleContainer.registerPower(WaterBreathe.class);
}

public ResourceLocation key() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.dueris.originspaper.power.origins;

import io.github.dueris.originspaper.OriginsPaper;
import io.github.dueris.originspaper.storage.PowerHolderComponent;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Player;

public class LikeWaterPower {
private static final AttributeModifier modifier = new AttributeModifier(CraftNamespacedKey.fromMinecraft(OriginsPaper.originIdentifier("likewater")), -1, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
private static final String cachedPowerRefrenceString = "origins:like_water";

public static void tick(Player p) {
if (!PowerHolderComponent.hasPower(p, cachedPowerRefrenceString)) {
if (p.getAttribute(Attribute.GENERIC_GRAVITY).getModifiers().contains(modifier)) {
p.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(modifier);
}
return;
}
if (p.isInWaterOrBubbleColumn() && !p.isSneaking()) {
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);
}
}
}
}
Loading

0 comments on commit 192ddae

Please sign in to comment.