diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java index 4a56e34e..6ecb9463 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java @@ -1,6 +1,5 @@ package com.minelittlepony.unicopia.entity; -import com.minelittlepony.unicopia.init.UItems; import com.minelittlepony.unicopia.tossable.ITossed; import com.minelittlepony.util.MagicalDamageSource; @@ -14,6 +13,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.network.play.server.SPacketChangeGameState; import net.minecraft.util.DamageSource; import net.minecraft.util.math.MathHelper; @@ -22,7 +24,11 @@ import net.minecraft.world.World; public class EntitySpear extends EntityArrow implements ITossed { - private int knockback; + private static final DataParameter ITEM = EntityDataManager + .createKey(EntitySpear.class, DataSerializers.ITEM_STACK); + + private static final DataParameter KNOCKBACK = EntityDataManager + .createKey(EntitySpear.class, DataSerializers.VARINT); public EntitySpear(World world) { super(world); @@ -36,6 +42,13 @@ public class EntitySpear extends EntityArrow implements ITossed { super(world, shooter); } + @Override + protected void entityInit() { + super.entityInit(); + getDataManager().register(ITEM, ItemStack.EMPTY); + getDataManager().register(KNOCKBACK, 0); + } + @Override public void shoot(double x, double y, double z, float velocity, float inaccuracy) { @@ -54,7 +67,7 @@ public class EntitySpear extends EntityArrow implements ITossed { public void setKnockbackStrength(int amount) { super.setKnockbackStrength(amount); - knockback = amount; + getDataManager().set(KNOCKBACK, amount); } @Override @@ -83,6 +96,8 @@ public class EntitySpear extends EntityArrow implements ITossed { entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1); } + int knockback = getDataManager().get(KNOCKBACK); + if (knockback > 0) { float f1 = MathHelper.sqrt(motionX * motionX + motionZ * motionZ); @@ -121,12 +136,12 @@ public class EntitySpear extends EntityArrow implements ITossed { @Override protected ItemStack getArrowStack() { - return new ItemStack(UItems.spear); + return getDataManager().get(ITEM); } @Override public void setItem(ItemStack stack) { - + getDataManager().set(ITEM, new ItemStack(stack.getItem(), 1, stack.getMetadata())); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java b/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java index 6be6ee21..b9b7c8ff 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java @@ -9,7 +9,9 @@ import com.minelittlepony.unicopia.tossable.ITossed; import net.minecraft.block.state.IBlockState; import net.minecraft.dispenser.IPosition; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; @@ -24,21 +26,56 @@ public class ItemSpear extends Item implements ITossableItem { setFull3D(); setTranslationKey(name); setRegistryName(domain, name); + setMaxStackSize(1); + setMaxDamage(500); + } + + @Override + public EnumAction getItemUseAction(ItemStack stack) { + return EnumAction.BOW; + } + + @Override + public boolean isFull3D() { + return true; + } + + @Override + public int getMaxItemUseDuration(ItemStack stack) { + return 440; } @Override public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { - ItemStack itemstack = player.getHeldItem(hand); + if (!world.isRemote) { + ItemStack itemstack = player.getHeldItem(hand); - if (canBeThrown(itemstack)) { - toss(world, itemstack, player); + if (canBeThrown(itemstack)) { + player.setActiveHand(hand); + + return new ActionResult(EnumActionResult.SUCCESS, itemstack); + } - return new ActionResult(EnumActionResult.SUCCESS, itemstack); } return super.onItemRightClick(world, player, hand); } + @Override + public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityLivingBase entity, int timeLeft) { + if (entity instanceof EntityPlayer) { + + int i = getMaxItemUseDuration(itemstack) - timeLeft; + + if (i > 10) { + if (canBeThrown(itemstack)) { + itemstack.damageItem(1, entity); + toss(world, itemstack, (EntityPlayer)entity); + } + } + } + } + @Override public boolean isEnchantable(ItemStack stack) { return true; diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java index 776f8541..e3698aba 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java @@ -24,7 +24,7 @@ import net.minecraft.nbt.NBTTagCompound; @IMessage.Id(1) public class MsgPlayerCapabilities implements IMessage, IMessageHandler { @Expose - public Race newRace; + Race newRace; @Expose UUID senderId; diff --git a/src/main/java/com/minelittlepony/unicopia/tossable/ITossableItem.java b/src/main/java/com/minelittlepony/unicopia/tossable/ITossableItem.java index 496920df..ad4250f7 100644 --- a/src/main/java/com/minelittlepony/unicopia/tossable/ITossableItem.java +++ b/src/main/java/com/minelittlepony/unicopia/tossable/ITossableItem.java @@ -47,9 +47,6 @@ public interface ITossableItem extends ITossable, IDispensable { } default void toss(World world, ItemStack itemstack, EntityPlayer player) { - if (!player.capabilities.isCreativeMode) { - itemstack.shrink(1); - } world.playSound(null, player.posX, player.posY, player.posZ, getThrowSound(itemstack), SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F)); @@ -67,6 +64,10 @@ public interface ITossableItem extends ITossable, IDispensable { world.spawnEntity((Entity)projectile); } + if (!player.capabilities.isCreativeMode) { + itemstack.shrink(1); + } + player.addStat(StatList.getObjectUseStats(itemstack.getItem())); } diff --git a/src/main/resources/assets/unicopia/models/item/spear.json b/src/main/resources/assets/unicopia/models/item/spear.json new file mode 100644 index 00000000..5063676f --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/spear.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/handheld_staff", + "textures": { + "layer0": "unicopia:items/spear_wood" + } +} diff --git a/src/main/resources/assets/unicopia/textures/items/spear_wood.png b/src/main/resources/assets/unicopia/textures/items/spear_wood.png new file mode 100644 index 00000000..6405f3de Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/items/spear_wood.png differ