Skip to content

Commit

Permalink
v1.5.2
Browse files Browse the repository at this point in the history
Improve how we get item damage for an `ItemStack`
  • Loading branch information
D-Cysteine committed Apr 27, 2023
1 parent 9f0fd95 commit a9770f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neiCustomDiagramVersion=1.5.1
neiCustomDiagramVersion=1.5.2

minecraftVersion=1.7.10
forgeVersion=10.13.4.1614
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.dcysteine.neicustomdiagram.main.config.ConfigOptions;
import com.google.auto.value.AutoValue;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -26,6 +27,17 @@ public abstract class ItemComponent implements Component {

public static final int DEFAULT_STACK_SIZE = 1;

/**
* Helper method for retrieving the raw item damage of an {@code ItemStack}.
*
* <p>This method is better than calling {@link ItemStack#getItemDamage()}, because that method
* could be overridden with a custom implementation of {@link Item#getDamage(ItemStack)} and
* therefore not actually return the raw item damage.
*/
public static int getItemDamage(ItemStack itemStack) {
return Items.feather.getDamage(itemStack);
}

public static ItemComponent create(Item item, int damage, Optional<NBTTagCompound> nbt) {
if (item.isDamageable()) {
return new AutoValue_ItemComponent(item, 0, nbt.map(ImmutableNbtWrapper::create));
Expand All @@ -40,17 +52,17 @@ public static ItemComponent create(Item item, int damage) {

/** NBT will be discarded. Use {@link #createWithNbt(ItemStack)} if you want NBT. */
public static ItemComponent create(ItemStack itemStack) {
return create(itemStack.getItem(), itemStack.getItemDamage());
return create(itemStack.getItem(), getItemDamage(itemStack));
}

public static ItemComponent createWithNbt(ItemStack itemStack) {
return create(
itemStack.getItem(), itemStack.getItemDamage(),
itemStack.getItem(), getItemDamage(itemStack),
Optional.ofNullable(itemStack.stackTagCompound));
}

public static ItemComponent createWithNbt(ItemStack itemStack, NBTTagCompound nbt) {
return create(itemStack.getItem(), itemStack.getItemDamage(), Optional.of(nbt));
return create(itemStack.getItem(), getItemDamage(itemStack), Optional.of(nbt));
}

public static Optional<ItemComponent> create(Block block, int damage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void initialize() {
for (ItemList item : HEATING_COILS) {
ItemStack itemStack = item.get(1);
long heat =
GT_Block_Casings5.getCoilHeatFromDamage(itemStack.getItemDamage()).getHeat();
GT_Block_Casings5
.getCoilHeatFromDamage(ItemComponent.getItemDamage(itemStack))
.getHeat();

builder.put(heat, ItemComponent.create(itemStack));
}
Expand Down

0 comments on commit a9770f0

Please sign in to comment.