Skip to content

Commit

Permalink
Completely Port to MC1.19.2, Origins 1.5.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondBlaze committed Aug 19, 2022
1 parent 8ab11c9 commit 145ad6c
Show file tree
Hide file tree
Showing 60 changed files with 455 additions and 579 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ org.gradle.daemon=false

# Mandatory Dependencies
caelus_version=3.0.0.6
calio_version=1.6.0.2
apoli_version=2.3.4.3
origins_version=1.5.0.5
calio_version=1.6.0.3
apoli_version=2.3.4.4
origins_version=1.5.0.6

# Compat Dependencies
farmersdelight_file=3916069
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 8 additions & 3 deletions src/main/java/dev/limonblaze/originsclasses/OriginsClasses.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.limonblaze.originsclasses;

import dev.limonblaze.originsclasses.client.OriginsClassesClient;
import dev.limonblaze.originsclasses.common.OriginsClassesCommon;
import dev.limonblaze.originsclasses.common.registry.OriginsClassesConditions;
import dev.limonblaze.originsclasses.common.registry.OriginsClassesPowers;
import dev.limonblaze.originsclasses.util.ClientConfig;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -19,7 +20,12 @@ public class OriginsClasses {
public static final String MODID = "origins_classes";
public static final String LEGACY_MODID = "origins-classes";
public static final Logger LOGGER = LogManager.getLogger();


@OnlyIn(Dist.CLIENT)
public static boolean INFINITE_TRADER;
@OnlyIn(Dist.CLIENT)
public static boolean MULTI_MINING;

public OriginsClasses() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.SPEC);
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
Expand All @@ -29,7 +35,6 @@ public OriginsClasses() {
OriginsClassesConditions.ITEM_CONDITIONS.register(modBus);
OriginsClassesPowers.POWER_FACTORIES.register(modBus);
modBus.addListener(OriginsClassesCommon::setup);
modBus.addListener(OriginsClassesClient::setup);
LOGGER.info("Origins:Classes " + ModLoadingContext.get().getActiveContainer().getModInfo().getVersion() + " has initialized. Time for work!");
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.limonblaze.originsclasses.common.event.ModifyCraftResultEvent;
import dev.limonblaze.originsclasses.util.OriginsClassesDataTypes;
import dev.limonblaze.originsclasses.common.calio.OriginsClassesDataTypes;
import io.github.edwinmindcraft.apoli.api.IDynamicFeatureConfiguration;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.limonblaze.originsclasses.common.event.ModifyCraftResultEvent;
import dev.limonblaze.originsclasses.util.OriginsClassesDataTypes;
import dev.limonblaze.originsclasses.common.calio.OriginsClassesDataTypes;
import io.github.edwinmindcraft.apoli.api.IDynamicFeatureConfiguration;
import io.github.edwinmindcraft.apoli.api.configuration.PowerReference;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBlockCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
import io.github.edwinmindcraft.calio.api.network.CalioCodecHelper;
import net.minecraft.core.Holder;

import java.util.Optional;

public record MultiMineConfiguration(float speedMultiplier,
Holder<ConfiguredBlockCondition<?, ?>> blockCondition,
public record MultiMineConfiguration(Holder<ConfiguredBlockCondition<?, ?>> blockCondition,
Holder<ConfiguredItemCondition<?, ?>> itemCondition,
Holder<ConfiguredEntityAction<?, ?>> entityAction) implements IDynamicFeatureConfiguration {

public static final Codec<MultiMineConfiguration> CODEC = RecordCodecBuilder.create(instance -> instance.group(
CalioCodecHelper.optionalField(Codec.FLOAT, "speed_multiplier")
.forGetter(x -> Optional.of(x.speedMultiplier)),
ConfiguredBlockCondition.optional("block_condition")
.forGetter(MultiMineConfiguration::blockCondition),
ConfiguredItemCondition.optional("item_condition")
.forGetter(MultiMineConfiguration::itemCondition),
ConfiguredEntityAction.optional("entity_action")
.forGetter(MultiMineConfiguration::entityAction)
).apply(instance, (sm, bc, ic, ea) -> new MultiMineConfiguration(sm.orElse(1.0F), bc, ic, ea)));
).apply(instance, MultiMineConfiguration::new));

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

import dev.limonblaze.originsclasses.util.MathUtils;
import dev.limonblaze.originsclasses.util.CommonUtils;
import io.github.edwinmindcraft.apoli.api.component.IPowerContainer;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityAction;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredBiEntityCondition;
Expand All @@ -18,7 +18,7 @@ public ModifyBreedingPower() {
}

public static int getBreedAmount(Player player, Animal actor, Animal target) {
return MathUtils.randomFloor(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BREEDING.get(), 1.0D,
return CommonUtils.rollInt(IPowerContainer.modify(player, OriginsClassesPowers.MODIFY_BREEDING.get(), 1.0D,
cp ->
cp.get().isActive(player) &&
ConfiguredBiEntityCondition.check(cp.get().getConfiguration().parentsCondition(), actor, target),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.limonblaze.originsclasses.common.apoli.power;

import dev.limonblaze.originsclasses.util.NbtUtils;
import dev.limonblaze.originsclasses.util.CommonUtils;
import io.github.edwinmindcraft.apoli.api.component.IPowerContainer;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
Expand Down Expand Up @@ -29,7 +29,7 @@ public static ItemStack modify(Player player, ItemStack stack, ModifyCraftResult
IPowerContainer.getPowers(player, OriginsClassesPowers.MODIFY_CRAFTED_FOOD.get()).stream()
.filter(cp -> check(cp.get(), player.level, stack, type))
.forEach(cp -> tag.add(StringTag.valueOf(cp.get().getConfiguration().modifyFoodPower().power().toString())));
if(!tag.isEmpty()) stack.getOrCreateTagElement(NbtUtils.ORIGINS_CLASSES).put(NbtUtils.MODIFY_FOOD_POWERS, tag);
if(!tag.isEmpty()) stack.getOrCreateTagElement(CommonUtils.ORIGINS_CLASSES).put(CommonUtils.MODIFY_FOOD_POWERS, tag);
return stack;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
package dev.limonblaze.originsclasses.common.apoli.power;

import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Pair;
import dev.limonblaze.originsclasses.util.MultiMineMode;
import dev.limonblaze.originsclasses.OriginsClasses;
import dev.limonblaze.originsclasses.common.apoli.configuration.MultiMineConfiguration;
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;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
import io.github.edwinmindcraft.apoli.api.power.factory.PowerFactory;
import io.github.edwinmindcraft.apoli.api.registry.ApoliRegistries;
import dev.limonblaze.originsclasses.client.OriginsClassesClient;
import dev.limonblaze.originsclasses.common.apoli.configuration.MultiMineConfiguration;
import dev.limonblaze.originsclasses.common.duck.SneakingStateSavingGameMode;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
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 ImmutableList<MultiMinePower> FACTORIES;
public final MultiMineMode miner;

public MultiMinePower(MultiMineMode miner) {
public final Range range;

public MultiMinePower(Range range) {
super(MultiMineConfiguration.CODEC);
this.miner = miner;
}

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;
this.range = range;
}

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

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())

public static List<BlockPos> apply(Player player, BlockPos pos, BlockState state) {
List<ConfiguredPower<MultiMineConfiguration, MultiMinePower>> cmmps = ApoliRegistries.POWER_FACTORY.get()
.getValues()
.stream()
.filter(pf -> pf instanceof MultiMinePower)
.flatMap(pf -> IPowerContainer.getPowers(player, (MultiMinePower) pf).stream())
.map(Holder::get)
.filter(cp -> shouldApply(cp, player, pos, state))
.toList();
OriginsClasses.LOGGER.debug(cmmps.size());
for(ConfiguredPower<MultiMineConfiguration, MultiMinePower> cmmp : cmmps) {
List<BlockPos> affectBlocks = cmmp.getFactory().miner.getAffectedBlocks(player, state, pos);
List<BlockPos> affectBlocks = cmmp.getFactory().range.getAffectedBlocks(player, state, pos);
if(affectBlocks.size() > 0) {
return Optional.of(new Pair<>(affectBlocks, cmmp.getConfiguration().speedMultiplier()));
return affectBlocks;
}
}
return Optional.empty();
return new ArrayList<>();
}

public static float modifyBreakingSpeed(float speed, Player player, BlockPos pos, BlockState state) {
boolean processMultimine;
if(player instanceof ServerPlayer sp) {
SneakingStateSavingGameMode sneakingState = (SneakingStateSavingGameMode)sp.gameMode;
processMultimine = !sneakingState.wasSneakingWhenBlockBreakingStarted();
} else {
processMultimine = OriginsClassesClient.MULTI_MINING;
}
return processMultimine ? speed * getResult(player, pos, state).map(Pair::getSecond).orElse(1.0F) : speed;

@FunctionalInterface
public interface Range {

List<BlockPos> getAffectedBlocks(Player player, BlockState state, BlockPos pos);

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.limonblaze.originsclasses.util;
package dev.limonblaze.originsclasses.common.calio;

import io.github.apace100.calio.data.SerializableDataType;
import dev.limonblaze.originsclasses.common.event.ModifyCraftResultEvent;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import dev.limonblaze.originsclasses.common.network.S2CInfiniteTrader;
import dev.limonblaze.originsclasses.common.registry.OriginsClassesPowers;
import dev.limonblaze.originsclasses.common.tag.OriginsClassesEntityTypeTags;
import dev.limonblaze.originsclasses.mixin.accessor.LivingEntityAccessor;
import dev.limonblaze.originsclasses.core.mixin.accessor.minecraft.LivingEntityAccessor;
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.MutableComponent;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
Expand Down Expand Up @@ -93,23 +93,25 @@ public static void onPotionGained(MobEffectEvent.Added event) {
//ModifyEnchantingLevel
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onEnchantmentLevel(EnchantmentLevelSetEvent event) {
NbtUtils.getOriginsClassesData(event.getItem(), NbtUtils.ENCHANTER, NbtType.UUID).ifPresent(uuid -> {
Player player = event.getLevel().getPlayerByUUID(uuid);
if(player != null) {
event.setEnchantLevel(Mth.floor(IPowerContainer.modify(
player,
OriginsClassesPowers.MODIFY_ENCHANTING_LEVEL.get(),
event.getEnchantLevel(),
cp -> cp.get().isActive(player)
)));
}
});
ItemStack stack = event.getItem();
if(!stack.hasTag()) return;
CompoundTag entry = CommonUtils.getOriginsClassesTag(stack.getTag());
if(!entry.contains(CommonUtils.ENCHANTER, Tag.TAG_INT_ARRAY)) return;
Player player = event.getLevel().getPlayerByUUID(entry.getUUID(CommonUtils.ENCHANTER));
if(player != null) {
event.setEnchantLevel(Mth.floor(IPowerContainer.modify(
player,
OriginsClassesPowers.MODIFY_ENCHANTING_LEVEL.get(),
event.getEnchantLevel(),
cp -> cp.get().isActive(player)
)));
}
}

//ModifyBoneMeal
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onBoneMeal(BonemealEvent event) {
int count = MathUtils.randomFloor(IPowerContainer.modify(
int count = CommonUtils.rollInt(IPowerContainer.modify(
event.getEntity(),
OriginsClassesPowers.MODIFY_BONE_MEAL.get(), 1.0D
), event.getEntity().getRandom());
Expand Down Expand Up @@ -148,7 +150,7 @@ public static void onInteractEntity(PlayerInteractEvent.EntityInteract event) {
public static void onLivingDrops(LivingDropsEvent event) {
if(event.getSource() instanceof EntityDamageSource eds && eds.getEntity() instanceof Player player) {
LivingEntity target = event.getEntity();
int amount = MathUtils.randomFloor(IPowerContainer.modify(
int amount = CommonUtils.rollInt(IPowerContainer.modify(
player,
OriginsClassesPowers.MODIFY_ENTITY_LOOT.get(), 1.0F,
cp -> cp.get().isActive(player) &&
Expand Down Expand Up @@ -178,6 +180,7 @@ public static void onTooltip(ItemTooltipEvent event) {
if(player == null) return;
ItemStack stack = event.getItemStack();
List<Component> tooltip = event.getToolTip();

if(ClientConfig.CONFIG.showModifyFoodTooltip.get() &&
stack.getFoodProperties(player) != null)
{
Expand All @@ -189,14 +192,15 @@ public static void onTooltip(ItemTooltipEvent event) {
foodModifiers.addAll(config.foodModifiers().entries());
saturationModifiers.addAll(config.saturationModifiers().entries());
});
foodModifiers.forEach(mod -> tooltip.add(ItemUtils.modifierTooltip(mod, FOOD_TRANSLATION_KEY)));
saturationModifiers.forEach(mod -> tooltip.add(ItemUtils.modifierTooltip(mod, SATURATION_MODIFIER_TRANSLATION_KEY)));
foodModifiers.forEach(mod -> tooltip.add(ClientUtils.modifierTooltip(mod, FOOD_TRANSLATION_KEY)));
saturationModifiers.forEach(mod -> tooltip.add(ClientUtils.modifierTooltip(mod, SATURATION_MODIFIER_TRANSLATION_KEY)));
}

if(ClientConfig.CONFIG.showPotionBonusTooltip.get() &&
(stack.getItem() instanceof PotionItem || stack.getItem() instanceof TippedArrowItem) &&
PotionUtils.hasPotionBonus(stack))
stack.hasTag() && ClericHelper.getPotionBonus(stack.getTag()))
{
tooltip.add(MutableComponent.create(new TranslatableContents(POTION_BONUS_TRANSLATION_KEY)).withStyle(ChatFormatting.BLUE));
tooltip.add(ClientUtils.translate(POTION_BONUS_TRANSLATION_KEY).withStyle(ChatFormatting.BLUE));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.limonblaze.originsclasses.common.network;

import dev.limonblaze.originsclasses.client.OriginsClassesClient;
import dev.limonblaze.originsclasses.OriginsClasses;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -21,7 +21,7 @@ public void encode(FriendlyByteBuf buf) {

@OnlyIn(Dist.CLIENT)
private void handleSync() {
OriginsClassesClient.INFINITE_TRADER = this.infiniteTrader;
OriginsClasses.INFINITE_TRADER = this.infiniteTrader;
}

public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
Expand Down
Loading

0 comments on commit 145ad6c

Please sign in to comment.