Search in sources :

Example 1 with SplashPotionItem

use of net.minecraft.item.SplashPotionItem in project bewitchment by MoriyaShiine.

the class ScepterCraftingRecipe method craft.

@Override
public ItemStack craft(CraftingInventory inv) {
    ItemStack scepter = null, potion = null;
    for (int i = 0; i < inv.size(); i++) {
        ItemStack stack = inv.getStack(i);
        if (stack.getItem() instanceof ScepterItem) {
            scepter = stack.copy();
        } else if (stack.getItem() instanceof SplashPotionItem) {
            potion = stack.copy();
        }
    }
    scepter.getOrCreateNbt().putInt("PotionUses", 4);
    PotionUtil.setCustomPotionEffects(scepter, !PotionUtil.getCustomPotionEffects(potion).isEmpty() ? PotionUtil.getCustomPotionEffects(potion) : PotionUtil.getPotionEffects(potion));
    if (potion.getOrCreateNbt().contains("PolymorphUUID")) {
        scepter.getOrCreateNbt().putUuid("PolymorphUUID", potion.getOrCreateNbt().getUuid("PolymorphUUID"));
        scepter.getOrCreateNbt().putString("PolymorphName", potion.getOrCreateNbt().getString("PolymorphName"));
    }
    return scepter;
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) ScepterItem(moriyashiine.bewitchment.common.item.ScepterItem)

Example 2 with SplashPotionItem

use of net.minecraft.item.SplashPotionItem in project bewitchment by MoriyaShiine.

the class ScepterCraftingRecipe method matches.

@Override
public boolean matches(CraftingInventory inv, World world) {
    boolean foundScepter = false, foundPotion = false;
    int foundItems = 0;
    for (int i = 0; i < inv.size(); i++) {
        ItemStack stack = inv.getStack(i);
        if (stack.getItem() instanceof ScepterItem) {
            if (!foundScepter) {
                foundScepter = true;
            }
            foundItems++;
        } else if (stack.getItem() instanceof SplashPotionItem && (!PotionUtil.getPotionEffects(stack).isEmpty() || !PotionUtil.getCustomPotionEffects(stack).isEmpty())) {
            if (!foundPotion) {
                foundPotion = true;
            }
            foundItems++;
        }
    }
    return foundScepter && foundPotion && foundItems == 2;
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) ScepterItem(moriyashiine.bewitchment.common.item.ScepterItem)

Example 3 with SplashPotionItem

use of net.minecraft.item.SplashPotionItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIPotionThrower method checkAndPerformAttack.

