このシリーズのまとめはこちら:
umagame.hatenablog.jp
どうも。
はじめに
今回はアイテムティアとアーマーマテリアルクラスの修正をするだけの記事です。
Enumを使ってなかったのがさすがに気持ち悪かったので。
ツール、防具の記事はこちら:
umagame.hatenablog.jp
umagame.hatenablog.jp
アイテムティア
ツールの記事のときに作ったアイテムティアのクラス(ItemTierDirt.java)を消して、新しくinitにクラスを作ります。
Enumを使って作ります。
package com.umagame.dirtmod.init;
import com.umagame.dirtmod.block.BlockSuperCompressedDirt;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ItemTier;
import net.minecraft.item.crafting.Ingredient;
public enum DirtModItemTiers implements IItemTier {
DIRT(ItemTier.IRON.getHarvestLevel(),
ItemTier.STONE.getMaxUses(),
ItemTier.IRON.getEfficiency(),
ItemTier.STONE.getAttackDamage(),
ItemTier.IRON.getEnchantability(),
Ingredient.fromItems(new BlockSuperCompressedDirt().asItem()));
private final int harvestLevel;
private final int maxUses;
private final float efficiency;
private final float attackDamage;
private final int enchantability;
private final Ingredient repairMaterial;
DirtModItemTiers(int harvestLevel, int maxUses, float efficiency, float attackDamage, int enchantability, Ingredient repairMaterial) {
this.harvestLevel = harvestLevel;
this.maxUses = maxUses;
this.efficiency = efficiency;
this.attackDamage = attackDamage;
this.enchantability = enchantability;
this.repairMaterial = repairMaterial;
}
@Override
public int getHarvestLevel() {
return harvestLevel;
}
@Override
public int getMaxUses() {
return maxUses;
}
@Override
public float getEfficiency() {
return efficiency;
}
@Override
public float getAttackDamage() {
return attackDamage;
}
@Override
public int getEnchantability() {
return enchantability;
}
@Override
public Ingredient getRepairMaterial() {
return repairMaterial;
}
}
そして、もともとnew ItemTierDirt()と書いていた部分を直します。
package com.umagame.dirtmod.item.tool;
import com.umagame.dirtmod.init.DirtModItemTiers;
import com.umagame.dirtmod.main.DirtMod;
import net.minecraft.item.AxeItem;
public class ItemDirtAxe extends AxeItem{
public ItemDirtAxe() {
super(DirtModItemTiers.DIRT,7,-3.2F,new Properties().group(DirtMod.DIRTMOD_TAB));
this.setRegistryName("dirt_axe");
}
}
これでOKです。
アーマーマテリアル
アーマーマテリアルの方も同様に修正します。
package com.umagame.dirtmod.init;
import com.umagame.dirtmod.block.BlockSuperCompressedDirt;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public enum DirtModArmorMaterials implements IArmorMaterial{
DIRT("dirtmod:dirt",
15,
new int[] {1,4,5,2},
ArmorMaterial.IRON.getEnchantability(),
SoundEvents.ITEM_ARMOR_EQUIP_LEATHER,
ArmorMaterial.CHAIN.getToughness(),
Ingredient.fromItems(new BlockSuperCompressedDirt().asItem()));
private static final int[] MAX_DAMAGE_ARRAY = new int[]{13, 15, 16, 11};
private final String name;
private final int maxDamageFactor;
private final int[] damageReductionAmountArray;
private final int enchantability;
private final SoundEvent soundEvent;
private final float toughness;
private final Ingredient repairMaterial;
private DirtModArmorMaterials(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountsIn, int enchantabilityIn, SoundEvent equipSoundIn, float p_i48533_8_, Ingredient repairMaterial) {
this.name = nameIn;
this.maxDamageFactor = maxDamageFactorIn;
this.damageReductionAmountArray = damageReductionAmountsIn;
this.enchantability = enchantabilityIn;
this.soundEvent = equipSoundIn;
this.toughness = p_i48533_8_;
this.repairMaterial = repairMaterial;
}
public int getDurability(EquipmentSlotType slotIn) {
return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
}
public int getDamageReductionAmount(EquipmentSlotType slotIn) {
return this.damageReductionAmountArray[slotIn.getIndex()];
}
public int getEnchantability() {
return this.enchantability;
}
public SoundEvent getSoundEvent() {
return this.soundEvent;
}
public Ingredient getRepairMaterial() {
return this.repairMaterial;
}
@OnlyIn(Dist.CLIENT)
public String getName() {
return this.name;
}
public float getToughness() {
return this.toughness;
}
}
package com.umagame.dirtmod.item.armor;
import com.umagame.dirtmod.init.DirtModArmorMaterials;
import com.umagame.dirtmod.main.DirtMod;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
public class ItemDirtHelmet extends ArmorItem{
public ItemDirtHelmet() {
super(DirtModArmorMaterials.DIRT,EquipmentSlotType.HEAD,new Properties().group(DirtMod.DIRTMOD_TAB));
this.setRegistryName("dirt_helmet");
}
}
これでOKです。
さいごに
次回の番外編は未定です。
銃の作り方とかやるかも。
Mod制作自体モチベ下がってきてるので、更新頻度は下がります。申し訳ない。