diff --git a/build.gradle b/build.gradle index 3b37fa0..6b1f7b0 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/gradle.properties b/gradle.properties index f8892df..3981a1d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ 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 @@ -18,4 +18,7 @@ org.gradle.daemon=false # Dependencies caelus_version=1.18.1-3.0.0.2 - origins_version=3747132 \ No newline at end of file + origins_version=3747132 + +# Compat Dependencies + apotheosis_version=3647864 \ No newline at end of file diff --git a/libs/Placebo-1.18.1-6.1.2-dev.jar b/libs/Placebo-1.18.1-6.1.2-dev.jar new file mode 100644 index 0000000..c44e601 Binary files /dev/null and b/libs/Placebo-1.18.1-6.1.2-dev.jar differ diff --git a/src/main/java/limonblaze/originsclasses/common/OriginsClassesCommon.java b/src/main/java/limonblaze/originsclasses/common/OriginsClassesCommon.java index fdea18b..b704cd1 100644 --- a/src/main/java/limonblaze/originsclasses/common/OriginsClassesCommon.java +++ b/src/main/java/limonblaze/originsclasses/common/OriginsClassesCommon.java @@ -20,7 +20,6 @@ public class OriginsClassesCommon { public static void setup(final FMLCommonSetupEvent event) { event.enqueueWork(OriginsClassesCommon::initNetwork); - MultiMinePower.bootstrap(); } private static void initNetwork() { diff --git a/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifyBreedingConfiguration.java b/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifyBreedingConfiguration.java index dd5b57e..2116224 100644 --- a/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifyBreedingConfiguration.java +++ b/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifyBreedingConfiguration.java @@ -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; @@ -16,7 +17,7 @@ public record ModifyBreedingConfiguration(ListConfiguration modifiers, @Nullable ConfiguredBiEntityCondition parentsCondition, @Nullable ConfiguredBiEntityAction parentsAction, - @Nullable ConfiguredEntityAction playerAction) implements IDynamicFeatureConfiguration { + @Nullable ConfiguredEntityAction playerAction) implements IValueModifyingPowerConfiguration { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( ListConfiguration.modifierCodec("modifier") diff --git a/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifySpeedOnItemUseConfiguration.java b/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifySpeedOnItemUseConfiguration.java index 7187e32..d0599e8 100644 --- a/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifySpeedOnItemUseConfiguration.java +++ b/src/main/java/limonblaze/originsclasses/common/apoli/configuration/ModifySpeedOnItemUseConfiguration.java @@ -5,6 +5,7 @@ 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; @@ -12,7 +13,7 @@ import java.util.Optional; public record ModifySpeedOnItemUseConfiguration(ListConfiguration modifiers, - @Nullable ConfiguredItemCondition itemCondition) implements IDynamicFeatureConfiguration { + @Nullable ConfiguredItemCondition itemCondition) implements IValueModifyingPowerConfiguration { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( ListConfiguration.modifierCodec("modifier") diff --git a/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifyBreedingPower.java b/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifyBreedingPower.java index 379c052..2fae4a7 100644 --- a/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifyBreedingPower.java +++ b/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifyBreedingPower.java @@ -1,31 +1,24 @@ 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 implements IValueModifyingPower { +public class ModifyBreedingPower extends ValueModifyingPowerFactory { 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); @@ -33,9 +26,4 @@ public static int getBreedAmount(Player player, Animal actor, Animal target) { }), player.getRandom()); } - @Override - public @Nonnull List getModifiers(ConfiguredPower configuredPower, Entity entity) { - return configuredPower.getConfiguration().modifiers().getContent(); - } - } \ No newline at end of file diff --git a/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifySpeedOnItemUsePower.java b/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifySpeedOnItemUsePower.java index a22f718..b62c681 100644 --- a/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifySpeedOnItemUsePower.java +++ b/src/main/java/limonblaze/originsclasses/common/apoli/power/ModifySpeedOnItemUsePower.java @@ -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; @@ -16,7 +17,7 @@ import javax.annotation.Nonnull; import java.util.List; -public class ModifySpeedOnItemUsePower extends PowerFactory implements IValueModifyingPower { +public class ModifySpeedOnItemUsePower extends ValueModifyingPowerFactory { public ModifySpeedOnItemUsePower() { super(ModifySpeedOnItemUseConfiguration.CODEC); @@ -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 getModifiers(ConfiguredPower configuredPower, Entity entity) { - return configuredPower.getConfiguration().modifiers().getContent(); - } - } diff --git a/src/main/java/limonblaze/originsclasses/common/apoli/power/MultiMinePower.java b/src/main/java/limonblaze/originsclasses/common/apoli/power/MultiMinePower.java index a10dff0..a1d4188 100644 --- a/src/main/java/limonblaze/originsclasses/common/apoli/power/MultiMinePower.java +++ b/src/main/java/limonblaze/originsclasses/common/apoli/power/MultiMinePower.java @@ -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; @@ -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 { - private static final List POWERS = new ArrayList<>(); - public final Miner miner; + private static ImmutableList 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 factories() { + if(FACTORIES == null) { + ImmutableList.Builder 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) { @@ -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> cmmps = POWERS.stream() + public static Optional, Float>> getResult(Player player, BlockPos pos, BlockState state) { + List> cmmps = factories().stream() .flatMap(pf -> IPowerContainer.getPowers(player, pf).stream()) .filter(cp -> shouldApply(cp, player, pos, state)) .toList(); for(ConfiguredPower cmmp : cmmps) { - List affectBlock = cmmp.getFactory().miner.getAffectedBlocks(player, state, pos); - if(affectBlock.size() > 0) { - return new MultiMineData(affectBlock, cmmp.getConfiguration().speedMultiplier()); + List 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) { @@ -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 affectedBlocks, float speedMultiplier) { - - public float getModifiedSpeed(float speed) { - return speed * this.speedMultiplier / affectedBlocks.size(); - } - - } - - @FunctionalInterface - public interface Miner { - List getAffectedBlocks(Player player, BlockState state, BlockPos pos); + return processMultimine ? speed * getResult(player, pos, state).map(Pair::getSecond).orElse(1.0F) : speed; } } diff --git a/src/main/java/limonblaze/originsclasses/common/event/PowerEventHandler.java b/src/main/java/limonblaze/originsclasses/common/event/PowerEventHandler.java index 1a5ec6a..4d7bb9e 100644 --- a/src/main/java/limonblaze/originsclasses/common/event/PowerEventHandler.java +++ b/src/main/java/limonblaze/originsclasses/common/event/PowerEventHandler.java @@ -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; @@ -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()); @@ -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(); @@ -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); @@ -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) { @@ -130,12 +133,14 @@ 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) { @@ -143,11 +148,12 @@ public static void onArrowShoots(EntityJoinWorldEvent event) { } } + //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); } @@ -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 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 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)) + ); } } diff --git a/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesConditions.java b/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesConditions.java index 4c45bae..f87504e 100644 --- a/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesConditions.java +++ b/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesConditions.java @@ -11,7 +11,7 @@ import io.github.edwinmindcraft.apoli.common.condition.item.SimpleItemCondition; import limonblaze.originsclasses.OriginsClasses; import limonblaze.originsclasses.common.apoli.condition.item.ToolActionCondition; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.MathUtils; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.item.*; @@ -25,7 +25,7 @@ public class OriginsClassesConditions { public static final DeferredRegister> BIENTITY_CONDITIONS = DeferredRegister.create(ApoliRegistries.BIENTITY_CONDITION_CLASS, OriginsClasses.MODID); public static final RegistryObject YAW_DIFF = BIENTITY_CONDITIONS.register("yaw_diff", () -> - new DoubleComparingBiEntityCondition(PowerUtil::yawDiff)); + new DoubleComparingBiEntityCondition(MathUtils::yawDiff)); public static final DeferredRegister> ENTITY_CONDITIONS = DeferredRegister.create(ApoliRegistries.ENTITY_CONDITION_CLASS, OriginsClasses.MODID); public static final RegistryObject ANIMAL = ENTITY_CONDITIONS.register("animal", () -> diff --git a/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesPowers.java b/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesPowers.java index 94ffe31..1f0a9dc 100644 --- a/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesPowers.java +++ b/src/main/java/limonblaze/originsclasses/common/registry/OriginsClassesPowers.java @@ -7,7 +7,7 @@ import io.github.edwinmindcraft.apoli.common.power.ModifyValuePower; import limonblaze.originsclasses.OriginsClasses; import limonblaze.originsclasses.common.apoli.power.*; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.MultiMiner; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.RegistryObject; @@ -41,7 +41,7 @@ public class OriginsClassesPowers { public static final RegistryObject INFINITE_TRADE = POWER_FACTORIES.register("infinite_trade", DummyPower::new); public static final RegistryObject RARE_WANDERING_LOOT = POWER_FACTORIES.register("rare_wandering_loot", DummyPower::new); // Lumberjack - public static final RegistryObject LUMBERJACK = POWER_FACTORIES.register("lumberjack", () -> new MultiMinePower(PowerUtil::lumberjackMiner)); + public static final RegistryObject LUMBERJACK = POWER_FACTORIES.register("lumberjack", () -> new MultiMinePower(MultiMiner.LUMBERJACK)); // Miner public static final RegistryObject NO_MINING_EXHAUSTION = POWER_FACTORIES.register("no_mining_exhaustion", DummyPower::new); // Adventurer diff --git a/src/main/java/limonblaze/originsclasses/compat/OriginsClassesCompat.java b/src/main/java/limonblaze/originsclasses/compat/OriginsClassesCompat.java new file mode 100644 index 0000000..a1daea7 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/compat/OriginsClassesCompat.java @@ -0,0 +1,62 @@ +package limonblaze.originsclasses.compat; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class OriginsClassesCompat implements IMixinConfigPlugin { + private static boolean APOTHEOSIS; + + private static boolean checkForClass(String cls) { + try { + Class.forName(cls, false, OriginsClassesCompat.class.getClassLoader()); + return true; + } catch (ClassNotFoundException exception) { + return false; + } + } + + @Override + public void onLoad(String mixinPackage) { + if(checkForClass("shadows.apotheosis.Apotheosis")) { + APOTHEOSIS = true; + } + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return switch(mixinClassName) { + case "limonblaze.originsclasses.mixin.compat.apotheosis.ApotheosisEnchantmentMenuMixin" -> APOTHEOSIS; + case "limonblaze.originsclasses.mixin.AnvilMenuMixin" -> !APOTHEOSIS; + default -> true; + }; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } +} diff --git a/src/main/java/limonblaze/originsclasses/mixin/AbstractCauldronBlockMixin.java b/src/main/java/limonblaze/originsclasses/mixin/AbstractCauldronBlockMixin.java index dc99739..1c2908b 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/AbstractCauldronBlockMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/AbstractCauldronBlockMixin.java @@ -2,7 +2,9 @@ import io.github.edwinmindcraft.apoli.api.component.IPowerContainer; import limonblaze.originsclasses.common.registry.OriginsClassesPowers; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.ClericUtils; +import limonblaze.originsclasses.util.NbtType; +import limonblaze.originsclasses.util.NbtUtils; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -31,11 +33,13 @@ public class AbstractCauldronBlockMixin { private void originsClasses$addPotionBonus(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable cir) { if(state.is(Blocks.WATER_CAULDRON) && state.getValue(LayeredCauldronBlock.LEVEL) > 0) { ItemStack stack = player.getItemInHand(hand); - if(!(stack.getItem() instanceof PotionItem && stack.hasTag() && !PotionUtils.getPotion(stack).getEffects().isEmpty() && stack.getOrCreateTag().contains(PowerUtil.ORIGINS_CLASSES) && stack.getOrCreateTagElement(PowerUtil.ORIGINS_CLASSES).contains(PowerUtil.POTION_BONUS))) { + if(stack.getItem() instanceof PotionItem && + !PotionUtils.getPotion(stack).getEffects().isEmpty() && + NbtUtils.getOriginsClassesData(stack, NbtUtils.POTION_BONUS, NbtType.BYTE).isPresent()) { int bonus = IPowerContainer.getPowers(player, OriginsClassesPowers.POTION_BONUS.get()).stream() .filter(cp -> cp.isActive(player)).mapToInt(cp -> cp.getConfiguration().value()).sum(); if(bonus > 0) { - PowerUtil.setPotionBonus(stack, (byte) bonus); + ClericUtils.setPotionBonus(stack, (byte) bonus); LayeredCauldronBlock.lowerFillLevel(state, world, pos); world.playSound(null, pos, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, 1.0F, 1.0F); world.gameEvent(null, GameEvent.FLUID_PICKUP, pos); diff --git a/src/main/java/limonblaze/originsclasses/mixin/AbstractVillagerMixin.java b/src/main/java/limonblaze/originsclasses/mixin/AbstractVillagerMixin.java index be650be..2da6ad3 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/AbstractVillagerMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/AbstractVillagerMixin.java @@ -3,7 +3,7 @@ import io.github.edwinmindcraft.apoli.api.component.IPowerContainer; import limonblaze.originsclasses.common.data.tag.OriginsClassesItemTags; import limonblaze.originsclasses.common.registry.OriginsClassesPowers; -import limonblaze.originsclasses.util.ItemUtil; +import limonblaze.originsclasses.util.MerchantUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.AgeableMob; import net.minecraft.world.entity.EntityType; @@ -85,7 +85,7 @@ protected AbstractVillagerMixin(EntityType type, Level wor Set excludedItems = new HashSet<>(OriginsClassesItemTags.MERCHANT_BLACKLIST.getValues()); list.add(new MerchantOffer( new ItemStack(Items.EMERALD, random.nextInt(12) + 6), - ItemUtil.createMerchantItemStack(ItemUtil.getRandomObtainableItem( + MerchantUtils.createMerchantItemStack(MerchantUtils.getRandomObtainableItem( this.getServer(), random, excludedItems), random), @@ -93,13 +93,13 @@ protected AbstractVillagerMixin(EntityType type, Level wor 5, 0.05F) ); - Item desiredItem = ItemUtil.getRandomObtainableItem( + Item desiredItem = MerchantUtils.getRandomObtainableItem( this.getServer(), random, excludedItems); list.add(new MerchantOffer( new ItemStack(desiredItem, 1 + random.nextInt(Math.min(16, desiredItem.getDefaultInstance().getMaxStackSize()))), - ItemUtil.createMerchantItemStack(ItemUtil.getRandomObtainableItem( + MerchantUtils.createMerchantItemStack(MerchantUtils.getRandomObtainableItem( this.getServer(), random, excludedItems), random), diff --git a/src/main/java/limonblaze/originsclasses/mixin/ArrowMixin.java b/src/main/java/limonblaze/originsclasses/mixin/ArrowMixin.java index 9019dca..1889260 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/ArrowMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/ArrowMixin.java @@ -1,6 +1,6 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.ClericUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.projectile.Arrow; @@ -19,7 +19,7 @@ public class ArrowMixin { @Inject(method = "setEffectsFromItem", at = @At("TAIL")) private void originsClasses$initFromAdditionalPotionNbt(ItemStack arrow, CallbackInfo ci) { - byte bonus = PowerUtil.getPotionBonus(arrow); + byte bonus = ClericUtils.getPotionBonus(arrow); if(bonus > 0) { this.originsClass$potionBonus = bonus; } @@ -27,22 +27,22 @@ public class ArrowMixin { @Inject(method = "addAdditionalSaveData", at = @At("TAIL")) private void originsClasses$writeAdditionalPotionNbt(CompoundTag nbt, CallbackInfo ci){ - if(originsClass$potionBonus > 0) PowerUtil.setPotionBonus(nbt, originsClass$potionBonus); + if(originsClass$potionBonus > 0) ClericUtils.setPotionBonus(nbt, originsClass$potionBonus); } @Inject(method = "readAdditionalSaveData", at = @At("TAIL")) private void originsClasses$readAdditionalPotionNbt(CompoundTag nbt, CallbackInfo ci){ - originsClass$potionBonus = PowerUtil.getPotionBonus(nbt); + originsClass$potionBonus = ClericUtils.getPotionBonus(nbt); } @Inject(method = "getPickupItem", at = @At("RETURN"), cancellable = true) private void originsClasses$storeAdditionalPotionNbt(CallbackInfoReturnable cir) { - if(originsClass$potionBonus > 0) cir.setReturnValue(PowerUtil.setPotionBonus(cir.getReturnValue(), originsClass$potionBonus)); + if(originsClass$potionBonus > 0) cir.setReturnValue(ClericUtils.setPotionBonus(cir.getReturnValue(), originsClass$potionBonus)); } @ModifyArg(method = "doPostHurtEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z"), index = 0) private MobEffectInstance originsClasses$handlePotionBonus(MobEffectInstance effect) { - return originsClass$potionBonus > 0 ? PowerUtil.applyPotionBonus(effect, originsClass$potionBonus) : effect; + return originsClass$potionBonus > 0 ? ClericUtils.applyPotionBonus(effect, originsClass$potionBonus) : effect; } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/BlockMixin.java b/src/main/java/limonblaze/originsclasses/mixin/BlockMixin.java index c91ac2a..3a6e3fa 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/BlockMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/BlockMixin.java @@ -3,7 +3,7 @@ import io.github.edwinmindcraft.apoli.api.component.IPowerContainer; import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBlockCondition; import limonblaze.originsclasses.common.registry.OriginsClassesPowers; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.MathUtils; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -25,7 +25,7 @@ public abstract class BlockMixin { @Inject(method = "playerDestroy", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V")) private void originsClasses$additionalDrop(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack, CallbackInfo ci) { - int amount = PowerUtil.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BLOCK_LOOT.get(), 1.0F, cp -> cp.isActive(player) && ConfiguredBlockCondition.check(cp.getConfiguration().condition(), world, pos, () -> state)), world.random); + int amount = MathUtils.naturalRandFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BLOCK_LOOT.get(), 1.0F, cp -> cp.isActive(player) && ConfiguredBlockCondition.check(cp.getConfiguration().condition(), world, pos, () -> state)), world.random); for(int i = 1; i < amount; ++i) { Block.dropResources(state, world, pos, blockEntity, player, stack); } diff --git a/src/main/java/limonblaze/originsclasses/mixin/BrewingRecipeRegistryMixin.java b/src/main/java/limonblaze/originsclasses/mixin/BrewingRecipeRegistryMixin.java index b370078..fe55273 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/BrewingRecipeRegistryMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/BrewingRecipeRegistryMixin.java @@ -1,6 +1,6 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.ClericUtils; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.PotionItem; import net.minecraftforge.common.brewing.BrewingRecipeRegistry; @@ -16,9 +16,9 @@ public class BrewingRecipeRegistryMixin { private static void originsClasses$handleAdditionalPotionNbt(ItemStack input, ItemStack ingredient, CallbackInfoReturnable cir) { ItemStack output = cir.getReturnValue(); if(output.getItem() instanceof PotionItem && input.hasTag()) { - byte bonus = PowerUtil.getPotionBonus(input); + byte bonus = ClericUtils.getPotionBonus(input); if(bonus > 0) { - cir.setReturnValue(PowerUtil.setPotionBonus(output, bonus)); + cir.setReturnValue(ClericUtils.setPotionBonus(output, bonus)); } } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/EnchantmentMenuMixin.java b/src/main/java/limonblaze/originsclasses/mixin/EnchantmentMenuMixin.java index 68404c6..2c6ae7a 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/EnchantmentMenuMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/EnchantmentMenuMixin.java @@ -1,6 +1,7 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.NbtUtils; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -29,7 +30,7 @@ public class EnchantmentMenuMixin { @ModifyVariable(method = "slotsChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ContainerLevelAccess;execute(Ljava/util/function/BiConsumer;)V")) private ItemStack originsClasses$storeEnchanter(ItemStack stack) { if(this.originsClasses$enchanter != null) { - stack.getOrCreateTag().putUUID(PowerUtil.ORIGINS_CLASSES_ENCHANTER, this.originsClasses$enchanter.getUUID()); + stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES).putUUID(NbtUtils.ENCHANTER, this.originsClasses$enchanter.getUUID()); } return stack; } @@ -37,7 +38,9 @@ public class EnchantmentMenuMixin { @Inject(method = "slotsChanged", at = @At("TAIL")) private void originsClasses$clearEnchanter(Container inventory, CallbackInfo ci) { ItemStack stack = inventory.getItem(0); - stack.removeTagKey(PowerUtil.ORIGINS_CLASSES_ENCHANTER); + CompoundTag ocNbt = stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES); + ocNbt.remove(NbtUtils.ENCHANTER); + if(ocNbt.isEmpty()) stack.removeTagKey(NbtUtils.ORIGINS_CLASSES); } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/FoodDataMixin.java b/src/main/java/limonblaze/originsclasses/mixin/FoodDataMixin.java index 32d6518..ed961cb 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/FoodDataMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/FoodDataMixin.java @@ -1,6 +1,7 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.NbtType; +import limonblaze.originsclasses.util.NbtUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.util.Mth; @@ -22,11 +23,9 @@ public abstract class FoodDataMixin { @Inject(method = "eat(Lnet/minecraft/world/item/Item;Lnet/minecraft/world/item/ItemStack;)V", at = @At("TAIL")) private void originsClasses$handleFoodBonus(Item item, ItemStack stack, CallbackInfo ci) { FoodProperties food = item.getFoodProperties(); - if(food != null && stack.hasTag() && stack.getOrCreateTag().contains(PowerUtil.ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { - CompoundTag nbt = stack.getOrCreateTagElement(PowerUtil.ORIGINS_CLASSES); - if(nbt.contains(PowerUtil.FOOD_BONUS, Tag.TAG_FLOAT)) { - this.eat(Mth.floor(food.getNutrition() * nbt.getFloat(PowerUtil.FOOD_BONUS)), food.getSaturationModifier()); - } + if(food != null) { + NbtUtils.getOriginsClassesData(stack, NbtUtils.FOOD_BONUS, NbtType.FLOAT).ifPresent(f -> + this.eat(Mth.floor(food.getNutrition() * f), food.getSaturationModifier())); } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/PotionUtilMixin.java b/src/main/java/limonblaze/originsclasses/mixin/PotionUtilMixin.java index 98f8735..9d64dc8 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/PotionUtilMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/PotionUtilMixin.java @@ -1,6 +1,6 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.ClericUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.alchemy.PotionUtils; @@ -18,9 +18,9 @@ public class PotionUtilMixin { @Inject(method = "getAllEffects(Lnet/minecraft/nbt/CompoundTag;)Ljava/util/List;", at = @At("RETURN"), cancellable = true) private static void originsClasses$modifyPotion(@Nullable CompoundTag nbt, CallbackInfoReturnable> cir) { - byte bonusLevel = PowerUtil.getPotionBonus(nbt); + byte bonusLevel = ClericUtils.getPotionBonus(nbt); if(bonusLevel > 0) { - cir.setReturnValue(cir.getReturnValue().stream().map(effect -> PowerUtil.applyPotionBonus(effect, bonusLevel)).collect(Collectors.toList())); + cir.setReturnValue(cir.getReturnValue().stream().map(effect -> ClericUtils.applyPotionBonus(effect, bonusLevel)).collect(Collectors.toList())); } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/ServerPlayerGameModeMixin.java b/src/main/java/limonblaze/originsclasses/mixin/ServerPlayerGameModeMixin.java index f6fb5a6..2abea0d 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/ServerPlayerGameModeMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/ServerPlayerGameModeMixin.java @@ -1,5 +1,6 @@ package limonblaze.originsclasses.mixin; +import com.mojang.datafixers.util.Pair; import limonblaze.originsclasses.common.OriginsClassesCommon; import limonblaze.originsclasses.common.duck.SneakingStateSave; import limonblaze.originsclasses.common.apoli.power.MultiMinePower; @@ -20,6 +21,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.List; +import java.util.Optional; + @Mixin(ServerPlayerGameMode.class) public abstract class ServerPlayerGameModeMixin implements SneakingStateSave { @@ -49,14 +53,16 @@ public abstract class ServerPlayerGameModeMixin implements SneakingStateSave { private void originsClasses$multiMinePower(BlockPos pos, ServerboundPlayerActionPacket.Action action, String reason, CallbackInfo ci) { if(!originsClasses$wasSneakingWhenStarted && !originsClasses$performingMultiMine) { originsClasses$performingMultiMine = true; - MultiMinePower.MultiMineData data = MultiMinePower.getMultiMineData(player, pos, originsClasses$justMinedState); - ItemStack tool = player.getMainHandItem().copy(); - for(BlockPos bp : data.affectedBlocks()) { - destroyAndAck(bp, action, reason); - if(!player.getMainHandItem().sameItem(tool)) { - break; + Optional, Float>> result = MultiMinePower.getResult(player, pos, originsClasses$justMinedState); + result.ifPresent(pair -> { + ItemStack tool = player.getMainHandItem().copy(); + for(BlockPos bp : pair.getFirst()) { + destroyAndAck(bp, action, reason); + if(!player.getMainHandItem().sameItem(tool)) { + break; + } } - } + }); originsClasses$performingMultiMine = false; } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/TippedArrowRecipeMixin.java b/src/main/java/limonblaze/originsclasses/mixin/TippedArrowRecipeMixin.java index 84b870a..6a44e41 100644 --- a/src/main/java/limonblaze/originsclasses/mixin/TippedArrowRecipeMixin.java +++ b/src/main/java/limonblaze/originsclasses/mixin/TippedArrowRecipeMixin.java @@ -1,6 +1,6 @@ package limonblaze.originsclasses.mixin; -import limonblaze.originsclasses.util.PowerUtil; +import limonblaze.originsclasses.util.ClericUtils; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.TippedArrowRecipe; @@ -18,9 +18,9 @@ public class TippedArrowRecipeMixin { if(!result.isEmpty()) { ItemStack input = inv.getItem(1 + inv.getWidth()); if(input.hasTag()) { - byte bonus = PowerUtil.getPotionBonus(input); + byte bonus = ClericUtils.getPotionBonus(input); if(bonus > 0) { - cir.setReturnValue(PowerUtil.setPotionBonus(result, bonus)); + cir.setReturnValue(ClericUtils.setPotionBonus(result, bonus)); } } } diff --git a/src/main/java/limonblaze/originsclasses/mixin/compat/apotheosis/ApotheosisEnchantmentMenuMixin.java b/src/main/java/limonblaze/originsclasses/mixin/compat/apotheosis/ApotheosisEnchantmentMenuMixin.java new file mode 100644 index 0000000..f2ce3f8 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/mixin/compat/apotheosis/ApotheosisEnchantmentMenuMixin.java @@ -0,0 +1,36 @@ +package limonblaze.originsclasses.mixin.compat.apotheosis; + +import limonblaze.originsclasses.util.NbtUtils; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import shadows.apotheosis.ench.table.ApothEnchantContainer; + +@Mixin(ApothEnchantContainer.class) +public class ApotheosisEnchantmentMenuMixin { + + @Shadow(remap = false) @Final protected Player player; + + @ModifyVariable(method = "lambda$slotsChanged$1", at = @At(value = "INVOKE", target = "Lshadows/apotheosis/ench/table/ApothEnchantContainer;gatherStats()V", remap = false)) + private ItemStack originsClasses$storeEnchanter(ItemStack stack) { + stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES).putUUID(NbtUtils.ENCHANTER, this.player.getUUID()); + return stack; + } + + @Inject(method = "slotsChanged", at = @At("TAIL")) + private void originsClasses$clearEnchanter(Container inventoryIn, CallbackInfo ci) { + ItemStack stack = inventoryIn.getItem(0); + CompoundTag ocNbt = stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES); + ocNbt.remove(NbtUtils.ENCHANTER); + if(ocNbt.isEmpty()) stack.removeTagKey(NbtUtils.ORIGINS_CLASSES); + } + +} diff --git a/src/main/java/limonblaze/originsclasses/util/ClericUtils.java b/src/main/java/limonblaze/originsclasses/util/ClericUtils.java new file mode 100644 index 0000000..98d2032 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/ClericUtils.java @@ -0,0 +1,45 @@ +package limonblaze.originsclasses.util; + +import limonblaze.originsclasses.compat.OriginsClassesCompat; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.ItemStack; +import shadows.apotheosis.Apotheosis; + +public class ClericUtils { + + public static byte getPotionBonus(ItemStack stack) { + return NbtUtils.getOriginsClassesData(stack, NbtUtils.POTION_BONUS, NbtType.BYTE, (byte)-1); + } + + public static byte getPotionBonus(CompoundTag nbt) { + return NbtUtils.getOriginsClassesData(nbt, NbtUtils.POTION_BONUS, NbtType.BYTE, (byte)-1); + } + + public static ItemStack setPotionBonus(ItemStack stack, byte bonus) { + stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES).putByte(NbtUtils.POTION_BONUS, bonus); + return stack; + } + + public static CompoundTag setPotionBonus(CompoundTag tag, byte bonus) { + if(!tag.contains(NbtUtils.ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { + tag.put(NbtUtils.ORIGINS_CLASSES, new CompoundTag()); + } + tag.getCompound(NbtUtils.ORIGINS_CLASSES).putByte(NbtUtils.POTION_BONUS, bonus); + return tag; + } + + public static MobEffectInstance applyPotionBonus(MobEffectInstance effect, byte bonusLevel) { + boolean instant = effect.getEffect().isInstantenous(); + return new MobEffectInstance( + effect.getEffect(), + instant ? effect.getDuration() : effect.getDuration() * (1 + bonusLevel), + instant ? effect.getAmplifier() + bonusLevel : effect.getAmplifier(), + effect.isAmbient(), + effect.isVisible(), + effect.showIcon() + ); + } + +} diff --git a/src/main/java/limonblaze/originsclasses/util/MathUtils.java b/src/main/java/limonblaze/originsclasses/util/MathUtils.java new file mode 100644 index 0000000..9524a36 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/MathUtils.java @@ -0,0 +1,29 @@ +package limonblaze.originsclasses.util; + +import net.minecraft.world.entity.Entity; + +import java.util.*; + +public class MathUtils { + + public static int naturalRandFloor(double d, Random random) { + if(d > 0) { + int i = (int) d; + return random.nextDouble() < d - i ? i + 1 : i; + } + return 0; + } + + public static double yawDiff(Entity actor, Entity target) { + float yawTarget = target.getYRot(); + while(yawTarget < 0F) yawTarget += 360F; + yawTarget %= 360F; + + float yawSelf = actor.getYRot(); + while(yawSelf < 0F) yawSelf += 360F; + yawSelf %= 360F; + + return Math.abs(yawTarget - yawSelf); + } + +} diff --git a/src/main/java/limonblaze/originsclasses/util/ItemUtil.java b/src/main/java/limonblaze/originsclasses/util/MerchantUtils.java similarity index 94% rename from src/main/java/limonblaze/originsclasses/util/ItemUtil.java rename to src/main/java/limonblaze/originsclasses/util/MerchantUtils.java index b6a1e04..a37fca6 100644 --- a/src/main/java/limonblaze/originsclasses/util/ItemUtil.java +++ b/src/main/java/limonblaze/originsclasses/util/MerchantUtils.java @@ -16,7 +16,7 @@ import java.util.*; -public class ItemUtil { +public class MerchantUtils { private static boolean APPENDED_OBTAINABLE_ITEMS; private static final Set OBTAINABLE = new HashSet<>(); @@ -54,9 +54,9 @@ public static void appendObtainableItems(MinecraftServer server) { while(!entryQueue.isEmpty()) { LootPoolEntryContainer entry = entryQueue.remove(); if(entry instanceof LootItem li) { - ItemUtil.OBTAINABLE.add(li.item); + MerchantUtils.OBTAINABLE.add(li.item); } else if(entry instanceof TagEntry te) { - ItemUtil.OBTAINABLE.addAll(te.tag.getValues()); + MerchantUtils.OBTAINABLE.addAll(te.tag.getValues()); } else if(entry instanceof CompositeEntryBase ceb) { entryQueue.addAll(Arrays.asList(ceb.children)); } diff --git a/src/main/java/limonblaze/originsclasses/util/MultiMiner.java b/src/main/java/limonblaze/originsclasses/util/MultiMiner.java new file mode 100644 index 0000000..c1c54d0 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/MultiMiner.java @@ -0,0 +1,57 @@ +package limonblaze.originsclasses.util; + +import net.minecraft.core.BlockPos; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; + +import java.util.*; + +@FunctionalInterface +public interface MultiMiner { + + List getAffectedBlocks(Player player, BlockState state, BlockPos pos); + + MultiMiner LUMBERJACK = (player, state, pos) -> { + Set affected = new HashSet<>(); + Queue queue = new LinkedList<>(); + queue.add(pos); + boolean foundOneWithLeaves = false; + BlockPos.MutableBlockPos pos$mutable = pos.mutable(); + BlockPos.MutableBlockPos newPos$mutable = pos.mutable(); + while(!queue.isEmpty()) { + pos$mutable.set(queue.remove()); + for(int dx = -1; dx <= 1; dx++) { + for(int dy = 0; dy <= 1; dy++) { + for(int dz = -1; dz <= 1; dz++) { + if(dx == 0 & dy == 0 && dz == 0) { + continue; + } + newPos$mutable.set(pos$mutable.getX() + dx, pos$mutable.getY() + dy, pos$mutable.getZ() + dz); + BlockState newState = player.level.getBlockState(newPos$mutable); + if(newState.is(state.getBlock()) && !affected.contains(newPos$mutable)) { + BlockPos savedNewPos = newPos$mutable.immutable(); + affected.add(savedNewPos); + queue.add(savedNewPos); + if(affected.size() > 255) { + if(!foundOneWithLeaves) { + return new ArrayList<>(); + } + return new ArrayList<>(affected); + } + } else + if((BlockTags.LEAVES.contains(newState.getBlock()) || newState.getBlock() instanceof LeavesBlock) && !newState.getValue(LeavesBlock.PERSISTENT)) { + foundOneWithLeaves = true; + } + } + } + } + } + if(!foundOneWithLeaves) { + affected.clear(); + } + return new ArrayList<>(affected); + }; + +} diff --git a/src/main/java/limonblaze/originsclasses/util/NbtType.java b/src/main/java/limonblaze/originsclasses/util/NbtType.java new file mode 100644 index 0000000..ebd3687 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/NbtType.java @@ -0,0 +1,45 @@ +package limonblaze.originsclasses.util; + +import net.minecraft.nbt.CompoundTag; + +import java.util.UUID; +import java.util.function.BiFunction; + +public class NbtType { + public static final NbtType BYTE = new NbtType<>(1, CompoundTag::getByte); + public static final NbtType SHORT = new NbtType<>(2, CompoundTag::getShort); + public static final NbtType INT = new NbtType<>(3, CompoundTag::getInt); + public static final NbtType LONG = new NbtType<>(4, CompoundTag::getLong); + public static final NbtType FLOAT = new NbtType<>(5, CompoundTag::getFloat); + public static final NbtType DOUBLE = new NbtType<>(6, CompoundTag::getDouble); + public static final NbtType BYTE_ARRAY = new NbtType<>(7, CompoundTag::getByteArray); + public static final NbtType STRING = new NbtType<>(8, CompoundTag::getString); + //TagList is not compatible with the getter bifunction + public static final NbtType COMPOUND = new NbtType<>(10, CompoundTag::getCompound); + public static final NbtType INT_ARRAY = new NbtType<>(11, CompoundTag::getIntArray); + public static final NbtType LONG_ARRAY = new NbtType<>(12, CompoundTag::getLongArray); + //TAG_ANY_NUMMERIC has no getter + public static final NbtType UUID = new NbtType<>(100, CompoundTag::getUUID) { + @Override + public boolean check(CompoundTag nbt, String key) { + return nbt.hasUUID(key); + } + }; + + private final int type; + private final BiFunction getter; + + public NbtType(int type, BiFunction getter) { + this.type = type; + this.getter = getter; + } + + public T get(CompoundTag nbt, String key) { + return this.getter.apply(nbt, key); + } + + public boolean check(CompoundTag nbt, String key) { + return nbt.contains(key, this.type); + } + +} diff --git a/src/main/java/limonblaze/originsclasses/util/NbtUtils.java b/src/main/java/limonblaze/originsclasses/util/NbtUtils.java new file mode 100644 index 0000000..47962d7 --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/NbtUtils.java @@ -0,0 +1,44 @@ +package limonblaze.originsclasses.util; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; + +import java.util.Optional; + +public class NbtUtils { + + public static final String ORIGINS_CLASSES = "OriginsClasses"; + public static final String ENCHANTER = "Enchanter"; + public static final String FOOD_BONUS = "FoodBonus"; + public static final String POTION_BONUS = "PotionBonus"; + + public static Optional getOriginsClassesData(ItemStack stack, String key, NbtType nbtType) { + return stack.hasTag() ? getOriginsClassesData(stack.getOrCreateTag(), key, nbtType) : Optional.empty(); + } + + public static T getOriginsClassesData(ItemStack stack, String key, NbtType nbtType, T defaultValue) { + return stack.hasTag() ? getOriginsClassesData(stack.getOrCreateTag(), key, nbtType, defaultValue) : defaultValue; + } + + public static Optional getOriginsClassesData(CompoundTag nbt, String key, NbtType nbtType) { + if(nbt.contains(ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { + CompoundTag ocNbt = nbt.getCompound(ORIGINS_CLASSES); + if(nbtType.check(ocNbt, key)) { + return Optional.of(nbtType.get(ocNbt, key)); + } + } + return Optional.empty(); + } + + public static T getOriginsClassesData(CompoundTag nbt, String key, NbtType nbtType, T defaultValue) { + if(nbt.contains(ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { + CompoundTag ocNbt = nbt.getCompound(ORIGINS_CLASSES); + if(nbtType.check(ocNbt, key)) { + return nbtType.get(ocNbt, key); + } + } + return defaultValue; + } + +} diff --git a/src/main/java/limonblaze/originsclasses/util/PowerUtil.java b/src/main/java/limonblaze/originsclasses/util/PowerUtil.java deleted file mode 100644 index 63eed2d..0000000 --- a/src/main/java/limonblaze/originsclasses/util/PowerUtil.java +++ /dev/null @@ -1,124 +0,0 @@ -package limonblaze.originsclasses.util; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.tags.BlockTags; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.block.state.BlockState; -import java.util.*; - -public class PowerUtil { - public static final String ORIGINS_CLASSES_ENCHANTER = "OriginsClassesEnchanter"; - public static final String ORIGINS_CLASSES = "OriginsClasses"; - public static final String FOOD_BONUS = "FoodBonus"; - public static final String POTION_BONUS = "PotionBonus"; - - public static int naturalRandFloor(double d, Random random) { - if(d > 0) { - int i = (int) d; - return random.nextDouble() < d - i ? i + 1 : i; - } - return 0; - } - - public static double yawDiff(Entity actor, Entity target) { - float yawTarget = target.getYRot(); - while(yawTarget < 0F) yawTarget += 360F; - yawTarget %= 360F; - - float yawSelf = actor.getYRot(); - while(yawSelf < 0F) yawSelf += 360F; - yawSelf %= 360F; - - return Math.abs(yawTarget - yawSelf); - } - - public static byte getPotionBonus(ItemStack stack) { - if(stack.hasTag()) return getPotionBonus(stack.getTag()); - return -1; - } - - public static byte getPotionBonus(@Nullable CompoundTag nbt) { - if(nbt != null && nbt.contains(ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { - CompoundTag ocNbt = nbt.getCompound(ORIGINS_CLASSES); - if(ocNbt.contains(POTION_BONUS, Tag.TAG_BYTE)) { - return ocNbt.getByte(POTION_BONUS); - } - } - return -1; - } - - public static ItemStack setPotionBonus(ItemStack stack, byte bonus) { - stack.getOrCreateTagElement(ORIGINS_CLASSES).putByte(POTION_BONUS, bonus); - return stack; - } - - public static CompoundTag setPotionBonus(CompoundTag tag, byte bonus) { - if(tag.contains(ORIGINS_CLASSES, Tag.TAG_COMPOUND)) { - tag.getCompound(ORIGINS_CLASSES).putByte(POTION_BONUS, bonus); - } - return tag; - } - - public static MobEffectInstance applyPotionBonus(MobEffectInstance effect, byte bonusLevel) { - boolean instant = effect.getEffect().isInstantenous(); - return new MobEffectInstance( - effect.getEffect(), - instant ? effect.getDuration() : effect.getDuration() * (1 + bonusLevel), - instant ? effect.getAmplifier() + bonusLevel : effect.getAmplifier(), - effect.isAmbient(), - effect.isVisible(), - effect.showIcon() - ); - } - - public static @Nonnull List lumberjackMiner(Player player, BlockState state, BlockPos pos) { - Set affected = new HashSet<>(); - Queue queue = new LinkedList<>(); - queue.add(pos); - boolean foundOneWithLeaves = false; - BlockPos.MutableBlockPos pos$mutable = pos.mutable(); - BlockPos.MutableBlockPos newPos$mutable = pos.mutable(); - while(!queue.isEmpty()) { - pos$mutable.set(queue.remove()); - for(int dx = -1; dx <= 1; dx++) { - for(int dy = 0; dy <= 1; dy++) { - for(int dz = -1; dz <= 1; dz++) { - if(dx == 0 & dy == 0 && dz == 0) { - continue; - } - newPos$mutable.set(pos$mutable.getX() + dx, pos$mutable.getY() + dy, pos$mutable.getZ() + dz); - BlockState newState = player.level.getBlockState(newPos$mutable); - if(newState.is(state.getBlock()) && !affected.contains(newPos$mutable)) { - BlockPos savedNewPos = newPos$mutable.immutable(); - affected.add(savedNewPos); - queue.add(savedNewPos); - if(affected.size() > 255) { - if(!foundOneWithLeaves) { - return new ArrayList<>(); - } - return new ArrayList<>(affected); - } - } else - if((BlockTags.LEAVES.contains(newState.getBlock()) || newState.getBlock() instanceof LeavesBlock) && !newState.getValue(LeavesBlock.PERSISTENT)) { - foundOneWithLeaves = true; - } - } - } - } - } - if(!foundOneWithLeaves) { - affected.clear(); - } - return new ArrayList<>(affected); - } - -} diff --git a/src/main/java/limonblaze/originsclasses/util/package-info.java b/src/main/java/limonblaze/originsclasses/util/package-info.java new file mode 100644 index 0000000..c7bc15d --- /dev/null +++ b/src/main/java/limonblaze/originsclasses/util/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +package limonblaze.originsclasses.util; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/resources/data/origins_classes/origins/cleric.json b/src/main/resources/data/origins_classes/origins/cleric.json index f2930c3..06d76fd 100644 --- a/src/main/resources/data/origins_classes/origins/cleric.json +++ b/src/main/resources/data/origins_classes/origins/cleric.json @@ -3,7 +3,7 @@ "origins_classes:potion_bonus", "origins_classes:better_enchanting" ], - "icon": "minecraft:potion", + "icon": "minecraft:experience_bottle", "order": 7, "impact": 0 } \ No newline at end of file diff --git a/src/main/resources/origins_classes.mixins.json b/src/main/resources/origins_classes.mixins.json index 9a0816c..1b23361 100644 --- a/src/main/resources/origins_classes.mixins.json +++ b/src/main/resources/origins_classes.mixins.json @@ -21,12 +21,14 @@ "ServerPlayerGameModeMixin", "TippedArrowRecipeMixin", "accessor.LivingEntityAccessor", - "accessor.LootTableAccessor" + "accessor.LootTableAccessor", + "compat.apotheosis.ApotheosisEnchantmentMenuMixin" ], "client": [ "client.ClientSideMerchantMixin", "client.LocalPlayerMixin" ], + "plugin": "limonblaze.originsclasses.compat.OriginsClassesCompat", "refmap": "origins_classes.refmap.json", "injectors": { "defaultRequire": 1