Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coyote enchantment #4

Open
wants to merge 1 commit into
base: 1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import house.greenhouse.enchiridion.Enchiridion;
import house.greenhouse.enchiridion.access.EntityPostEntityDropParamsAccess;
import house.greenhouse.enchiridion.access.EntityRidingEffectsAccess;
import house.greenhouse.enchiridion.enchantment.effects.DirectionalSprintEffect;
import house.greenhouse.enchiridion.enchantment.effects.RidingConditionalEffect;
import house.greenhouse.enchiridion.registry.EnchiridionAttributes;
import house.greenhouse.enchiridion.registry.EnchiridionEnchantmentEffectComponents;
Expand All @@ -17,7 +16,6 @@
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Unit;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.effect.MobEffectInstance;
Expand All @@ -33,18 +31,19 @@
import net.minecraft.world.item.enchantment.TargetedConditionalEffect;
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
import net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -71,6 +70,8 @@ public abstract class Mixin_LivingEntity extends Entity implements EntityPostEnt

@Shadow public abstract boolean hurt(DamageSource source, float amount);

private int enchiridion$airTime;

@Unique
private static LootParams.Builder enchiridion$builder;

Expand Down Expand Up @@ -280,4 +281,27 @@ public Mixin_LivingEntity(EntityType<?> entityType, Level level) {
private float enchiridion$modifyFriction(float original) {
return (float) (original * getAttributeValue(EnchiridionAttributes.FRICTION_MULTIPLIER));
}

@Shadow
protected abstract ItemStack getLastArmorItem(EquipmentSlot slot);

@Inject(method = "tick", at = @At(value = "HEAD"))
private void enchiridion$setAirTime(CallbackInfo ci) {
if (getAttributeValue(EnchiridionAttributes.JUMP_EXTENSION_TIME) > 0) {
if (this.onGround()) enchiridion$airTime = 0;
else if (enchiridion$airTime > -1) enchiridion$airTime++;
}
}

@Inject(method = "jumpFromGround", at = @At(value = "HEAD"))
private void enchiridion$resetAirTime(CallbackInfo ci) {
enchiridion$airTime = -1;
}

@ModifyExpressionValue(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;onGround()Z"))
private boolean enchiridion$extendJumpTime(boolean original) {
Vec3 position = this.getPosition(0);
boolean longFall = this.level().getBlockState(this.level().clip(new ClipContext(position, position.add(0, -0.5, 0), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getBlockPos()).isAir();
return original || (longFall && enchiridion$airTime > -1 && enchiridion$airTime / 20 < getAttributeValue(EnchiridionAttributes.JUMP_EXTENSION_TIME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class EnchiridionAttributes {
public static final Holder<Attribute> FRICTION_MULTIPLIER = Registry.registerForHolder(BuiltInRegistries.ATTRIBUTE, Enchiridion.asResource("generic.slipperiness_multiplier"), new RangedAttribute("attribute.name.generic.friction_multiplier", 1.0F, 0.0F, 100.0F).setSyncable(true));
public static final Holder<Attribute> JUMP_EXTENSION_TIME = Registry.registerForHolder(BuiltInRegistries.ATTRIBUTE, Enchiridion.asResource("generic.jump_extension_time"), new RangedAttribute("attribute.name.generic.jump_extension_time", 0, 0, Integer.MAX_VALUE).setSyncable(true));

public static void registerAll() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@
import house.greenhouse.enchiridion.loot.condition.BlockParamsLootItemCondition;
import house.greenhouse.enchiridion.loot.condition.subpredicate.CollidingSubpredicate;
import house.greenhouse.enchiridion.loot.function.SplitToPlanksFunction;
import net.minecraft.advancements.critereon.BlockPredicate;
import net.minecraft.advancements.critereon.DamageSourcePredicate;
import net.minecraft.advancements.critereon.EntityFlagsPredicate;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.EntityTypePredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.LocationPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.MobEffectsPredicate;
import net.minecraft.advancements.critereon.MovementPredicate;
import net.minecraft.advancements.critereon.TagPredicate;
import net.minecraft.advancements.critereon.*;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
Expand Down Expand Up @@ -49,14 +39,7 @@
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentTarget;
import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.item.enchantment.effects.AddValue;
import net.minecraft.world.item.enchantment.effects.AllOf;
import net.minecraft.world.item.enchantment.effects.DamageEntity;
import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect;
import net.minecraft.world.item.enchantment.effects.Ignite;
import net.minecraft.world.item.enchantment.effects.MultiplyValue;
import net.minecraft.world.item.enchantment.effects.PlaySoundEffect;
import net.minecraft.world.item.enchantment.effects.SpawnParticlesEffect;
import net.minecraft.world.item.enchantment.effects.*;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.functions.EnchantWithLevelsFunction;
Expand Down Expand Up @@ -86,6 +69,7 @@ public class EnchiridionEnchantments {
public static final ResourceKey<Enchantment> REACH = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("reach"));
public static final ResourceKey<Enchantment> RELIABILITY = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("reliability"));
public static final ResourceKey<Enchantment> SPLITTING = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("splitting"));
public static final ResourceKey<Enchantment> COYOTE = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("coyote"));

public static final ResourceKey<Enchantment> ASHES_CURSE = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("ashes_curse"));
public static final ResourceKey<Enchantment> MURKY_WATERS_CURSE = ResourceKey.create(Registries.ENCHANTMENT, Enchiridion.asResource("murky_waters_curse"));
Expand Down Expand Up @@ -617,6 +601,21 @@ EnchiridionEnchantmentEffectComponents.PREVENT_HUNGER_CONSUMPTION, new PreventHu
),
BlockParamsLootItemCondition.block(BlockPredicate.Builder.block().of(EnchiridionTags.BlockTags.CAN_SPLIT))
).build(SPLITTING.location());
Enchantment coyote = Enchantment.enchantment(
Enchantment.definition(
footArmorEnchantable,
1,
2,
Enchantment.dynamicCost(10, 10),
Enchantment.dynamicCost(25, 10),
8,
EquipmentSlotGroup.FEET)
).exclusiveWith(speedEnhancingExclusiveSet
).withEffect(EnchantmentEffectComponents.ATTRIBUTES, new EnchantmentAttributeEffect(ResourceLocation.withDefaultNamespace("enchantment.coyote"),
EnchiridionAttributes.JUMP_EXTENSION_TIME,
LevelBasedValue.perLevel(3, 2),
AttributeModifier.Operation.ADD_VALUE)
).build(COYOTE.location());

context.register(ASHES_CURSE, ashesCurse);
context.register(BARDING, barding);
Expand All @@ -634,5 +633,6 @@ EnchiridionEnchantmentEffectComponents.PREVENT_HUNGER_CONSUMPTION, new PreventHu
context.register(REACH, reach);
context.register(RELIABILITY, reliability);
context.register(SPLITTING, splitting);
context.register(COYOTE, coyote);
}
}
4 changes: 4 additions & 0 deletions common/src/main/resources/assets/enchiridion/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"attribute.name.generic.jump_extension_time": "Coyote Time Seconds",

