Skip to content

Commit

Permalink
feat(critereon): frozen predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Jan 20, 2025
1 parent f3daf1a commit b2c499f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2025 AUIOC.ORG
*
* This file is part of ArnicaLib, a mod made for Minecraft.
*
* ArnicaLib is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.auioc.mcmod.arnicalib.game.critereon;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.advancements.critereon.EntitySubPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

public record FrozenPredicate(MinMaxBounds.Ints ticks, MinMaxBounds.Doubles percent) implements EntitySubPredicate {

public static final MapCodec<FrozenPredicate> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
MinMaxBounds.Ints.CODEC.optionalFieldOf("ticks", MinMaxBounds.Ints.ANY).forGetter(o -> o.ticks),
MinMaxBounds.Doubles.CODEC.optionalFieldOf("percent", MinMaxBounds.Doubles.ANY).forGetter(o -> o.percent)
).apply(instance, FrozenPredicate::new)
);

@Override
public MapCodec<? extends EntitySubPredicate> codec() { return CODEC; }

@Override
public boolean matches(Entity entity, ServerLevel level, @Nullable Vec3 position) {
if (!ticks.matches(entity.getTicksFrozen())) {
return false;
}
if (!percent.matches(entity.getPercentFrozen())) {
return false;
}
return true;
}

// ============================================================================================================== //

public static FrozenPredicate ticks(MinMaxBounds.Ints value) {
return new FrozenPredicate(value, MinMaxBounds.Doubles.ANY);
}

public static FrozenPredicate percent(MinMaxBounds.Doubles value) {
return new FrozenPredicate(MinMaxBounds.Ints.ANY, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.common.NeoForge;
import org.auioc.mcmod.arnicalib.ArnicaLib;
import org.auioc.mcmod.arnicalib.mod.critereon.AHEntitySubPredicates;
import org.auioc.mcmod.arnicalib.mod.registry.AHLevelBasedValues;
import org.auioc.mcmod.arnicalib.mod.registry.AHLootItemConditions;

Expand All @@ -45,6 +46,7 @@ public static void init() {
private static void modSetup() {
AHLootItemConditions.TYPES.register(modEventBus);
AHLevelBasedValues.TYPES.register(modEventBus);
AHEntitySubPredicates.CODECS.register(modEventBus);
// AHGlobalLootModifiers.GLOBAL_LOOT_MODIFIERS.register(modEventBus);
// AHLootItemFunctions.LOOT_FUNCTION_TYPES.register(modEventBus);
// HTags.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2025 AUIOC.ORG
*
* This file is part of ArnicaLib, a mod made for Minecraft.
*
* ArnicaLib is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.auioc.mcmod.arnicalib.mod.critereon;

import com.mojang.serialization.MapCodec;
import net.minecraft.advancements.critereon.EntitySubPredicate;
import net.minecraft.core.registries.BuiltInRegistries;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.auioc.mcmod.arnicalib.ArnicaLib;
import org.auioc.mcmod.arnicalib.game.critereon.FrozenPredicate;

public class AHEntitySubPredicates {

public static final DeferredRegister<MapCodec<? extends EntitySubPredicate>> CODECS = DeferredRegister.create(BuiltInRegistries.ENTITY_SUB_PREDICATE_TYPE, ArnicaLib.MOD_ID);

public static final DeferredHolder<MapCodec<? extends EntitySubPredicate>, MapCodec<FrozenPredicate>> FROZEN = CODECS.register("frozen", () -> FrozenPredicate.CODEC);

}

0 comments on commit b2c499f

Please sign in to comment.