Skip to content

Commit

Permalink
Give slimes 4x armor and 4x protection
Browse files Browse the repository at this point in the history
Since they are just a head, they don't need to protect other parts of their body, so the helmet is more effective
  • Loading branch information
KnightMiner committed May 23, 2022
1 parent 0aadc85 commit 3f7a8a8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"#forge:slimes"
]
}
3 changes: 2 additions & 1 deletion src/main/java/slimeknights/tconstruct/common/TinkerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ private static void init() {}
public static final TagKey<EntityType<?>> KILLAGERS = tag("killagers");
/** Mobs that rarely spawn, boosts drop rate of severing */
public static final TagKey<EntityType<?>> RARE_MOBS = tag("rare_mobs");

/** Mobs that get the 4x protection boost due to only 1 armor piece */
public static final TagKey<EntityType<?>> SMALL_ARMOR = forgeTag("small_armor");

private static TagKey<EntityType<?>> tag(String name) {
return TagKey.create(Registry.ENTITY_TYPE_REGISTRY, TConstruct.getResource(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void addTags() {
this.tag(TinkerTags.EntityTypes.VILLAGERS).add(EntityType.VILLAGER, EntityType.WANDERING_TRADER, EntityType.ZOMBIE_VILLAGER);
this.tag(TinkerTags.EntityTypes.ILLAGERS).add(EntityType.EVOKER, EntityType.ILLUSIONER, EntityType.PILLAGER, EntityType.VINDICATOR, EntityType.WITCH);
this.tag(TinkerTags.EntityTypes.KILLAGERS).addTags(TinkerTags.EntityTypes.VILLAGERS, TinkerTags.EntityTypes.ILLAGERS).add(EntityType.IRON_GOLEM, EntityType.RAVAGER);

this.tag(TinkerTags.EntityTypes.SMALL_ARMOR).addTag(TinkerTags.EntityTypes.SLIMES);
}

@Override
Expand Down
46 changes: 27 additions & 19 deletions src/main/java/slimeknights/tconstruct/tools/logic/ToolEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import slimeknights.tconstruct.library.events.TinkerToolEvent.ToolHarvestEvent;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.dynamic.MobDisguiseModifier;
import slimeknights.tconstruct.library.modifiers.hooks.IArmorWalkModifier;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability;
import slimeknights.tconstruct.library.tools.capability.TinkerDataKeys;
Expand All @@ -57,7 +58,6 @@
import slimeknights.tconstruct.library.utils.BlockSideHitListener;
import slimeknights.tconstruct.tools.TinkerModifiers;
import slimeknights.tconstruct.tools.modifiers.defense.ProjectileProtectionModifier;
import slimeknights.tconstruct.library.modifiers.dynamic.MobDisguiseModifier;
import slimeknights.tconstruct.tools.modifiers.upgrades.armor.HasteArmorModifier;

import java.util.List;
Expand Down Expand Up @@ -266,29 +266,37 @@ static void livingHurt(LivingHurtEvent event) {

// determine if there is any modifiable armor, if not nothing to do
// TODO: shields should support this hook too, probably with a separate tag so holding armor does not count as a shield
EquipmentContext context = new EquipmentContext(entity);
if (!context.hasModifiableArmor()) {
return;
}

// first, fetch vanilla enchant level, assuming its not bypassed in vanilla
DamageSource source = event.getSource();
EquipmentContext context = new EquipmentContext(entity);
int vanillaModifier = 0;
if (!source.isBypassMagic()) {
vanillaModifier = EnchantmentHelper.getDamageProtection(entity.getArmorSlots(), source);
}

// next, determine how much tinkers armor wants to change it
// note that armor modifiers can choose to block "absolute damage" if they wish, currently just starving damage I think
float modifierValue = vanillaModifier;
float modifierValue = 0;
float originalDamage = event.getAmount();
for (EquipmentSlot slotType : ModifiableArmorMaterial.ARMOR_SLOTS) {
IToolStackView tool = context.getToolInSlot(slotType);
if (tool != null && !tool.isBroken()) {
for (ModifierEntry entry : tool.getModifierList()) {
modifierValue = entry.getModifier().getProtectionModifier(tool, entry.getLevel(), context, slotType, source, modifierValue);

// for our own armor, we have boosts from modifiers to consider
if (context.hasModifiableArmor()) {
// first, fetch vanilla enchant level, assuming its not bypassed in vanilla
if (!source.isBypassMagic()) {
modifierValue = vanillaModifier = EnchantmentHelper.getDamageProtection(entity.getArmorSlots(), source);
}

// next, determine how much tinkers armor wants to change it
// note that armor modifiers can choose to block "absolute damage" if they wish, currently just starving damage I think
for (EquipmentSlot slotType : ModifiableArmorMaterial.ARMOR_SLOTS) {
IToolStackView tool = context.getToolInSlot(slotType);
if (tool != null && !tool.isBroken()) {
for (ModifierEntry entry : tool.getModifierList()) {
modifierValue = entry.getModifier().getProtectionModifier(tool, entry.getLevel(), context, slotType, source, modifierValue);
}
}
}

// give slimes a 4x armor boost
if (entity.getType().is(TinkerTags.EntityTypes.SMALL_ARMOR)) {
modifierValue *= 4;
}
} else if (!source.isBypassMagic() && entity.getType().is(TinkerTags.EntityTypes.SMALL_ARMOR)) {
vanillaModifier = EnchantmentHelper.getDamageProtection(entity.getArmorSlots(), source);
modifierValue = vanillaModifier * 4;
}

// TODO: consider hook for modifiers to change damage directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.monster.Slime;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
Expand All @@ -24,6 +29,19 @@
public class ArmoredSlimeEntity extends Slime {
public ArmoredSlimeEntity(EntityType<? extends Slime> type, Level world) {
super(type, world);
if (!world.isClientSide) {
tryAddAttribute(Attributes.ARMOR, new AttributeModifier("tconstruct.small_armor_bonus", 3, Operation.MULTIPLY_TOTAL));
tryAddAttribute(Attributes.ARMOR_TOUGHNESS, new AttributeModifier("tconstruct.small_toughness_bonus", 3, Operation.MULTIPLY_TOTAL));
tryAddAttribute(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier("tconstruct.small_resistence_bonus", 3, Operation.MULTIPLY_TOTAL));
}
}

/** Adds an attribute if possible */
private void tryAddAttribute(Attribute attribute, AttributeModifier modifier) {
AttributeInstance instance = getAttribute(attribute);
if (instance != null) {
instance.addTransientModifier(modifier);
}
}

@Nullable
Expand Down

0 comments on commit 3f7a8a8

Please sign in to comment.