"enchiridion.expand_categories.message": "Hold shift to view categories.",
"enchiridion.enchantment.with_category": "%s%s%s",

Expand All @@ -18,6 +20,7 @@
"enchantment.enchiridion.reach": "Reach",
"enchantment.enchiridion.reliability": "Reliability",
"enchantment.enchiridion.splitting": "Splitting",
"enchantment.enchiridion.coyote": "Coyote",

"enchiridion.category.enchiridion.primary": "Primary",
"enchiridion.category.enchiridion.secondary": "Secondary",
Expand All @@ -41,6 +44,7 @@
"enchantment.enchiridion.reach.desc": "Increases block interaction range of the tool.",
"enchantment.enchiridion.reliability.desc": "Increases the enchantment quality and durability of fished up items.",
"enchantment.enchiridion.splitting.desc": "Splits cut oak logs into more planks than usual.",
"enchantment.enchiridion.coyote.desc": "Gives leeway for jumping after leaving the ground",

"subtitles.enchantment.enchiridion.flurry.bell": "Boots jingle",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.FishingHookPredicate;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.*;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceKey;
Expand All @@ -35,7 +31,8 @@
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.*;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.entries.NestedLootTable;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
Expand Down Expand Up @@ -167,7 +164,8 @@ protected void addTags(HolderLookup.Provider wrapperLookup) {
EnchiridionEnchantments.EXPERIENCED,
EnchiridionEnchantments.ICE_STRIKE,
EnchiridionEnchantments.REACH,
EnchiridionEnchantments.RELIABILITY
EnchiridionEnchantments.RELIABILITY,
EnchiridionEnchantments.COYOTE
);
getOrCreateTagBuilder(EnchantmentTags.TREASURE)
.add(
Expand Down Expand Up @@ -234,7 +232,8 @@ protected void addTags(HolderLookup.Provider wrapperLookup) {
EnchiridionEnchantments.DREDGE,
EnchiridionEnchantments.JOUSTING,
EnchiridionEnchantments.PROSPECTOR,
EnchiridionEnchantments.SPLITTING
EnchiridionEnchantments.SPLITTING,
EnchiridionEnchantments.COYOTE
);
getOrCreateTagBuilder(EnchiridionTags.EnchantmentTags.SECONDARY_CATEGORY)
.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,13 @@

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import house.greenhouse.enchiridion.registry.EnchiridionAttributes;
import house.greenhouse.enchiridion.registry.EnchiridionEnchantmentEffectComponents;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.ConditionalEffect;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
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.ModifyVariable;

import java.util.Optional;

@Mixin(LivingEntity.class)
public abstract class Mixin_LivingEntity extends Entity {
Expand All @@ -36,7 +18,8 @@ public Mixin_LivingEntity(EntityType<?> entityType, Level level) {

@ModifyReturnValue(method = "createLivingAttributes", at = @At("RETURN"))
private static AttributeSupplier.Builder enchiridion$addAttributesToLivingEntities(AttributeSupplier.Builder original) {
original.add(EnchiridionAttributes.FRICTION_MULTIPLIER);
original.add(EnchiridionAttributes.FRICTION_MULTIPLIER)
.add(EnchiridionAttributes.JUMP_EXTENSION_TIME);
return original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import net.neoforged.neoforge.event.TagsUpdatedEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeModificationEvent;
import net.neoforged.neoforge.event.entity.living.LivingGetProjectileEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
import net.neoforged.neoforge.event.village.VillagerTradesEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
Expand Down Expand Up @@ -157,8 +156,10 @@ public static void onPlayerTick(PlayerTickEvent.Post event) {
public static class ModEvents {
@SubscribeEvent
public static void modifyEntityAttributes(EntityAttributeModificationEvent event) {
for (EntityType<? extends LivingEntity> type : event.getTypes())
for (EntityType<? extends LivingEntity> type : event.getTypes()) {
event.add(type, EnchiridionAttributes.FRICTION_MULTIPLIER);
event.add(type, EnchiridionAttributes.JUMP_EXTENSION_TIME);
}
}

// Make sure that other creative mode items have been added first.
Expand Down