Skip to content

Commit

Permalink
Implement tags for holdable armor
Browse files Browse the repository at this point in the history
Will be used for shields shortly, and eventually staffs
Holdable armor triggers most modifier hooks as if it were worn armor, but only triggers counterattack when blocking (making counterattack shield exclusive)
  • Loading branch information
KnightMiner committed Jan 30, 2023
1 parent b0c5c39 commit f0e36d0
Show file tree
Hide file tree
Showing 33 changed files with 201 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"tools": {
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
"slots": {
"defense": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
"slots": {
"defense": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
"slots": {
"defense": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"tag": "tconstruct:modifiable/harvest"
},
{
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
}
],
"slots": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"tag": "tconstruct:modifiable/melee"
},
{
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"type": "tconstruct:modifier_salvage",
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"tools": {
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
"slots": {
"upgrades": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
"item": "tconstruct:sky_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
"item": "tconstruct:ichor_slime"
}
],
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"tag": "tconstruct:modifiable/melee"
},
{
"tag": "tconstruct:modifiable/armor"
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
},
"amount_per_item": 1,
"needed_per_level": 25,
"tools": {
"tag": "tconstruct:modifiable/armor"
},
"tools": [
{
"tag": "tconstruct:modifiable/armor/worn"
},
{
"tag": "tconstruct:modifiable/shields"
}
],
"slots": {
"upgrades": 1
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"replace": false,
"values": [
"#tconstruct:modifiable/armor/boots",
"#tconstruct:modifiable/armor/leggings",
"#tconstruct:modifiable/armor/chestplate",
"#tconstruct:modifiable/armor/helmets"
"#tconstruct:modifiable/armor/worn",
"#tconstruct:modifiable/armor/held"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"#tconstruct:modifiable/shields"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"replace": false,
"values": [
"#tconstruct:modifiable/armor/boots",
"#tconstruct:modifiable/armor/leggings",
"#tconstruct:modifiable/armor/chestplate",
"#tconstruct:modifiable/armor/helmets"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"replace": false,
"values": []
}
6 changes: 6 additions & 0 deletions src/main/java/slimeknights/tconstruct/common/TinkerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ private static void init() {}
public static final TagKey<Item> CHESTPLATES = tag("modifiable/armor/chestplate");
/** Modifiable items that are worn as helmets */
public static final TagKey<Item> HELMETS = tag("modifiable/armor/helmets");
/** Modifiable items that are worn on any of the main armor slots, likely is applicable for curio slots too */
public static final TagKey<Item> WORN_ARMOR = tag("modifiable/armor/worn");
/** Modifiable items that are held in either hand */
public static final TagKey<Item> HELD_ARMOR = tag("modifiable/armor/held");
/** Modifiable items that have innate shielding behavior */
public static final TagKey<Item> SHIELDS = tag("modifiable/shields");

/** Modifiable items that support ranged attacks. Items in this tag support {@link ToolStats#DRAW_SPEED}, {@link ToolStats#VELOCITY}, {@link ToolStats#PROJECTILE_DAMAGE} and {@link ToolStats#ACCURACY} */
public static final TagKey<Item> RANGED = tag("modifiable/ranged");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static slimeknights.tconstruct.common.TinkerTags.Items.HARVEST;
import static slimeknights.tconstruct.common.TinkerTags.Items.HARVEST_PRIMARY;
import static slimeknights.tconstruct.common.TinkerTags.Items.HELD;
import static slimeknights.tconstruct.common.TinkerTags.Items.HELD_ARMOR;
import static slimeknights.tconstruct.common.TinkerTags.Items.HELMETS;
import static slimeknights.tconstruct.common.TinkerTags.Items.INTERACTABLE;
import static slimeknights.tconstruct.common.TinkerTags.Items.INTERACTABLE_ARMOR;
Expand All @@ -65,10 +66,12 @@
import static slimeknights.tconstruct.common.TinkerTags.Items.MULTIPART_TOOL;
import static slimeknights.tconstruct.common.TinkerTags.Items.ONE_HANDED;
import static slimeknights.tconstruct.common.TinkerTags.Items.RANGED;
import static slimeknights.tconstruct.common.TinkerTags.Items.SHIELDS;
import static slimeknights.tconstruct.common.TinkerTags.Items.STONE_HARVEST;
import static slimeknights.tconstruct.common.TinkerTags.Items.SWORD;
import static slimeknights.tconstruct.common.TinkerTags.Items.TWO_HANDED;
import static slimeknights.tconstruct.common.TinkerTags.Items.UNARMED;
import static slimeknights.tconstruct.common.TinkerTags.Items.WORN_ARMOR;

@SuppressWarnings("unchecked")
public class ItemTagProvider extends ItemTagsProvider {
Expand Down Expand Up @@ -244,6 +247,9 @@ private void addTools() {
addArmorTags(TinkerTools.slimesuit, DURABILITY, EMBELLISHMENT_SLIME);
addToolTags(TinkerTools.slimesuit.get(ArmorSlotType.HELMET), MULTIPART_TOOL);

// shields
tag(SHIELDS);

// add tags to other tags
// harvest primary and stone harvest are both automatically harvest
this.tag(TinkerTags.Items.HARVEST).addTag(HARVEST_PRIMARY).addTag(STONE_HARVEST);
Expand All @@ -260,7 +266,9 @@ private void addTools() {
// left and right handed are held, but not armor
this.tag(HELD).addTags(INTERACTABLE_RIGHT, INTERACTABLE_LEFT);
this.tag(INTERACTABLE).addTags(INTERACTABLE_LEFT, INTERACTABLE_RIGHT, INTERACTABLE_ARMOR);
this.tag(ARMOR).addTag(BOOTS).addTag(LEGGINGS).addTag(CHESTPLATES).addTag(HELMETS);
this.tag(WORN_ARMOR).addTags(BOOTS, LEGGINGS, CHESTPLATES, HELMETS);
this.tag(HELD_ARMOR).addTag(SHIELDS);
this.tag(ARMOR).addTags(WORN_ARMOR, HELD_ARMOR);
this.tag(AOE).addTag(BOOTS); // boot walk modifiers
this.tag(RANGED).addTag(BOWS);
this.tag(BOWS).addTags(LONGBOWS, CROSSBOWS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import javax.annotation.Nullable;

/** Helper class to keep track the max modifier level in a modifier, floats and keeps track of max slot */
/** Helper class to keep track the max modifier level in a modifier, floats, keeps track of max slot, and tracks all 6 slots */
public class ModifierMaxLevel {
/** Level for each slot */
private final float[] levels = new float[4];
private final float[] levels = new float[6];
/** Max level across all slots */
@Getter
private float max = 0;
Expand All @@ -19,10 +19,10 @@ public class ModifierMaxLevel {

/** Sets the given value in the structure */
public void set(EquipmentSlot slot, float level) {
float oldLevel = levels[slot.getIndex()];
float oldLevel = levels[slot.getFilterFlag()];
if (level != oldLevel) {
// first, update level
levels[slot.getIndex()] = level;
levels[slot.getFilterFlag()] = level;
// if larger than max, new max
if (level >= max) {
max = level;
Expand All @@ -31,7 +31,7 @@ public void set(EquipmentSlot slot, float level) {
// if the old level was max, find new max
max = 0;
for (EquipmentSlot armorSlot : ModifiableArmorMaterial.ARMOR_SLOTS) {
float value = levels[armorSlot.getIndex()];
float value = levels[armorSlot.getFilterFlag()];
if (value > max) {
max = value;
maxSlot = armorSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import net.minecraft.world.entity.EquipmentSlot;

/** Helper class to keep track the max vanilla level in a modifier, ints */
/** Helper class to keep track the max vanilla level in a modifier, ints and only on four armor slots */
public class VanillaMaxLevel {
/** Level for each slot */
private final int[] levels = new int[4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability;
import slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial;
import slimeknights.tconstruct.library.tools.helper.ModifierUtil;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.tools.nbt.ToolStack;

Expand Down Expand Up @@ -53,8 +53,8 @@ public IToolStackView getToolInSlot(EquipmentSlot slotType) {

/** Checks if any of the armor items are modifiable */
public boolean hasModifiableArmor() {
for (EquipmentSlot slotType : ModifiableArmorMaterial.ARMOR_SLOTS) {
if (getToolInSlot(slotType) != null) {
for (EquipmentSlot slotType : EquipmentSlot.values()) {
if (ModifierUtil.validArmorSlot(entity, slotType) && getToolInSlot(slotType) != null) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ public static boolean hasUpgrades(ItemStack stack) {
return false;
}

/** Checks if the given slot may contain armor */
public static boolean validArmorSlot(LivingEntity living, EquipmentSlot slot) {
return slot.getType() == Type.ARMOR || living.getItemBySlot(slot).is(TinkerTags.Items.HELD_ARMOR);
}

/** Checks if the given slot may contain armor */
public static boolean validArmorSlot(IToolStackView tool, EquipmentSlot slot) {
return slot.getType() == Type.ARMOR || tool.hasTag(TinkerTags.Items.HELD_ARMOR);
}

/**
* Adds levels to the given key in entity modifier data for an armor modifier
* @param tool Tool instance
Expand All @@ -202,7 +212,7 @@ public static boolean hasUpgrades(ItemStack stack) {
* @param amount Amount to add
*/
public static void addTotalArmorModifierLevel(IToolStackView tool, EquipmentChangeContext context, TinkerDataKey<Integer> key, int amount, boolean allowBroken) {
if (context.getChangedSlot().getType() == Type.ARMOR && (allowBroken || !tool.isBroken())) {
if (validArmorSlot(tool, context.getChangedSlot()) && (allowBroken || !tool.isBroken())) {
context.getTinkerData().ifPresent(data -> {
int totalLevels = data.get(key, 0) + amount;
if (totalLevels <= 0) {
Expand Down Expand Up @@ -233,7 +243,7 @@ public static void addTotalArmorModifierLevel(IToolStackView tool, EquipmentChan
* @param amount Amount to add
*/
public static void addTotalArmorModifierFloat(IToolStackView tool, EquipmentChangeContext context, TinkerDataKey<Float> key, float amount) {
if (context.getChangedSlot().getType() == Type.ARMOR && !tool.isBroken()) {
if (validArmorSlot(tool, context.getChangedSlot()) && !tool.isBroken()) {
context.getTinkerData().ifPresent(data -> {
float totalLevels = data.get(key, 0f) + amount;
if (totalLevels <= 0.005f) {
Expand Down

0 comments on commit f0e36d0

Please sign in to comment.