Skip to content

Commit

Permalink
Switch to switches.
Browse files Browse the repository at this point in the history
  • Loading branch information
IMB11 committed Jun 18, 2024
1 parent 56b90bd commit 5dc0863
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ public class ModItems {
// :::2

// :::1
// We can use generics (<T extends Item>), so we don't need to
// cast to an item when using this method.
public static <T extends Item> T register(T item, String id) {
public static Item register(Item item, String id) {
// Create the identifier for the item.
Identifier itemID = new Identifier(FabricDocsReference.MOD_ID, id);

// Register the item.
T registeredItem = Registry.register(Registries.ITEM, itemID, item);
Item registeredItem = Registry.register(Registries.ITEM, itemID, item);

// Return the registered item!
return registeredItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.ArmorMaterials;

Check failure on line 5 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

Unused import - net.minecraft.item.ArmorMaterials.
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
Expand All @@ -13,47 +14,34 @@ public class GuiditeArmorMaterial implements ArmorMaterial {
//:::1
// :::_10
public static final GuiditeArmorMaterial INSTANCE = new GuiditeArmorMaterial();
// :::_10
// :::1
// Base durability values for all the slots.
// Boots, Leggings, Chestplate, Helmet
// You shouldn't change these values.
private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};

// Protection values for all the slots.
// For reference, diamond uses 3 for boots, 6 for leggings, 8 for chestplate
// and 3 for helmet.
private static final int PROTECTION_BOOTS = 3;
private static final int PROTECTION_LEGGINGS = 6;
private static final int PROTECTION_CHESTPLATE = 8;
private static final int PROTECTION_HELMET = 3;

// Storing the protection and durability values in an array allows
// you to quickly get them by slot ID.
private static final int[] PROTECTION_VALUES = new int[] {
PROTECTION_BOOTS,
PROTECTION_LEGGINGS,
PROTECTION_CHESTPLATE,
PROTECTION_HELMET
};

// :::1
// :::_10
// :::2
@Override
public int getDurability(ArmorItem.Type type) {
// Replace X with a multiplier that you see fit!
// For reference, diamond uses a multiplier of 33, whilst
// leather uses 11.
return BASE_DURABILITY[type.getEquipmentSlot().getEntitySlotId()] * 33;
// Replace this multiplier by a constant value for the durability of the armor.
// For reference, diamond uses 33 for all armor pieces, whilst leather uses 5.
int DURABILITY_MULTIPLIER = 12;
return switch (type) {
case BOOTS -> 13 * DURABILITY_MULTIPLIER;

Check failure on line 26 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
case LEGGINGS -> 15 * DURABILITY_MULTIPLIER;

Check failure on line 27 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
case CHESTPLATE -> 16 * DURABILITY_MULTIPLIER;

Check failure on line 28 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
case HELMET -> 11 * DURABILITY_MULTIPLIER;

Check failure on line 29 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
};
}

// :::2
// :::3
@Override
public int getProtection(ArmorItem.Type type) {
// This will get the protection value for the slot from
// our array.
return PROTECTION_VALUES[type.getEquipmentSlot().getEntitySlotId()];
// Protection values for all the slots.
// For reference, diamond uses 3 for boots, 6 for leggings, 8 for chestplate, and 3 for helmet,
// whilst leather uses 1, 2, 3 and 1 respectively.
return switch (type) {
case BOOTS, HELMET -> 3;

Check failure on line 41 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
case LEGGINGS -> 6;

Check failure on line 42 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
case CHESTPLATE -> 8;

Check failure on line 43 in reference/latest/src/main/java/com/example/docs/item/armor/GuiditeArmorMaterial.java

View workflow job for this annotation

GitHub Actions / mod

'case' child has incorrect indentation level 24, expected level should be 16.
};
}

// :::3
Expand Down

0 comments on commit 5dc0863

Please sign in to comment.