Files
neoLegacy/Minecraft.World/BowItem.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

156 lines
4.6 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.projectile.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.item.enchantment.h"
#include "net.minecraft.world.h"
#include "BowItem.h"
#include "SoundTypes.h"
const wstring BowItem::TEXTURE_PULL[] = {L"bow_pull_0", L"bow_pull_1", L"bow_pull_2"};
BowItem::BowItem(int id) : Item( id )
{
maxStackSize = 1;
setMaxDamage(384);
icons = nullptr;
}
void BowItem::releaseUsing(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player, int durationLeft)
{
bool infiniteArrows = player->abilities.instabuild || EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowInfinite->id, itemInstance) > 0;
int ammoSlot = findAmmoSlot(player);
if (player->abilities.instabuild || ammoSlot >= 0)
{
shared_ptr<ItemInstance> ammo = ammoSlot >= 0 ? player->inventory->getItem(ammoSlot) : nullptr;
if (ammo != nullptr && ammo->id != Item::arrow_Id && !player->abilities.instabuild) infiniteArrows = false;
int timeHeld = getUseDuration(itemInstance) - durationLeft;
float pow = timeHeld / static_cast<float>(MAX_DRAW_DURATION);
pow = ((pow * pow) + pow * 2) / 3;
if (pow < 0.1) return;
if (pow > 1) pow = 1;
shared_ptr<Arrow> arrow = std::make_shared<Arrow>(level, player, pow * 2.0f);
arrow->setFromItem(ammo);
if (pow == 1) arrow->setCritArrow(true);
int damageBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowBonus->id, itemInstance);
if (damageBonus > 0)
{
arrow->setBaseDamage(arrow->getBaseDamage() + static_cast<double>(damageBonus) * .5 + .5);
}
int knockbackBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowKnockback->id, itemInstance);
if (knockbackBonus > 0)
{
arrow->setKnockback(knockbackBonus);
}
if (EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowFire->id, itemInstance) > 0)
{
arrow->setOnFire(100);
}
itemInstance->hurtAndBreak(1, player);
level->playEntitySound(player, eSoundType_RANDOM_BOW, 1.0f, 1 / (random->nextFloat() * 0.4f + 1.2f) + pow * 0.5f);
if (infiniteArrows)
{
arrow->pickup = Arrow::PICKUP_CREATIVE_ONLY;
}
else
{
if (ammoSlot == Inventory::OFFHAND_SLOT)
{
if (--player->inventory->offhand[0]->count <= 0) player->inventory->offhand[0] = nullptr;
}
else if (--player->inventory->items[ammoSlot]->count <= 0) player->inventory->items[ammoSlot] = nullptr;
}
if (!level->isClientSide) level->addEntity(arrow);
}
}
shared_ptr<ItemInstance> BowItem::useTimeDepleted(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player)
{
return instance;
}
int BowItem::getUseDuration(shared_ptr<ItemInstance> itemInstance)
{
return 20 * 60 * 60;
}
UseAnim BowItem::getUseAnimation(shared_ptr<ItemInstance> itemInstance)
{
return UseAnim_bow;
}
shared_ptr<ItemInstance> BowItem::use(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player)
{
if (player->abilities.instabuild || hasAmmo(player))
{
player->startUsingItem(instance, getUseDuration(instance));
}
return instance;
}
int BowItem::getEnchantmentValue()
{
return 1;
}
void BowItem::registerIcons(IconRegister *iconRegister)
{
Item::registerIcons(iconRegister);
icons = new Icon *[BOW_ICONS_COUNT];
for (int i = 0; i < BOW_ICONS_COUNT; i++)
{
icons[i] = iconRegister->registerIcon(TEXTURE_PULL[i]);
}
}
Icon *BowItem::getDrawnIcon(int amount)
{
return icons[amount];
}
int BowItem::findAmmoSlot(shared_ptr<Player> player)
{
Inventory *inventory = player->inventory.get();
if (inventory->offhand[0] != nullptr && Arrow::isArrowItem(inventory->offhand[0]->id))
{
return Inventory::OFFHAND_SLOT;
}
int selected = inventory->selected;
if (selected >= 0 && selected < static_cast<int>(inventory->items.length) && inventory->items[selected] != nullptr && Arrow::isArrowItem(inventory->items[selected]->id))
{
return selected;
}
for (unsigned int i = 0; i < inventory->items.length; i++)
{
if (inventory->items[i] != nullptr && Arrow::isArrowItem(inventory->items[i]->id))
{
return i;
}
}
return -1;
}
bool BowItem::hasAmmo(shared_ptr<Player> player)
{
return findAmmoSlot(player) >= 0;
}
Icon *BowItem::GetOverrideCountIcon(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player)
{
if (player != nullptr && player->getUseItem() == itemInstance)
{
int ticksUsingItem = player->getTicksUsingItem();
if (ticksUsingItem >= MAX_DRAW_DURATION - 2) return getDrawnIcon(2);
if (ticksUsingItem > MAX_DRAW_DURATION * 2 / 3) return getDrawnIcon(1);
if (ticksUsingItem > 0) return getDrawnIcon(0);
}
return Item::GetOverrideCountIcon(itemInstance, player);
}