mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
More implementing spears
This commit is contained in:
parent
0f2f148eec
commit
e5cb2df0ce
6 changed files with 72 additions and 13 deletions
|
@ -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<ItemStack> ITEM = EntityDataManager
|
||||
.createKey(EntitySpear.class, DataSerializers.ITEM_STACK);
|
||||
|
||||
private static final DataParameter<Integer> 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
|
||||
|
|
|
@ -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<ItemStack> 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<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(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;
|
||||
|
|
|
@ -24,7 +24,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
@IMessage.Id(1)
|
||||
public class MsgPlayerCapabilities implements IMessage, IMessageHandler<MsgPlayerCapabilities> {
|
||||
@Expose
|
||||
public Race newRace;
|
||||
Race newRace;
|
||||
|
||||
@Expose
|
||||
UUID senderId;
|
||||
|
|
|
@ -47,9 +47,6 @@ public interface ITossableItem extends ITossable<ItemStack>, 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<ItemStack>, IDispensable {
|
|||
world.spawnEntity((Entity)projectile);
|
||||
}
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
player.addStat(StatList.getObjectUseStats(itemstack.getItem()));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "unicopia:item/handheld_staff",
|
||||
"textures": {
|
||||
"layer0": "unicopia:items/spear_wood"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/unicopia/textures/items/spear_wood.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/items/spear_wood.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in a new issue