Finish implementation of the Poss Ball
This commit is contained in:
parent
4800e7dd6c
commit
8dfa92f7b8
2 changed files with 183 additions and 4 deletions
|
@ -1,10 +1,14 @@
|
|||
package dev.zontreck.otemod.items;
|
||||
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.monster.Guardian;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Arrow;
|
||||
import net.minecraft.world.item.EggItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -14,16 +18,41 @@ public class PossBallItem extends Item
|
|||
public PossBallItem(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
public boolean contents=false;
|
||||
@Override
|
||||
public boolean isFoil(ItemStack pStack) {
|
||||
return contents;
|
||||
if(pStack.getTag().contains("entity"))
|
||||
{
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
|
||||
contents = !contents;
|
||||
ItemStack stack = pPlayer.getItemInHand(pUsedHand);
|
||||
pLevel.playSound((Player) null, pPlayer.getX(), pPlayer.getY(), pPlayer.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (pLevel.random.nextFloat() * 0.4f + 0.8f));
|
||||
if(!pLevel.isClientSide)
|
||||
{
|
||||
ThrownPossBall TPB = new ThrownPossBall(pLevel, pPlayer);
|
||||
TPB.setItem(stack);
|
||||
TPB.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 1.5F, 1.0F);
|
||||
pLevel.addFreshEntity(TPB);
|
||||
}
|
||||
|
||||
pPlayer.awardStat(Stats.ITEM_USED.get(this));
|
||||
if(!pPlayer.getAbilities().instabuild)
|
||||
{
|
||||
stack.shrink(1);
|
||||
}
|
||||
return super.use(pLevel, pPlayer, pUsedHand);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue