From e5cb2df0ce51557911ddeabf4a71cd623f256fbb Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 13 Aug 2019 09:16:22 +0200 Subject: [PATCH] More implementing spears --- .../unicopia/entity/EntitySpear.java | 25 ++++++++-- .../unicopia/item/ItemSpear.java | 45 ++++++++++++++++-- .../network/MsgPlayerCapabilities.java | 2 +- .../unicopia/tossable/ITossableItem.java | 7 +-- .../assets/unicopia/models/item/spear.json | 6 +++ .../unicopia/textures/items/spear_wood.png | Bin 0 -> 3199 bytes 6 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/assets/unicopia/models/item/spear.json create mode 100644 src/main/resources/assets/unicopia/textures/items/spear_wood.png 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 0000000000000000000000000000000000000000..6405f3decc97829a2a7d98d05005168543198c38 GIT binary patch literal 3199 zcmV-_41n{AP)uJ@VVD_UC<6{NG_fI~0ue<-1QkJoA_k0xBC#Thg@9ne9*`iQ#9$Or zQF$}6R&?d%y_c8YA7_1QpS|}zXYYO1x&V;8{kgn!SPFnNo`4_X6{c}T{8k*B#$jdxfFg<9uYy1K45IaYvHg`_dOZM)Sy63ve6hvv z1)yUy0P^?0*fb9UASvow`@mQCp^4`uNg&9uGcn1|&Nk+9SjOUl{-OWr@Hh0;_l(8q z{wNRKos+;6rV8ldy0Owz(}jF`W(JeRp&R{qi2rfmU!TJ;gp(Kmm5I1s5m_f-n#TRsj}B0%?E`vOzxB2#P=n*a3EfYETOrKoe*ICqM@{4K9Go;5xVgZi5G4 z1dM~{UdP6d+Yd3o?MrAqM0Kc|iV92owdyL5UC#5<>aVCa44|hpM4E zs0sQWIt5*Tu0n&*J!lk~f_{hI!w5`*sjxDv4V%CW*ah~3!{C*0BD@;TgA3v9a1~q+ zAA{TB3-ERLHar49hi4Ih5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