mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 12:33:35 +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
140 lines
4.9 KiB
C++
140 lines
4.9 KiB
C++
#include "../Platform/stdafx.h"
|
|
#include "../Headers/net.minecraft.world.entity.player.h"
|
|
#include "../Headers/net.minecraft.world.item.h"
|
|
#include "../Headers/net.minecraft.world.level.h"
|
|
#include "../Headers/net.minecraft.world.phys.h"
|
|
#include "LeashFenceKnotEntity.h"
|
|
|
|
void LeashFenceKnotEntity::_init() { defineSynchedData(); }
|
|
|
|
LeashFenceKnotEntity::LeashFenceKnotEntity(Level* level)
|
|
: HangingEntity(level) {
|
|
_init();
|
|
}
|
|
|
|
LeashFenceKnotEntity::LeashFenceKnotEntity(Level* level, int xTile, int yTile,
|
|
int zTile)
|
|
: HangingEntity(level, xTile, yTile, zTile, 0) {
|
|
_init();
|
|
setPos(xTile + .5, yTile + .5, zTile + .5);
|
|
}
|
|
|
|
void LeashFenceKnotEntity::defineSynchedData() {
|
|
HangingEntity::defineSynchedData();
|
|
}
|
|
|
|
void LeashFenceKnotEntity::setDir(int dir) {
|
|
// override to do nothing, knots don't have directions
|
|
}
|
|
|
|
int LeashFenceKnotEntity::getWidth() { return 9; }
|
|
|
|
int LeashFenceKnotEntity::getHeight() { return 9; }
|
|
|
|
bool LeashFenceKnotEntity::shouldRenderAtSqrDistance(double distance) {
|
|
return distance < 32 * 32;
|
|
}
|
|
|
|
void LeashFenceKnotEntity::dropItem(std::shared_ptr<Entity> causedBy) {}
|
|
|
|
bool LeashFenceKnotEntity::save(CompoundTag* entityTag) {
|
|
// knots are not saved, they are recreated by the entities that are tied
|
|
return false;
|
|
}
|
|
|
|
void LeashFenceKnotEntity::addAdditonalSaveData(CompoundTag* tag) {}
|
|
|
|
void LeashFenceKnotEntity::readAdditionalSaveData(CompoundTag* tag) {}
|
|
|
|
bool LeashFenceKnotEntity::interact(std::shared_ptr<Player> player) {
|
|
std::shared_ptr<ItemInstance> item = player->getCarriedItem();
|
|
|
|
bool attachedMob = false;
|
|
if (item != nullptr && item->id == Item::lead_Id) {
|
|
if (!level->isClientSide) {
|
|
// look for entities that can be attached to the fence
|
|
double range = 7;
|
|
AABB mob_aabb{x - range, y - range, z - range,
|
|
x + range, y + range, z + range};
|
|
std::vector<std::shared_ptr<Entity> >* mobs =
|
|
level->getEntitiesOfClass(typeid(Mob), &mob_aabb);
|
|
if (mobs != nullptr) {
|
|
for (auto it = mobs->begin(); it != mobs->end(); ++it) {
|
|
std::shared_ptr<Mob> mob =
|
|
std::dynamic_pointer_cast<Mob>(*it);
|
|
if (mob->isLeashed() && mob->getLeashHolder() == player) {
|
|
mob->setLeashedTo(shared_from_this(), true);
|
|
attachedMob = true;
|
|
}
|
|
}
|
|
delete mobs;
|
|
}
|
|
}
|
|
}
|
|
if (!level->isClientSide && !attachedMob) {
|
|
remove();
|
|
|
|
if (player->abilities.instabuild) {
|
|
// if the player is in creative mode, attempt to remove all leashed
|
|
// mobs without dropping additional items
|
|
double range = 7;
|
|
AABB mob_aabb{x - range, y - range, z - range,
|
|
x + range, y + range, z + range};
|
|
std::vector<std::shared_ptr<Entity> >* mobs =
|
|
level->getEntitiesOfClass(typeid(Mob), &mob_aabb);
|
|
if (mobs != nullptr) {
|
|
for (auto it = mobs->begin(); it != mobs->end(); ++it) {
|
|
std::shared_ptr<Mob> mob =
|
|
std::dynamic_pointer_cast<Mob>(*it);
|
|
if (mob->isLeashed() &&
|
|
mob->getLeashHolder() == shared_from_this()) {
|
|
mob->dropLeash(true, false);
|
|
}
|
|
}
|
|
delete mobs;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool LeashFenceKnotEntity::survives() {
|
|
// knots are placed on top of fence tiles
|
|
int tile = level->getTile(xTile, yTile, zTile);
|
|
if (Tile::tiles[tile] != nullptr &&
|
|
Tile::tiles[tile]->getRenderShape() == Tile::SHAPE_FENCE) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::shared_ptr<LeashFenceKnotEntity> LeashFenceKnotEntity::createAndAddKnot(
|
|
Level* level, int x, int y, int z) {
|
|
std::shared_ptr<LeashFenceKnotEntity> knot =
|
|
std::shared_ptr<LeashFenceKnotEntity>(
|
|
new LeashFenceKnotEntity(level, x, y, z));
|
|
knot->forcedLoading = true;
|
|
level->addEntity(knot);
|
|
return knot;
|
|
}
|
|
|
|
std::shared_ptr<LeashFenceKnotEntity> LeashFenceKnotEntity::findKnotAt(
|
|
Level* level, int x, int y, int z) {
|
|
AABB leash_fence_knot_entity_aabb{x - 1.0, y - 1.0, z - 1.0,
|
|
x + 1.0, y + 1.0, z + 1.0};
|
|
std::vector<std::shared_ptr<Entity> >* knots = level->getEntitiesOfClass(
|
|
typeid(LeashFenceKnotEntity), &leash_fence_knot_entity_aabb);
|
|
if (knots != nullptr) {
|
|
for (auto it = knots->begin(); it != knots->end(); ++it) {
|
|
std::shared_ptr<LeashFenceKnotEntity> knot =
|
|
std::dynamic_pointer_cast<LeashFenceKnotEntity>(*it);
|
|
if (knot->xTile == x && knot->yTile == y && knot->zTile == z) {
|
|
delete knots;
|
|
return knot;
|
|
}
|
|
}
|
|
delete knots;
|
|
}
|
|
return nullptr;
|
|
}
|