mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-25 03:43:36 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
155 lines
5.6 KiB
C++
155 lines
5.6 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.level.h"
|
|
#include "../../Headers/net.minecraft.world.level.tile.h"
|
|
#include "../../Headers/net.minecraft.world.phys.h"
|
|
#include "../../Headers/net.minecraft.world.item.h"
|
|
#include "../../Headers/net.minecraft.world.effect.h"
|
|
#include "../../Util/SharedConstants.h"
|
|
#include "../../Util/JavaMath.h"
|
|
#include "ThrownPotion.h"
|
|
|
|
const double ThrownPotion::SPLASH_RANGE = 4.0;
|
|
const double ThrownPotion::SPLASH_RANGE_SQ =
|
|
ThrownPotion::SPLASH_RANGE * ThrownPotion::SPLASH_RANGE;
|
|
|
|
void ThrownPotion::_init() {
|
|
// 4J Stu - This function call had to be moved here from the Entity ctor to
|
|
// ensure that the derived version of the function is called
|
|
this->defineSynchedData();
|
|
|
|
potionItem = nullptr;
|
|
}
|
|
|
|
ThrownPotion::ThrownPotion(Level* level) : Throwable(level) { _init(); }
|
|
|
|
ThrownPotion::ThrownPotion(Level* level, std::shared_ptr<LivingEntity> mob,
|
|
int potionValue)
|
|
: Throwable(level, mob) {
|
|
_init();
|
|
|
|
potionItem = std::shared_ptr<ItemInstance>(
|
|
new ItemInstance(Item::potion, 1, potionValue));
|
|
}
|
|
|
|
ThrownPotion::ThrownPotion(Level* level, std::shared_ptr<LivingEntity> mob,
|
|
std::shared_ptr<ItemInstance> potion)
|
|
: Throwable(level, mob) {
|
|
_init();
|
|
|
|
potionItem = potion;
|
|
}
|
|
|
|
ThrownPotion::ThrownPotion(Level* level, double x, double y, double z,
|
|
int potionValue)
|
|
: Throwable(level, x, y, z) {
|
|
_init();
|
|
|
|
potionItem = std::shared_ptr<ItemInstance>(
|
|
new ItemInstance(Item::potion, 1, potionValue));
|
|
}
|
|
|
|
ThrownPotion::ThrownPotion(Level* level, double x, double y, double z,
|
|
std::shared_ptr<ItemInstance> potion)
|
|
: Throwable(level, x, y, z) {
|
|
_init();
|
|
|
|
potionItem = potion;
|
|
}
|
|
|
|
float ThrownPotion::getGravity() { return 0.05f; }
|
|
|
|
float ThrownPotion::getThrowPower() { return 0.5f; }
|
|
|
|
float ThrownPotion::getThrowUpAngleOffset() { return -20; }
|
|
|
|
void ThrownPotion::setPotionValue(int potionValue) {
|
|
if (potionItem == nullptr)
|
|
potionItem =
|
|
std::shared_ptr<ItemInstance>(new ItemInstance(Item::potion, 1, 0));
|
|
potionItem->setAuxValue(potionValue);
|
|
}
|
|
|
|
int ThrownPotion::getPotionValue() {
|
|
if (potionItem == nullptr)
|
|
potionItem =
|
|
std::shared_ptr<ItemInstance>(new ItemInstance(Item::potion, 1, 0));
|
|
return potionItem->getAuxValue();
|
|
}
|
|
|
|
void ThrownPotion::onHit(HitResult* res) {
|
|
if (!level->isClientSide) {
|
|
std::vector<MobEffectInstance*>* mobEffects =
|
|
Item::potion->getMobEffects(potionItem);
|
|
|
|
if (mobEffects != nullptr && !mobEffects->empty()) {
|
|
AABB aoe = bb.grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE);
|
|
std::vector<std::shared_ptr<Entity> >* entitiesOfClass =
|
|
level->getEntitiesOfClass(typeid(LivingEntity), &aoe);
|
|
|
|
if (entitiesOfClass != nullptr && !entitiesOfClass->empty()) {
|
|
// for (Entity e : entitiesOfClass)
|
|
for (auto it = entitiesOfClass->begin();
|
|
it != entitiesOfClass->end(); ++it) {
|
|
// shared_ptr<Entity> e = *it;
|
|
std::shared_ptr<LivingEntity> e =
|
|
std::dynamic_pointer_cast<LivingEntity>(*it);
|
|
double dist = distanceToSqr(e);
|
|
if (dist < SPLASH_RANGE_SQ) {
|
|
double scale = 1.0 - (sqrt(dist) / SPLASH_RANGE);
|
|
if (e == res->entity) {
|
|
scale = 1;
|
|
}
|
|
|
|
// for (MobEffectInstance effect : mobEffects)
|
|
for (auto itMEI = mobEffects->begin();
|
|
itMEI != mobEffects->end(); ++itMEI) {
|
|
MobEffectInstance* effect = *itMEI;
|
|
int id = effect->getId();
|
|
if (MobEffect::effects[id]->isInstantenous()) {
|
|
MobEffect::effects[id]->applyInstantenousEffect(
|
|
getOwner(), e, effect->getAmplifier(),
|
|
scale);
|
|
} else {
|
|
int duration =
|
|
(int)(scale *
|
|
(double)effect->getDuration() +
|
|
.5);
|
|
if (duration >
|
|
SharedConstants::TICKS_PER_SECOND) {
|
|
e->addEffect(new MobEffectInstance(
|
|
id, duration, effect->getAmplifier()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
delete entitiesOfClass;
|
|
}
|
|
level->levelEvent(LevelEvent::PARTICLES_POTION_SPLASH,
|
|
(int)Math::round(x), (int)Math::round(y),
|
|
(int)Math::round(z), getPotionValue());
|
|
|
|
remove();
|
|
}
|
|
}
|
|
|
|
void ThrownPotion::readAdditionalSaveData(CompoundTag* tag) {
|
|
Throwable::readAdditionalSaveData(tag);
|
|
|
|
if (tag->contains(L"Potion")) {
|
|
potionItem = ItemInstance::fromTag(tag->getCompound(L"Potion"));
|
|
} else {
|
|
setPotionValue(tag->getInt(L"potionValue"));
|
|
}
|
|
|
|
if (potionItem == nullptr) remove();
|
|
}
|
|
|
|
void ThrownPotion::addAdditonalSaveData(CompoundTag* tag) {
|
|
Throwable::addAdditonalSaveData(tag);
|
|
|
|
if (potionItem != nullptr)
|
|
tag->putCompound(L"Potion", potionItem->save(new CompoundTag()));
|
|
}
|