Skip to content

Commit

Permalink
Clean up tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 4, 2024
1 parent d096562 commit d6c77c2
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 78 deletions.
27 changes: 10 additions & 17 deletions src/main/java/com/progwml6/natura/tools/NaturaTools.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
package com.progwml6.natura.tools;

import org.apache.logging.log4j.Logger;

import com.google.common.eventbus.Subscribe;
import com.progwml6.natura.common.CommonProxy;
import com.progwml6.natura.common.NaturaPulse;
import com.progwml6.natura.library.Util;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.tools.item.armor.ItemNaturaImpArmor;
import com.progwml6.natura.tools.item.bows.ItemNaturaBow;
import com.progwml6.natura.tools.item.tools.ItemNaturaAxe;
import com.progwml6.natura.tools.item.tools.ItemNaturaFlintAndBlaze;
import com.progwml6.natura.tools.item.tools.ItemNaturaHoe;
import com.progwml6.natura.tools.item.tools.ItemNaturaPickaxe;
import com.progwml6.natura.tools.item.tools.ItemNaturaShears;
import com.progwml6.natura.tools.item.tools.ItemNaturaShovel;
import com.progwml6.natura.tools.item.tools.ItemNaturaSword;

import org.apache.logging.log4j.Logger;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
Expand All @@ -32,6 +17,14 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.registries.IForgeRegistry;

import com.progwml6.natura.common.CommonProxy;
import com.progwml6.natura.common.NaturaPulse;
import com.progwml6.natura.library.Util;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.tools.item.armor.ItemNaturaImpArmor;
import com.progwml6.natura.tools.item.bows.ItemNaturaBow;
import com.progwml6.natura.tools.item.tools.*;
import slimeknights.mantle.pulsar.pulse.Pulse;

@Pulse(id = NaturaTools.PulseId, description = "All of the tools + armor added by natura")
Expand Down Expand Up @@ -100,7 +93,7 @@ public void registerItems(Register<Item> event)

