Skip to content

Commit

Permalink
Added compat for Apotheosis
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondBlaze committed Apr 16, 2022
1 parent ea23d78 commit e5e5a49
Show file tree
Hide file tree
Showing 34 changed files with 460 additions and 261 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ repositories {
dependencies {
minecraft "net.minecraftforge:forge:${project.forge_version}"

//Dependencies
implementation fg.deobf(group: 'top.theillusivec4.caelus', name: 'caelus-forge', version: "${project.caelus_version}")
implementation fg.deobf("curse.maven:origins-474438:${project.origins_version}")
//Compat Dependencies
implementation fg.deobf("curse.maven:apotheosis-313970:${project.apotheosis_version}")
implementation fileTree(dir: 'libs', include: '*.jar')

annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ org.gradle.daemon=false
mappings_version=2022.02.13-1.18.1

# Mod Properties
mod_version=1.0.1
mod_version=1.0.2
mod_id=origins_classes
mod_author=LimonBlaze
maven_group=limonblaze.originsclasses
archives_base_name=origins-classes-forge

# Dependencies
caelus_version=1.18.1-3.0.0.2
origins_version=3747132
origins_version=3747132

# Compat Dependencies
apotheosis_version=3647864
Binary file added libs/Placebo-1.18.1-6.1.2-dev.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class OriginsClassesCommon {

public static void setup(final FMLCommonSetupEvent event) {
event.enqueueWork(OriginsClassesCommon::initNetwork);
MultiMinePower.bootstrap();
}

private static void initNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.power.IValueModifyingPowerConfiguration;
import io.github.edwinmindcraft.calio.api.network.CalioCodecHelper;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;

Expand All @@ -16,7 +17,7 @@
public record ModifyBreedingConfiguration(ListConfiguration<AttributeModifier> modifiers,
@Nullable ConfiguredBiEntityCondition<?, ?> parentsCondition,
@Nullable ConfiguredBiEntityAction<?, ?> parentsAction,
@Nullable ConfiguredEntityAction<?, ?> playerAction) implements IDynamicFeatureConfiguration {
@Nullable ConfiguredEntityAction<?, ?> playerAction) implements IValueModifyingPowerConfiguration {

public static final Codec<ModifyBreedingConfiguration> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ListConfiguration.modifierCodec("modifier")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import io.github.edwinmindcraft.apoli.api.IDynamicFeatureConfiguration;
import io.github.edwinmindcraft.apoli.api.configuration.ListConfiguration;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.power.IValueModifyingPowerConfiguration;
import io.github.edwinmindcraft.calio.api.network.CalioCodecHelper;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;

import javax.annotation.Nullable;
import java.util.Optional;

public record ModifySpeedOnItemUseConfiguration(ListConfiguration<AttributeModifier> modifiers,
@Nullable ConfiguredItemCondition<?, ?> itemCondition) implements IDynamicFeatureConfiguration {
@Nullable ConfiguredItemCondition<?, ?> itemCondition) implements IValueModifyingPowerConfiguration {

public static final Codec<ModifySpeedOnItemUseConfiguration> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ListConfiguration.modifierCodec("modifier")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
package limonblaze.originsclasses.common.apoli.power;

import io.github.edwinmindcraft.apoli.api.component.IPowerContainer;
import io.github.edwinmindcraft.apoli.api.power.IValueModifyingPower;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
import io.github.edwinmindcraft.apoli.api.power.factory.PowerFactory;
import io.github.edwinmindcraft.apoli.api.power.factory.power.ValueModifyingPowerFactory;
import limonblaze.originsclasses.common.apoli.configuration.ModifyBreedingConfiguration;
import limonblaze.originsclasses.common.registry.OriginsClassesPowers;
import limonblaze.originsclasses.util.PowerUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import limonblaze.originsclasses.util.MathUtils;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;

import javax.annotation.Nonnull;
import java.util.List;

public class ModifyBreedingPower extends PowerFactory<ModifyBreedingConfiguration> implements IValueModifyingPower<ModifyBreedingConfiguration> {
public class ModifyBreedingPower extends ValueModifyingPowerFactory<ModifyBreedingConfiguration> {

public ModifyBreedingPower() {
super(ModifyBreedingConfiguration.CODEC);
}

public static int getBreedAmount(Player player, Animal actor, Animal target) {
return PowerUtil.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BREEDING.get(), 1.0D,
return MathUtils.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BREEDING.get(), 1.0D,
cp -> cp.isActive(player) && ConfiguredBiEntityCondition.check(cp.getConfiguration().parentsCondition(), actor, target),
cp -> {
ConfiguredBiEntityAction.execute(cp.getConfiguration().parentsAction(), actor, target);
ConfiguredEntityAction.execute(cp.getConfiguration().playerAction(), player);
}), player.getRandom());
}

@Override
public @Nonnull List<AttributeModifier> getModifiers(ConfiguredPower<ModifyBreedingConfiguration, ?> configuredPower, Entity entity) {
return configuredPower.getConfiguration().modifiers().getContent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
import io.github.edwinmindcraft.apoli.api.power.factory.PowerFactory;
import io.github.edwinmindcraft.apoli.api.power.factory.power.ValueModifyingPowerFactory;
import limonblaze.originsclasses.common.apoli.configuration.ModifySpeedOnItemUseConfiguration;
import limonblaze.originsclasses.common.registry.OriginsClassesPowers;
import net.minecraft.util.Mth;
Expand All @@ -16,7 +17,7 @@
import javax.annotation.Nonnull;
import java.util.List;

public class ModifySpeedOnItemUsePower extends PowerFactory<ModifySpeedOnItemUseConfiguration> implements IValueModifyingPower<ModifySpeedOnItemUseConfiguration> {
public class ModifySpeedOnItemUsePower extends ValueModifyingPowerFactory<ModifySpeedOnItemUseConfiguration> {

public ModifySpeedOnItemUsePower() {
super(ModifySpeedOnItemUseConfiguration.CODEC);
Expand All @@ -28,9 +29,4 @@ public static float modifySlowDown(Player player, float slowdownMultiplier) {
cp -> ConfiguredItemCondition.check(cp.getConfiguration().itemCondition(), player.level, stack)), 0.0F, 1.0F);
}

@Override
public @Nonnull List<AttributeModifier> getModifiers(ConfiguredPower<ModifySpeedOnItemUseConfiguration, ?> configuredPower, Entity entity) {
return configuredPower.getConfiguration().modifiers().getContent();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package limonblaze.originsclasses.common.apoli.power;

import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Pair;
import io.github.edwinmindcraft.apoli.api.component.IPowerContainer;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBlockCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
Expand All @@ -9,27 +11,33 @@
import limonblaze.originsclasses.client.OriginsClassesClient;
import limonblaze.originsclasses.common.apoli.configuration.MultiMineConfiguration;
import limonblaze.originsclasses.common.duck.SneakingStateSave;
import limonblaze.originsclasses.util.MultiMiner;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class MultiMinePower extends PowerFactory<MultiMineConfiguration> {
private static final List<MultiMinePower> POWERS = new ArrayList<>();
public final Miner miner;
private static ImmutableList<MultiMinePower> FACTORIES;
public final MultiMiner miner;

public MultiMinePower(Miner miner) {
public MultiMinePower(MultiMiner miner) {
super(MultiMineConfiguration.CODEC);
this.miner = miner;
}

public static void bootstrap() {
ApoliRegistries.POWER_FACTORY.get().getValues().forEach(pf -> {
if(pf instanceof MultiMinePower mmp) POWERS.add(mmp);
});
public static List<MultiMinePower> factories() {
if(FACTORIES == null) {
ImmutableList.Builder<MultiMinePower> factories = ImmutableList.builder();
ApoliRegistries.POWER_FACTORY.get().getValues().forEach(pf -> {
if(pf instanceof MultiMinePower mmp) factories.add(mmp);
});
FACTORIES = factories.build();
}
return FACTORIES;
}

public static boolean shouldApply(ConfiguredPower<?, ?> cp, Player player, BlockPos pos, BlockState state) {
Expand All @@ -39,18 +47,18 @@ public static boolean shouldApply(ConfiguredPower<?, ?> cp, Player player, Block
ConfiguredItemCondition.check(mmc.itemCondition(), player.level, player.getMainHandItem());
}

public static MultiMineData getMultiMineData(Player player, BlockPos pos, BlockState state) {
List<ConfiguredPower<MultiMineConfiguration, MultiMinePower>> cmmps = POWERS.stream()
public static Optional<Pair<List<BlockPos>, Float>> getResult(Player player, BlockPos pos, BlockState state) {
List<ConfiguredPower<MultiMineConfiguration, MultiMinePower>> cmmps = factories().stream()
.flatMap(pf -> IPowerContainer.getPowers(player, pf).stream())
.filter(cp -> shouldApply(cp, player, pos, state))
.toList();
for(ConfiguredPower<MultiMineConfiguration, MultiMinePower> cmmp : cmmps) {
List<BlockPos> affectBlock = cmmp.getFactory().miner.getAffectedBlocks(player, state, pos);
if(affectBlock.size() > 0) {
return new MultiMineData(affectBlock, cmmp.getConfiguration().speedMultiplier());
List<BlockPos> affectBlocks = cmmp.getFactory().miner.getAffectedBlocks(player, state, pos);
if(affectBlocks.size() > 0) {
return Optional.of(new Pair<>(affectBlocks, cmmp.getConfiguration().speedMultiplier()));
}
}
return new MultiMineData(new ArrayList<>(), 1F);
return Optional.empty();
}

public static float modifyBreakingSpeed(float speed, Player player, BlockPos pos, BlockState state) {
Expand All @@ -61,26 +69,7 @@ public static float modifyBreakingSpeed(float speed, Player player, BlockPos pos
} else {
processMultimine = OriginsClassesClient.MULTI_MINING;
}
if(processMultimine) {
MultiMineData data = getMultiMineData(player, pos, state);
if(data.affectedBlocks.size() > 0) {
return data.getModifiedSpeed(speed);
}
}
return speed;
}

public record MultiMineData(List<BlockPos> affectedBlocks, float speedMultiplier) {

public float getModifiedSpeed(float speed) {
return speed * this.speedMultiplier / affectedBlocks.size();
}

}

@FunctionalInterface
public interface Miner {
List<BlockPos> getAffectedBlocks(Player player, BlockState state, BlockPos pos);
return processMultimine ? speed * getResult(player, pos, state).map(Pair::getSecond).orElse(1.0F) : speed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import limonblaze.originsclasses.common.registry.OriginsClassesAttributes;
import limonblaze.originsclasses.common.registry.OriginsClassesPowers;
import limonblaze.originsclasses.mixin.accessor.LivingEntityAccessor;
import limonblaze.originsclasses.util.PowerUtil;
import limonblaze.originsclasses.util.MathUtils;
import limonblaze.originsclasses.util.NbtType;
import limonblaze.originsclasses.util.NbtUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -56,6 +56,7 @@ public class PowerEventHandler {
public static final String FOOD_BONUS_TRANSLATION_KEY = "tooltip.origins_classes.food_bonus";
public static final String POTION_BONUS_TRANSLATION_KEY = "tooltip.origins_classes.potion_bonus";

//ActionOnTame
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onAnimalTame(AnimalTameEvent event) {
ActionOnTamePower.apply(event.getTamer(), event.getAnimal());
Expand All @@ -72,6 +73,7 @@ public static void onBabyEntitySpawn(BabyEntitySpawnEvent event) {
}
}

//TamedPotionDiffusal
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onPotionGained(PotionEvent.PotionAddedEvent event) {
MobEffectInstance effect = event.getPotionEffect();
Expand All @@ -84,23 +86,23 @@ public static void onPotionGained(PotionEvent.PotionAddedEvent event) {
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
//ModifyEnchantingLevel
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onEnchantmentLevel(EnchantmentLevelSetEvent event) {
ItemStack stack = event.getItem();
if(stack.hasTag()) {
CompoundTag nbt = stack.getOrCreateTag();
if(nbt.hasUUID(PowerUtil.ORIGINS_CLASSES_ENCHANTER)) {
Player player = event.getWorld().getPlayerByUUID(nbt.getUUID(PowerUtil.ORIGINS_CLASSES_ENCHANTER));
if(player != null) {
event.setLevel(Mth.floor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_ENCHANTING_LEVEL.get(), event.getLevel(), cp -> cp.isActive(player))));
}
NbtUtils.getOriginsClassesData(event.getItem(), NbtUtils.ENCHANTER, NbtType.UUID).ifPresent(uuid -> {
Player player = event.getWorld().getPlayerByUUID(uuid);
if(player != null) {
event.setLevel(Mth.floor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_ENCHANTING_LEVEL.get(), event.getLevel(),
cp -> cp.isActive(player)
)));
}
}
});
}

//ModifyBoneMeal
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onBoneMeal(BonemealEvent event) {
int count = PowerUtil.naturalRandFloor(IPowerContainer.modify(event.getPlayer(), OriginsClassesPowers.MODIFY_BONE_MEAL.get(), 1.0D), event.getPlayer().getRandom());
int count = MathUtils.naturalRandFloor(IPowerContainer.modify(event.getPlayer(), OriginsClassesPowers.MODIFY_BONE_MEAL.get(), 1.0D), event.getPlayer().getRandom());
if(count == 0) {
event.setCanceled(true);
event.setResult(Event.Result.DENY);
Expand All @@ -118,6 +120,7 @@ public static void onBoneMeal(BonemealEvent event) {
}
}

//InfiniteTrade
@SubscribeEvent
public static void onInteractEntity(PlayerInteractEvent.EntityInteract event) {
if(event.getPlayer() instanceof ServerPlayer sp) {
Expand All @@ -130,24 +133,27 @@ public static void onInteractEntity(PlayerInteractEvent.EntityInteract event) {
}
}

//Multimine & MiningSpeed
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onBreakSpeed(PlayerEvent.BreakSpeed event) {
double multiplier = event.getPlayer().getAttributeValue(OriginsClassesAttributes.MINING_SPEED.get());
event.setNewSpeed(MultiMinePower.modifyBreakingSpeed((float) (event.getNewSpeed() * multiplier), event.getPlayer(), event.getPos(), event.getState()));
}

//ProjectileStrength
@SubscribeEvent
public static void onArrowShoots(EntityJoinWorldEvent event) {
if(event.getEntity() instanceof AbstractArrow arrow && arrow.getOwner() instanceof LivingEntity owner) {
arrow.setBaseDamage(arrow.getBaseDamage() * owner.getAttributeValue(OriginsClassesAttributes.PROJECTILE_STRENGTH.get()));
}
}

//ModifyEntityLoot
@SubscribeEvent
public static void onLivingDrops(LivingDropsEvent event) {
if(event.getSource() instanceof EntityDamageSource eds && eds.getEntity() instanceof Player player) {
LivingEntity target = event.getEntityLiving();
int amount = PowerUtil.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_ENTITY_LOOT.get(), 1.0F, cp -> cp.isActive(player) && ConfiguredBiEntityCondition.check(cp.getConfiguration().condition(), player, target)), player.getRandom());
int amount = MathUtils.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_ENTITY_LOOT.get(), 1.0F, cp -> cp.isActive(player) && ConfiguredBiEntityCondition.check(cp.getConfiguration().condition(), player, target)), player.getRandom());
for(int i = 1; i < amount; ++i) {
((LivingEntityAccessor)target).invokeDropFromLootTable(event.getSource(), true);
}
Expand All @@ -158,19 +164,16 @@ public static void onLivingDrops(LivingDropsEvent event) {
public static void onTooltip(ItemTooltipEvent event) {
if(event.getFlags().isAdvanced()) {
ItemStack stack = event.getItemStack();
if(stack.hasTag() && stack.getOrCreateTag().contains(PowerUtil.ORIGINS_CLASSES, Tag.TAG_COMPOUND)) {
CompoundTag bonus = stack.getOrCreateTagElement(PowerUtil.ORIGINS_CLASSES);
List<Component> tooltip = event.getToolTip();
if(bonus.contains(PowerUtil.FOOD_BONUS, Tag.TAG_FLOAT)) {
FoodProperties food = stack.getItem().getFoodProperties();
if(food != null) {
tooltip.add(new TranslatableComponent(FOOD_BONUS_TRANSLATION_KEY, Mth.floor(bonus.getFloat(PowerUtil.FOOD_BONUS) * food.getNutrition())).withStyle(ChatFormatting.BLUE));
}
}
if(bonus.contains(PowerUtil.POTION_BONUS, Tag.TAG_BYTE)) {
tooltip.add(new TranslatableComponent(POTION_BONUS_TRANSLATION_KEY, bonus.getByte(PowerUtil.POTION_BONUS)).withStyle(ChatFormatting.BLUE));
List<Component> tooltip = event.getToolTip();
NbtUtils.getOriginsClassesData(stack, NbtUtils.FOOD_BONUS, NbtType.FLOAT).ifPresent(f -> {
FoodProperties food = stack.getItem().getFoodProperties();
if(food != null) {
tooltip.add(new TranslatableComponent(FOOD_BONUS_TRANSLATION_KEY, Mth.floor(f * food.getNutrition())).withStyle(ChatFormatting.BLUE));
}
}
});
NbtUtils.getOriginsClassesData(stack, NbtUtils.POTION_BONUS, NbtType.BYTE).ifPresent(b ->
tooltip.add(new TranslatableComponent(POTION_BONUS_TRANSLATION_KEY, b).withStyle(ChatFormatting.BLUE))
);
}
}

Expand Down
Loading

0 comments on commit e5e5a49

Please sign in to comment.