Skip to content

Commit

Permalink
Migrate blasting, hydraulic, lightspeed, maintained, and raging to JS…
Browse files Browse the repository at this point in the history
…ON modifiers
  • Loading branch information
KnightMiner committed Jan 11, 2024
1 parent 5fdcd60 commit b86f780
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"modules": [
{
"type": "tconstruct:conditional_mining_speed",
"blocks": "tconstruct:any",
"entity": "mantle:any",
"require_effective": true,
"percent": false,
"variables": {
"resistance": {
"type": "tconstruct:block",
"block_type": "tconstruct:blast_resistance",
"fallback": 3.0
}
},
"formula": [
3.0,
6.0,
"$resistance",
"-",
1.5,
"/",
"^",
10.0,
"min",
"$level",
"*",
"$multiplier",
"*",
"$speed",
"+"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"modules": [
{
"type": "tconstruct:conditional_mining_speed",
"blocks": "tconstruct:any",
"entity": "mantle:any",
"require_effective": true,
"percent": false,
"variables": {
"bonus": {
"type": "tconstruct:entity",
"entity_type": "tconstruct:conditional",
"condition_type": "tconstruct:eyes_in_water",
"if_true": {
"type": "tconstruct:conditional",
"condition_type": "tconstruct:has_enchantment",
"enchantment": "minecraft:aqua_affinity",
"if_true": 8.0,
"if_false": 40.0
},
"if_false": {
"type": "tconstruct:conditional",
"condition_type": "tconstruct:raining_at",
"if_true": 4.0,
"if_false": 0.0
},
"fallback": 8.0
}
},
"formula": [
"$multiplier",
"$bonus",
"*",
"$level",
"*",
"$speed",
"+"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"modules": [
{
"type": "tconstruct:conditional_mining_speed",
"blocks": "tconstruct:any",
"entity": "mantle:any",
"require_effective": true,
"percent": false,
"variables": {
"light": {
"type": "tconstruct:block_light",
"light_layer": "block",
"fallback": 15.0
}
},
"formula": [
3.0,
"$light",
5.0,
"-",
5.0,
"/",
"^",
"$level",
"*",
"$multiplier",
"*",
"$speed",
"+"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"modules": [
{
"type": "tconstruct:conditional_mining_speed",
"blocks": "tconstruct:any",
"entity": "mantle:any",
"require_effective": true,
"percent": false,
"variables": {
"durability": {
"type": "tconstruct:tool",
"tool_type": "tconstruct:current_durability"
},
"max_durability": {
"type": "tconstruct:tool",
"tool_type": "tconstruct:stat",
"stat": "tconstruct:durability"
}
},
"formula": [
"$max_durability",
0.5,
"*",
"duplicate",
"$durability",
"!-",
"non-negative",
"!/",
"$level",
"*",
6.0,
"*",
"$multiplier",
"*",
"$speed",
"+"
]
},
{
"type": "tconstruct:conditional_stat",
"stat": "tconstruct:velocity",
"entity": "mantle:any",
"percent": false,
"variables": {
"durability": {
"type": "tconstruct:tool",
"tool_type": "tconstruct:current_durability"
},
"max_durability": {
"type": "tconstruct:tool",
"tool_type": "tconstruct:stat",
"stat": "tconstruct:durability"
}
},
"formula": [
"$max_durability",
0.5,
"*",
"duplicate",
"$durability",
"!-",
"non-negative",
"!/",
"$level",
"*",
0.05,
"*",
"$multiplier",
"*",
"$value",
"+"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"modules": [
{
"type": "tconstruct:conditional_melee_damage",
"target": "mantle:any",
"percent": false,
"variables": {
"health": {
"type": "tconstruct:entity",
"entity_type": "tconstruct:health",
"which": "attacker",
"fallback": 0.0
},
"max_health": {
"type": "tconstruct:entity",
"entity_type": "tconstruct:attribute",
"attribute": "minecraft:generic.max_health",
"which": "attacker",
"fallback": 20.0
}
},
"formula": [
"$health",
10.0,
"$max_health",
"-",
"non-negative",
"+",
10.0,
"!-",
8.0,
"/",
"percent_clamp",
"$level",
"*",
4.0,
"*",
"$multiplier",
"*",
"$damage",
"+"
]
},
{
"type": "tconstruct:conditional_stat",
"stat": "tconstruct:draw_speed",
"entity": "mantle:any",
"percent": false,
"variables": {
"health": {
"type": "tconstruct:entity",
"entity_type": "tconstruct:health",
"fallback": 0.0
},
"max": {
"type": "tconstruct:entity",
"entity_type": "tconstruct:attribute",
"attribute": "minecraft:generic.max_health",
"fallback": 20.0
}
},
"formula": [
"$health",
10.0,
"$max",
"-",
"non-negative",
"+",
10.0,
"!-",
8.0,
"/",
"percent_clamp",
"$level",
"*",
0.25,
"*",
"$multiplier",
"*",
"$value",
"+"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package slimeknights.tconstruct.library.json.predicate.entity;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.predicate.IJsonPredicate;
import slimeknights.mantle.data.predicate.entity.LivingEntityPredicate;
import slimeknights.tconstruct.library.json.serializer.GenericRegistryEntrySerializer;

/**
* Predicate that checks if the given entity has the given enchantment on any of their equipment
*/
public record HasEnchantmentEntityPredicate(Enchantment enchantment) implements LivingEntityPredicate {
public static final IGenericLoader<HasEnchantmentEntityPredicate> LOADER = new GenericRegistryEntrySerializer<>("enchantment", ForgeRegistries.ENCHANTMENTS, HasEnchantmentEntityPredicate::new, HasEnchantmentEntityPredicate::enchantment);

@Override
public boolean matches(LivingEntity entity) {
return EnchantmentHelper.getEnchantmentLevel(enchantment, entity) > 0;
}

@Override
public IGenericLoader<? extends IJsonPredicate<LivingEntity>> getLoader() {
return LOADER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import java.util.function.Predicate;

/** Additional living predicates added by Tinkers, Mantle controls the loader we use these days */
public interface TinkerLivingEntityPredicate {

/** Entities that are in the air, notably does not count you as airborne if swimming, riding, or climbing */
LivingEntityPredicate AIRBORNE = simple(entity -> !entity.isOnGround() && !entity.onClimbable() && !entity.isInWater() && !entity.isPassenger());
/** Checks if the entity is on the ground */
Expand All @@ -21,6 +21,8 @@ public interface TinkerLivingEntityPredicate {
LivingEntityPredicate EYES_IN_WATER = simple(entity -> entity.wasEyeInWater);
/** Entities with feet in water */
LivingEntityPredicate FEET_IN_WATER = simple(Entity::isInWater);
/** Checks if the entity is being hit by rain at their location */
LivingEntityPredicate RAINING = simple(entity -> entity.level.isRainingAt(entity.blockPosition()));

private static LivingEntityPredicate simple(Predicate<LivingEntity> predicate) {
return SingletonLoader.singleton(loader -> new LivingEntityPredicate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
package slimeknights.tconstruct.library.json.variable.block;

import net.minecraft.util.ToFloatFunction;
import net.minecraft.world.level.block.state.BlockState;
import slimeknights.mantle.data.GenericLoaderRegistry;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.GenericLoaderRegistry.IHaveLoader;
import slimeknights.tconstruct.library.json.variable.VariableLoaderRegistry;
import slimeknights.tconstruct.library.json.variable.VariableLoaderRegistry.ConstantLoader;

import static slimeknights.mantle.data.GenericLoaderRegistry.SingletonLoader.singleton;

/** Variable that fetches a property from a block state */
public interface BlockVariable extends IHaveLoader<BlockVariable> {
GenericLoaderRegistry<BlockVariable> LOADER = new VariableLoaderRegistry<>(Constant.LOADER.constructor());

/** Gets a value from the given block state */
float getValue(BlockState state);



/* Singletons */

/** Creates a new singleton variable getter */
private static BlockVariable simple(ToFloatFunction<BlockState> getter) {
return singleton(loader -> new BlockVariable() {
@Override
public float getValue(BlockState state) {
return getter.apply(state);
}

@Override
public IGenericLoader<? extends BlockVariable> getLoader() {
return loader;
}
});
}

/** Gets the block's blast resistance */
BlockVariable BLAST_RESISTANCE = simple(state -> state.getBlock().getExplosionResistance());


/** Constant value instance for this object */
record Constant(float value) implements VariableLoaderRegistry.ConstantFloat, BlockVariable {
Expand Down

0 comments on commit b86f780

Please sign in to comment.