Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.
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 @@ -74,8 +74,8 @@ public class BMEntities
public static final RegistrySupplier<EntityType<StoneGolemEntity>> STONE_GOLEM = ENTITIES.register(BiomeMakeover.ID("stone_golem"), ()->TEntityTypeBuilder.of(StoneGolemEntity::new, MobCategory.MISC).sized(1.6F, 2.5F).clientTrackingRange(12).build());
public static final RegistrySupplier<EntityType<HelmitCrabEntity>> HELMIT_CRAB = ENTITIES.register(BiomeMakeover.ID("helmit_crab"), ()->TEntityTypeBuilder.of(HelmitCrabEntity::new, MobCategory.CREATURE).sized(0.825F, 0.5F).clientTrackingRange(12).build());


public static final RegistrySupplier<Attribute> ATT_PROJECTILE_RESISTANCE = ATTRIBUTES.register(BiomeMakeover.ID("projectile_resistance"), ()->new RangedAttribute("attribute.name.biomemakeover.projectile_resistance", 0.0D, 0.0D, 30.0D));
public static final Attribute ATT_PROJECTILE_RESISTANCE = new RangedAttribute("attribute.name.biomemakeover.projectile_resistance", 0.0D, 0.0D, 30.0D);
public static final RegistrySupplier<Attribute> ATT_PROJECTILE_RESISTANCE_SUPPLIER = ATTRIBUTES.register(BiomeMakeover.ID("projectile_resistance"), () -> ATT_PROJECTILE_RESISTANCE);

public static void init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public class BMItems

public static void init() {

BMEntities.ATT_PROJECTILE_RESISTANCE.listen(a->{
ArmorBuilder CLADDED_ARMOR_BUILDER = ArmorBuilder.create(CLADDED_MATERIAL).attribute("Armor Proj Res", BMEntities.ATT_PROJECTILE_RESISTANCE.get(), 1.5, AttributeModifier.Operation.ADDITION);
BMEntities.ATT_PROJECTILE_RESISTANCE_SUPPLIER.listen(a->{
ArmorBuilder CLADDED_ARMOR_BUILDER = ArmorBuilder.create(CLADDED_MATERIAL).attribute("Armor Proj Res", BMEntities.ATT_PROJECTILE_RESISTANCE_SUPPLIER.get(), 1.5, AttributeModifier.Operation.ADDITION);
Supplier<Item> CLADDED_HELMET = registerItem("cladded_helmet", CLADDED_ARMOR_BUILDER.build(ArmorItem.Type.HELMET, properties()));
Supplier<Item> CLADDED_CHESTPLATE = registerItem("cladded_chestplate", CLADDED_ARMOR_BUILDER.build(ArmorItem.Type.CHESTPLATE, properties()));
Supplier<Item> CLADDED_LEGGINGS = registerItem("cladded_leggings",CLADDED_ARMOR_BUILDER.build(ArmorItem.Type.LEGGINGS, properties()));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import org.jetbrains.annotations.Nullable;
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.CallbackInfoReturnable;
import party.lemons.biomemakeover.init.BMEntities;
import party.lemons.biomemakeover.util.EntityUtil;

@Mixin(LivingEntity.class)
public class LivingEntityMixin
public abstract class LivingEntityMixin
{
@Shadow @Nullable public abstract AttributeInstance getAttribute(Attribute attribute);

@Inject(at = @At("HEAD"), method = "hurt", cancellable = true)
private void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cbi)
{
Expand All @@ -19,4 +28,16 @@ private void onDamage(DamageSource source, float amount, CallbackInfoReturnable<
cbi.setReturnValue(true);
}
}

@ModifyVariable(method = "getDamageAfterMagicAbsorb", at = @At(value = "STORE", ordinal = 1))
private int applyProjectileResistance(int value)
{
return value + (int) Math.round(this.getAttribute(BMEntities.ATT_PROJECTILE_RESISTANCE).getValue());
}

@Inject(method = "createLivingAttributes", at = @At("RETURN"))
private static void addProjectileResistanceAttribute(CallbackInfoReturnable<AttributeSupplier.Builder> cir)
{
cir.getReturnValue().add(BMEntities.ATT_PROJECTILE_RESISTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
package party.lemons.biomemakeover.util;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.Containers;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.apache.commons.lang3.mutable.MutableInt;
import party.lemons.biomemakeover.init.BMEntities;
import party.lemons.biomemakeover.init.BMItems;

import java.util.Collection;

public final class EntityUtil
{
public static void applyProjectileResistance(Iterable<ItemStack> equipment, MutableInt resistance)
{
MutableInt slotIndex = new MutableInt(0);
equipment.forEach(e->{
if(!e.isEmpty())
{
EquipmentSlot slot = EquipmentSlot.values()[2 + slotIndex.getValue()];
if(e.getAttributeModifiers(slot).containsKey(BMEntities.ATT_PROJECTILE_RESISTANCE.get()))
{
Collection<AttributeModifier> modifiers = e.getAttributeModifiers(slot).get(BMEntities.ATT_PROJECTILE_RESISTANCE.get());
for(AttributeModifier mod : modifiers)
{
resistance.add(mod.getAmount());
}
}
}
slotIndex.add(1);
});
}

public static double getProjectileResistance(LivingEntity e)
{
double res = 0;
for(EquipmentSlot slot : EquipmentSlot.values())
{
ItemStack st = e.getItemBySlot(slot);
if(!st.isEmpty() && st.getAttributeModifiers(slot).containsKey(BMEntities.ATT_PROJECTILE_RESISTANCE.get()))
{
Collection<AttributeModifier> modifiers = st.getAttributeModifiers(slot).get(BMEntities.ATT_PROJECTILE_RESISTANCE.get());
for(AttributeModifier mod : modifiers)
{
res += mod.getAmount();
}
}
}
return res;
}

private EntityUtil()
{
Expand All @@ -69,7 +16,7 @@ private EntityUtil()
public static boolean attemptProjectileResistanceBlock(LivingEntity entity, DamageSource source)
{
if (source.is(DamageTypeTags.IS_PROJECTILE)) {
double protection = EntityUtil.getProjectileResistance(entity);
double protection = entity.getAttribute(BMEntities.ATT_PROJECTILE_RESISTANCE).getValue();
if (protection > 0D && (entity.getRandom().nextDouble() * 30D) < protection) {
entity.playSound(SoundEvents.SHIELD_BLOCK, 1F, 0.8F + entity.getRandom().nextFloat() * 0.4F);
return true;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/biomemakeover-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"CamelMixin",
"ComposterBlockMixin",
"DarkOakTreeGrowerMixin_SingleTree",
"EnchantmentHelperMixin",
"GoalSelectorMixin",
"InputContainerMixin_EctoCompost",
"LivingEntityMixin",
Expand Down