if (isEntitiesLoaded())
{
ArmorMaterial impMaterial = EnumHelper.addArmorMaterial("IMP_HIDE", "imp_hide", 12, new int[]{2, 4, 5, 2}, 18, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0);
ArmorMaterial impMaterial = EnumHelper.addArmorMaterial("IMP_HIDE", "imp_hide", 12, new int[] {2, 4, 5, 2}, 18, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0);

impHelmet = registerItem(registry, new ItemNaturaImpArmor(impMaterial, EntityEquipmentSlot.HEAD), "imp_armor_helmet");
impChestplate = registerItem(registry, new ItemNaturaImpArmor(impMaterial, EntityEquipmentSlot.CHEST), "imp_armor_chestplate");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/progwml6/natura/tools/ToolsClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools;

import com.progwml6.natura.common.ClientProxy;

import net.minecraft.item.ItemStack;

import com.progwml6.natura.common.ClientProxy;

public class ToolsClientProxy extends ClientProxy
{
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.progwml6.natura.tools.item.armor;

import com.progwml6.natura.tools.NaturaTools;
import javax.annotation.Nonnull;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
Expand All @@ -9,6 +9,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;

import com.progwml6.natura.tools.NaturaTools;

public class ItemNaturaImpArmor extends ItemArmor
{
public ItemNaturaImpArmor(ArmorMaterial armorMaterialIn, EntityEquipmentSlot equipmentSlotIn)
Expand All @@ -17,32 +19,32 @@ public ItemNaturaImpArmor(ArmorMaterial armorMaterialIn, EntityEquipmentSlot equ
}

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list)
public void getSubItems(@Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> list)
{
if (this.isInCreativeTab(tab))
{
switch (this.armorType)
{
case HEAD:
list.add(NaturaTools.impHelmetStack.copy());
break;
case CHEST:
list.add(NaturaTools.impChestplateStack.copy());
break;
case LEGS:
list.add(NaturaTools.impLeggingsStack.copy());
break;
case FEET:
list.add(NaturaTools.impBootsStack.copy());
break;
default:
break;
case HEAD:
list.add(NaturaTools.impHelmetStack.copy());
break;
case CHEST:
list.add(NaturaTools.impChestplateStack.copy());
break;
case LEGS:
list.add(NaturaTools.impLeggingsStack.copy());
break;
case FEET:
list.add(NaturaTools.impBootsStack.copy());
break;
default:
break;
}
}
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type)
public String getArmorTexture(@Nonnull ItemStack stack, @Nonnull Entity entity, @Nonnull EntityEquipmentSlot slot, @Nonnull String type)
{
return "natura:textures/armor/imp_armor" + (slot == EntityEquipmentSlot.LEGS ? "_legs" : "") + ".png";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.progwml6.natura.tools.item.bows;

import com.progwml6.natura.library.NaturaRegistry;
import javax.annotation.Nonnull;

import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
Expand All @@ -19,14 +19,18 @@
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;

public class ItemNaturaBow extends ItemBow {
public float damageMult;
public float velocityMult;
public float inaccuracy;
public float drawTimeMult;
public Ingredient repairMaterial;
import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaBow extends ItemBow
{
public final float damageMult;
public final float velocityMult;
public final float inaccuracy;
public final float drawTimeMult;
public final Ingredient repairMaterial;

public ItemNaturaBow(int durability, float damageMult, float velocityMult, float drawTimeMult, float inaccuracy, Ingredient repairMaterial) {
public ItemNaturaBow(int durability, float damageMult, float velocityMult, float drawTimeMult, float inaccuracy, Ingredient repairMaterial)
{
this.setCreativeTab(NaturaRegistry.tabGeneral);
this.maxStackSize = 1;
this.setMaxDamage(durability);
Expand All @@ -36,7 +40,8 @@ public ItemNaturaBow(int durability, float damageMult, float velocityMult, float
this.inaccuracy = inaccuracy;
this.repairMaterial = repairMaterial;
this.addPropertyOverride(new ResourceLocation("pull"), (ItemStack bow, World world, EntityLivingBase entity) -> {
if (entity == null) {
if (entity == null)
{
return 0.0F;
}

Expand All @@ -47,8 +52,10 @@ public ItemNaturaBow(int durability, float damageMult, float velocityMult, float
}

@Override
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingBase entityLiving, int timeInUse) {
if (entityLiving instanceof EntityPlayer) {
public void onPlayerStoppedUsing(@Nonnull ItemStack itemStack, @Nonnull World world, @Nonnull EntityLivingBase entityLiving, int timeInUse)
{
if (entityLiving instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entityLiving;
boolean isInfinityEnchant = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemStack) > 0;
ItemStack stack = this.findAmmo(player);
Expand All @@ -59,47 +66,56 @@ public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingB
charge = ForgeEventFactory.onArrowLoose(itemStack, world, player, charge, !stack.isEmpty() || isInfinityEnchant);
if (charge < 0) return;

if ((!stack.isEmpty() || isInfinityEnchant)) {
if (stack.isEmpty()) {
if ((!stack.isEmpty() || isInfinityEnchant))
{
if (stack.isEmpty())
{
stack = new ItemStack(Items.ARROW);
}

float arrowVelocity = getArrowVelocity(charge);

if ((double) arrowVelocity >= 0.1D) {
if (arrowVelocity >= 0.1D)
{
boolean arrowInfinite = player.capabilities.isCreativeMode || (stack.getItem() instanceof ItemArrow && ((ItemArrow) stack.getItem()).isInfinite(stack, itemStack, player));

if (!world.isRemote) {
if (!world.isRemote)
{
ItemArrow itemArrow = (ItemArrow) (stack.getItem() instanceof ItemArrow ? stack.getItem() : Items.ARROW);
EntityArrow entityArrow = itemArrow.createArrow(world, stack, player);
entityArrow = this.customizeArrow(entityArrow);
entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, (arrowVelocity * 3.0F) * velocityMult, inaccuracy);

if (arrowVelocity == 1.0F) {
if (arrowVelocity == 1.0F)
{
entityArrow.setIsCritical(true);
}

entityArrow.setDamage(entityArrow.getDamage() * damageMult);

int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemStack);

if (power > 0) {
entityArrow.setDamage(entityArrow.getDamage() + (double) power * 0.5D + 0.5D);
if (power > 0)
{
entityArrow.setDamage(entityArrow.getDamage() + power * 0.5D + 0.5D);
}

int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, itemStack);

if (punch > 0) {
if (punch > 0)
{
entityArrow.setKnockbackStrength(punch);
}

if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, itemStack) > 0) {
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, itemStack) > 0)
{
entityArrow.setFire(100);
}

itemStack.damageItem(1, player);

if (arrowInfinite || player.capabilities.isCreativeMode && (stack.getItem() == Items.SPECTRAL_ARROW || stack.getItem() == Items.TIPPED_ARROW)) {
if (arrowInfinite || player.capabilities.isCreativeMode && (stack.getItem() == Items.SPECTRAL_ARROW || stack.getItem() == Items.TIPPED_ARROW))
{
entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}

Expand All @@ -108,10 +124,12 @@ public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingB

world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + arrowVelocity * 0.5F);

if (!arrowInfinite && !player.capabilities.isCreativeMode) {
if (!arrowInfinite && !player.capabilities.isCreativeMode)
{
stack.shrink(1);

if (stack.isEmpty()) {
if (stack.isEmpty())
{
player.inventory.deleteStack(stack);
}
}
Expand All @@ -123,7 +141,8 @@ public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingB
}

@Override
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
public boolean getIsRepairable(@Nonnull ItemStack toRepair, @Nonnull ItemStack repair)
{
return repairMaterial.test(repair) || super.getIsRepairable(toRepair, repair);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;

import net.minecraft.item.ItemAxe;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaAxe extends ItemAxe
{
public ItemNaturaAxe(ToolMaterial material, float damage, float speed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;
import javax.annotation.Nonnull;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
Expand All @@ -14,6 +14,8 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaFlintAndBlaze extends Item
{
public ItemNaturaFlintAndBlaze()
Expand All @@ -26,8 +28,9 @@ public ItemNaturaFlintAndBlaze()
/**
* Called when a Block is right-clicked with this Item
*/
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
public EnumActionResult onItemUse(EntityPlayer player, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing facing, float hitX, float hitY, float hitZ)
{
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;

import net.minecraft.item.ItemHoe;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaHoe extends ItemHoe
{
public ItemNaturaHoe(ToolMaterial toolMaterialIn)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;

import net.minecraft.item.ItemPickaxe;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaPickaxe extends ItemPickaxe
{
public ItemNaturaPickaxe(ToolMaterial toolMaterialIn)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;
import javax.annotation.Nonnull;

import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaShears extends ItemShears
{
public Ingredient repairMaterial;
public final Ingredient repairMaterial;

public ItemNaturaShears(int durability, Ingredient repairMaterial)
{
this.maxStackSize = 1;
this.maxStackSize = 1;
this.repairMaterial = repairMaterial;
this.setMaxDamage(durability);
this.setCreativeTab(NaturaRegistry.tabGeneral);
}

@Override
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
public boolean getIsRepairable(@Nonnull ItemStack toRepair, @Nonnull ItemStack repair)
{
return repairMaterial.test(repair) || super.getIsRepairable(toRepair, repair);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;

import net.minecraft.item.ItemSpade;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaShovel extends ItemSpade
{
public ItemNaturaShovel(ToolMaterial toolMaterialIn)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.progwml6.natura.tools.item.tools;

import com.progwml6.natura.library.NaturaRegistry;

import net.minecraft.item.ItemSword;

import com.progwml6.natura.library.NaturaRegistry;

public class ItemNaturaSword extends ItemSword
{
public ItemNaturaSword(ToolMaterial toolMaterialIn)
Expand Down

0 comments on commit d6c77c2

Please sign in to comment.