Skip to content

Commit

Permalink
Merge pull request #170 from sddsd2332/main
Browse files Browse the repository at this point in the history
Animate the electric bow (close #169 )
  • Loading branch information
maggi373 committed May 15, 2024
2 parents fbb3f9c + 5ec43f4 commit ab46b57
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
34 changes: 25 additions & 9 deletions src/main/java/mekanism/common/item/ItemElectricBow.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mekanism.common.item;

import io.netty.buffer.ByteBuf;
import java.util.List;
import javax.annotation.Nonnull;
import mekanism.api.EnumColor;
import mekanism.common.base.IItemNetwork;
import mekanism.common.util.ItemDataUtils;
Expand All @@ -16,24 +14,42 @@
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public class ItemElectricBow extends ItemEnergized implements IItemNetwork {

public ItemElectricBow() {
super(120000);
setFull3D();
this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
if (entityIn == null) {
return 0.0F;
}else {
return !(entityIn.getActiveItemStack().getItem() instanceof ItemElectricBow) ? 0.0F : (float) (stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F;
}
}
});
this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
}
});
}

@Override
Expand All @@ -45,7 +61,7 @@ public void addInformation(ItemStack itemstack, World world, List<String> list,

@Override
public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityLivingBase entityLiving, int itemUseCount) {
if (entityLiving instanceof EntityPlayer && getEnergy(itemstack) > 0) {
if (entityLiving instanceof EntityPlayer && getEnergy(itemstack) > 0) {
EntityPlayer player = (EntityPlayer) entityLiving;
boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemstack) > 0;
ItemStack ammo = findAmmo(player);
Expand Down Expand Up @@ -87,7 +103,7 @@ public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityLivingB
}

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

if (!noConsume) {
ammo.shrink(1);
Expand Down Expand Up @@ -166,4 +182,4 @@ public void handlePacketData(ItemStack stack, ByteBuf dataStream) {
setFireState(stack, state);
}
}
}
}
30 changes: 25 additions & 5 deletions src/main/resources/assets/mekanism/models/item/electricbow.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
{
"parent": "item/bow",
"textures": {
"layer0": "mekanism:items/ElectricBow"
"parent": "item/bow",
"textures": {
"layer0": "mekanism:items/ElectricBow"
},
"overrides": [
{
"predicate": {
"pulling": 1
},
"model": "mekanism:item/electricbow_pulling_0"
},
"overrides": []
{
"predicate": {
"pulling": 1,
"pull": 0.65
},
"model": "mekanism:item/electricbow_pulling_1"
},
{
"predicate": {
"pulling": 1,
"pull": 0.9
},
"model": "mekanism:item/electricbow_pulling_2"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parent": "item/bow",
"textures": {"layer0": "mekanism:items/electricbow_pulling_0"},
"overrides": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parent": "item/bow",
"textures": {"layer0": "mekanism:items/electricbow_pulling_1"},
"overrides": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parent": "item/bow",
"textures": {"layer0": "mekanism:items/electricbow_pulling_2"},
"overrides": []
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab46b57

Please sign in to comment.