@Override
protected void checkAndPerformAttack(LivingEntity attackTarget) {
    if (this.entity.tickCount > this.prevTimeAttacked + this.getAttackCooldown()) {
        ItemStack stack = this.getEquippedWeapon();
        Item item = stack.getItem();
        final double x = attackTarget.getX() - this.entity.getX();
        double y = attackTarget.getY() + attackTarget.getBbHeight() * 0.5D;
        final double z = attackTarget.getZ() - this.entity.getZ();
        final double distance = Math.sqrt(x * x + z * z);
        // Throwable potions
        if (item instanceof SplashPotionItem || item instanceof LingeringPotionItem) {
            PotionEntity proj = new PotionEntity(this.world, this.entity);
            proj.setItem(stack.copy());
            y -= proj.getY();
            proj.shoot(x, y + distance * 0.06D, z, 1.F, this.entity.getRandom().nextFloat() * 0.25F);
            /*proj.motionX += this.entity.motionX;
				proj.motionZ += this.entity.motionZ;
				if (!this.entity.onGround) {
					proj.motionY += this.entity.motionY;
				}*/
            proj.setDeltaMovement(proj.getDeltaMovement().add(this.entity.getDeltaMovement()));
            proj.hasImpulse = true;
            this.entity.level.addFreshEntity(proj);
            this.entity.swing(Hand.OFF_HAND);
            this.entity.playSound(SoundEvents.SPLASH_POTION_THROW, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
            if (CQRConfig.mobs.offhandPotionsAreSingleUse) {
                stack.shrink(1);
            }
            this.prevTimeAttacked = this.entity.tickCount;
        } else if (item instanceof ItemAlchemyBag) {
            IItemHandler inventory = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).resolve().get();
            int indx = this.entity.getRandom().nextInt(inventory.getSlots());
            ItemStack st = inventory.getStackInSlot(indx);
            Set<Integer> usedIDs = new HashSet<>();
            int counter = 0;
            while (st.isEmpty() && !usedIDs.contains(indx) && counter > inventory.getSlots()) {
                indx = this.entity.getRandom().nextInt(inventory.getSlots());
                usedIDs.add(indx);
                st = inventory.getStackInSlot(indx);
                counter++;
            }
            if (!st.isEmpty()) {
                ItemStack potion = st.copy();
                // Now throw it
                if (potion.getItem() instanceof SplashPotionItem || potion.getItem() instanceof LingeringPotionItem) {
                    PotionEntity proj = new PotionEntity(this.world, this.entity);
                    proj.setItem(potion);
                    y -= proj.getY();
                    proj.shoot(x, y + distance * 0.08D, z, 1.F, this.entity.getRandom().nextFloat() * 0.25F);
                    /*proj.motionX += this.entity.motionX;
						proj.motionZ += this.entity.motionZ;
						if (!this.entity.onGround) {
							proj.motionY += this.entity.motionY;
						}*/
                    proj.setDeltaMovement(proj.getDeltaMovement().add(this.entity.getDeltaMovement()));
                    proj.hasImpulse = true;
                    this.entity.level.addFreshEntity(proj);
                    this.entity.swing(Hand.OFF_HAND);
                    this.entity.playSound(SoundEvents.SPLASH_POTION_THROW, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
                }
            }
            this.prevTimeAttacked = this.entity.tickCount;
        }
    }
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) Item(net.minecraft.item.Item) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) Set(java.util.Set) HashSet(java.util.HashSet) IItemHandler(net.minecraftforge.items.IItemHandler) SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) ItemAlchemyBag(team.cqr.cqrepoured.item.ItemAlchemyBag) PotionEntity(net.minecraft.entity.projectile.PotionEntity)

Example 4 with SplashPotionItem

use of net.minecraft.item.SplashPotionItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemAlchemyBag method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity playerIn, Hand handIn) {
    if (!world.isClientSide) {
        if (playerIn.isCrouching()) {
            playerIn.openGui(CQRMain.INSTANCE, GuiHandler.ALCHEMY_BAG_GUI_ID, world, handIn.ordinal(), 0, 0);
            return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
        }
        ItemStack stack = playerIn.getItemInHand(handIn);
        Item item = stack.getItem();
        if (item == this) {
            IItemHandler inventory = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            for (int i = 0; i < inventory.getSlots(); i++) {
                ItemStack potion = inventory.extractItem(i, 1, false);
                if (!potion.isEmpty()) {
                    if (potion.getItem() instanceof SplashPotionItem || potion.getItem() instanceof LingeringPotionItem) {
                        PotionEntity entitypotion = new PotionEntity(world, playerIn);
                        entitypotion.setItem(potion);
                        entitypotion.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
                        world.addFreshEntity(entitypotion);
                        world.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
                        return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
                    }
                }
            }
        }
    }
    return new ActionResult<>(ActionResultType.FAIL, playerIn.getItemInHand(handIn));
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) Item(net.minecraft.item.Item) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) IItemHandler(net.minecraftforge.items.IItemHandler) SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) PotionEntity(net.minecraft.entity.projectile.PotionEntity)

Aggregations

ItemStack (net.minecraft.item.ItemStack)4 SplashPotionItem (net.minecraft.item.SplashPotionItem)4 ScepterItem (moriyashiine.bewitchment.common.item.ScepterItem)2 PotionEntity (net.minecraft.entity.projectile.PotionEntity)2 Item (net.minecraft.item.Item)2 LingeringPotionItem (net.minecraft.item.LingeringPotionItem)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ItemAlchemyBag (team.cqr.cqrepoured.item.ItemAlchemyBag)1