Skip to content

Commit

Permalink
更改边框颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Dec 15, 2020
1 parent 0e35e64 commit cdf7273
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 143 deletions.
127 changes: 74 additions & 53 deletions common/Trapdoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
//

#include "Trapdoor.h"
#include "level/Level.h"
#include "commands/CommandManager.h"
#include <map>
#include "RightClickManager.h"
#include "graphics/Vec3.h"
#include "graphics/BlockPos.h"
#include "block/Block.h"
#include "commands/CommandManager.h"
#include "entity/PlayerBuffer.h"
#include "graphics/AABB.h"
#include "graphics/BlockPos.h"
#include "graphics/Graphics.h"
#include "graphics/Particle.h"
#include "graphics/Vec3.h"
#include "level/Biome.h"
#include "level/Level.h"

void *globalSpawner = nullptr; //全局刷怪器对象
void *globalVillageManager = nullptr; //全局村庄管理器对象
void *globalCommandRegistry = nullptr;
//CircuitSceneGraph *globalCircuitSceneGraph = nullptr;
void *globalCircuitSystem = nullptr;
Level *globalLevel = nullptr;
void* globalSpawner = nullptr; //全局刷怪器对象
void* globalVillageManager = nullptr; //全局村庄管理器对象
void* globalCommandRegistry = nullptr;
// CircuitSceneGraph *globalCircuitSceneGraph = nullptr;
void* globalCircuitSystem = nullptr;
Level* globalLevel = nullptr;

//粒子效果配置(性能配置)
int particleViewDistance = 1024;
Expand All @@ -34,65 +37,83 @@ bool enableHsaShow = false;
int mobTickCounter = 0;
int hopperTickLength = 50;


CommandManager &getCommandManager() {
static CommandManager commandManager;
return commandManager;
CommandManager& getCommandManager() {
static CommandManager commandManager;
return commandManager;
}

std::map<std::string, PlayerBuffer> &getPlayerBuffer() {
static std::map<std::string, PlayerBuffer> playerBuffer;
return playerBuffer;
std::map<std::string, PlayerBuffer>& getPlayerBuffer() {
static std::map<std::string, PlayerBuffer> playerBuffer;
return playerBuffer;
}

RightClickManager &getRightClickManager() {
static RightClickManager rightClickManager;
return rightClickManager;
RightClickManager& getRightClickManager() {
static RightClickManager rightClickManager;
return rightClickManager;
}


void initRightClickManager() {
// auto &manager = getRightClickManager();
// manager.registerRightClickBackEvent("Cactus",
// RIGHT_CLICK_EVENT({
// printf("%s %d %d %d %f %f %f\n",
// player->getNameTag().c_str(),
// pos.x, pos.y, pos.z, offset.x, offset.y,
// offset.z);
// }));
// auto &manager = getRightClickManager();
// manager.registerRightClickBackEvent("Cactus",
// RIGHT_CLICK_EVENT({
// printf("%s
// %d %d %d %f
// %f %f\n",
// player->getNameTag().c_str(),
// pos.x,
// pos.y,
// pos.z,
// offset.x,
// offset.y,
// offset.z);
// }));
}

std::set<BoundingBox> &getHardcodedSpawnAreas() {
static std::set<BoundingBox> hsaList;
return hsaList;
std::set<BoundingBox>& getHardcodedSpawnAreas() {
static std::set<BoundingBox> hsaList;
return hsaList;
}

int showHsaFreq = 0;

void showHsa() {
if (!enableHsaShow)return;
showHsaFreq++;
if (showHsaFreq == 40) {
auto &hsaList = getHardcodedSpawnAreas();
auto num = hsaList.size();
// printf("total %llu\n", num);
for (const auto &hsa:hsaList) {
spawnRectangleParticle(hsa.getSpwawnArea());
}
showHsaFreq = 0;
}

if (!enableHsaShow)
return;
showHsaFreq++;
if (showHsaFreq == 39) {
auto& hsaList = getHardcodedSpawnAreas();
// printf("total %llu\n", num);
auto num = hsaList.size();
for (const auto& hsa : hsaList) {
auto area = hsa.getSpwawnArea();
auto blockPos = area.p1.toBlockPos();
auto nearestPlayer = globalLevel->getNearestPlayer(blockPos);
if (!nearestPlayer) {
return;
}
auto blockSource = nearestPlayer->getBlockSource();
auto biome = blockSource->getBiome(&(blockPos));
auto biomeType = biome->getBiomeType();
if (biomeType == 5 || biomeType == 18)
spawnRectangleParticleColor(area, graphics::COLOR::RED);
else if (biomeType == 10)
spawnRectangleParticleColor(area, graphics::COLOR::BLUE);
else if (biomeType == 15)
spawnRectangleParticleColor(area, graphics::COLOR::GREEN);
else
spawnRectangleParticleColor(area, graphics::COLOR::YELLOW);
}
showHsaFreq = 0;
}
}


namespace trapdoor {
Level *TrapdoorMod::getLevel() {
return this->globalLevel;
}

void TrapdoorMod::setLevel(Level *level) {
this->globalLevel = level;
}

Level* TrapdoorMod::getLevel() {
return this->globalLevel;
}

void TrapdoorMod::setLevel(Level* level) {
this->globalLevel = level;
}

} // namespace trapdoor
81 changes: 36 additions & 45 deletions graphics/AABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,48 @@
#ifndef TRAPDOOR_AABB_H
#define TRAPDOOR_AABB_H

#include "Vec3.h"
#include "BlockPos.h"
#include "Vec3.h"

struct AABB {
Vec3 p1{};
Vec3 p2{};
Vec3 p1{};
Vec3 p2{};

AABB(Vec3 _p1, Vec3 _p2) {
p1 = _p1;
p2 = _p2;
}
AABB(Vec3 _p1, Vec3 _p2) {
p1 = _p1;
p2 = _p2;
}
};

struct BoundingBox {
BlockPos minPos;
BlockPos maxPos;


inline BlockPos getCenter() const {
return {
(minPos.x + maxPos.x) / 2,
(minPos.y + maxPos.y) / 2,
(minPos.z + maxPos.z) / 2
};
}

AABB getSpwawnArea() const {
int x = (this->maxPos.x - this->minPos.x + 1) / 2 + this->minPos.x;
int z = (this->maxPos.z - this->minPos.z + 1) / 2 + this->minPos.z + 1;
Vec3 minPoint{x, minPos.y, z};
Vec3 maxPoint{x + 1, maxPos.y + 1, z + 1};
return {minPoint, maxPoint};
}


bool operator<(const BoundingBox &rhs) const {
if (minPos < rhs.minPos)
return true;
if (rhs.minPos < minPos)
return false;
return maxPos < rhs.maxPos;
}


AABB toAABB() const {
Vec3 one(1, 1, 1);
return {minPos.toVec3(), maxPos.toVec3() + one};
}


BlockPos minPos;
BlockPos maxPos;

inline BlockPos getCenter() const {
return {(minPos.x + maxPos.x) / 2, (minPos.y + maxPos.y) / 2,
(minPos.z + maxPos.z) / 2};
}

AABB getSpwawnArea() const {
int x = (this->maxPos.x - this->minPos.x + 1) / 2 + this->minPos.x;
int z = (this->maxPos.z - this->minPos.z + 1) / 2 + this->minPos.z + 1;
Vec3 minPoint{x, minPos.y, z - 1};
Vec3 maxPoint{x + 1, maxPos.y + 1, z};
return {minPoint, maxPoint};
}

bool operator<(const BoundingBox& rhs) const {
if (minPos < rhs.minPos)
return true;
if (rhs.minPos < minPos)
return false;
return maxPos < rhs.maxPos;
}

AABB toAABB() const {
Vec3 one(1, 1, 1);
return {minPos.toVec3(), maxPos.toVec3() + one};
}
};


#endif //TRAPDOOR_AABB_H
#endif // TRAPDOOR_AABB_H
100 changes: 60 additions & 40 deletions graphics/Particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,79 @@
// Created by xhy on 2020/8/25.
//
#include "Particle.h"
#include <string>
#include "common/Trapdoor.h"
#include "lib/mod.h"
#include <string>

using namespace SymHook;

#include "Graphics.h"
#include "entity/Actor.h"
#include "level/Level.h"
#include "Graphics.h"

namespace particle {
// const ParticleType BALLOON_GAS = "minecraft:balloon_gas_particle";
// const ParticleType HEART = "minecraft:heart_particle ";
// const ParticleType HEART = "minecraft:heart_particle ";
}

void spawnParticle(Vec3 p, std::string &type) {
auto pos = p.toBlockPos();
auto player = globalLevel->getNearestPlayer(pos);
if (!player) {
return;
}
// if (math::distance(p, *player->getPos()) > particleViewDistance)return;
// p.x += 0.5;
// p.y += 0.5;
// p.z += 0.5;
SYM_CALL(
void(*)(Level * , std::string, Vec3 *, void *),
MSSYM_MD5_a2fdc6a066bbe9a360c9c9d76725a8fb,
globalLevel, type, &p, player->getDimension()
);
void spawnParticle(Vec3 p, std::string& type) {
auto pos = p.toBlockPos();
auto player = globalLevel->getNearestPlayer(pos);
if (!player) {
return;
}
// if (math::distance(p, *player->getPos()) > particleViewDistance)return;
// p.x += 0.5;
// p.y += 0.5;
// p.z += 0.5;
SYM_CALL(void (*)(Level*, std::string, Vec3*, void*),
MSSYM_MD5_a2fdc6a066bbe9a360c9c9d76725a8fb, globalLevel, type, &p,
player->getDimension());
}

void spawnRectangleParticle(const AABB& aabb) {
auto p1 = aabb.p1, p2 = aabb.p2;
auto dx = p2.x - p1.x;
auto dy = p2.y - p1.y;
auto dz = p2.z - p1.z;
graphics::drawLine(p1, FACING::POS_X, dx, graphics::COLOR::RED);
graphics::drawLine(p1, FACING::POS_Y, dy, graphics::COLOR::GREEN);
graphics::drawLine(p1, FACING::POS_Z, dz, graphics::COLOR::BLUE);

Vec3 p3{p2.x, p1.y, p2.z};
graphics::drawLine(p3, FACING::NEG_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p3, FACING::POS_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p3, FACING::NEG_Z, dz, graphics::COLOR::WHITE);
Vec3 p4{p2.x, p2.y, p1.z};
graphics::drawLine(p4, FACING::NEG_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p4, FACING::NEG_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p4, FACING::POS_Z, dz, graphics::COLOR::WHITE);

Vec3 p5{p1.x, p2.y, p2.z};
graphics::drawLine(p5, FACING::POS_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p5, FACING::NEG_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p5, FACING::NEG_Z, dz, graphics::COLOR::WHITE);
}
void spawnRectangleParticleColor(const AABB& aabb, graphics::COLOR color) {
auto p1 = aabb.p1, p2 = aabb.p2;
auto dx = p2.x - p1.x;
auto dy = p2.y - p1.y;
auto dz = p2.z - p1.z;
graphics::drawLine(p1, FACING::POS_X, dx, color);
graphics::drawLine(p1, FACING::POS_Y, dy, color);
graphics::drawLine(p1, FACING::POS_Z, dz, color);

Vec3 p3{p2.x, p1.y, p2.z};
graphics::drawLine(p3, FACING::NEG_X, dx, color);
graphics::drawLine(p3, FACING::POS_Y, dy, color);
graphics::drawLine(p3, FACING::NEG_Z, dz, color);
Vec3 p4{p2.x, p2.y, p1.z};
graphics::drawLine(p4, FACING::NEG_X, dx, color);
graphics::drawLine(p4, FACING::NEG_Y, dy, color);
graphics::drawLine(p4, FACING::POS_Z, dz, color);

void spawnRectangleParticle(const AABB &aabb) {
auto p1 = aabb.p1, p2 = aabb.p2;
auto dx = p2.x - p1.x;
auto dy = p2.y - p1.y;
auto dz = p2.z - p1.z;
graphics::drawLine(p1, FACING::POS_X, dx, graphics::COLOR::RED);
graphics::drawLine(p1, FACING::POS_Y, dy, graphics::COLOR::GREEN);
graphics::drawLine(p1, FACING::POS_Z, dz, graphics::COLOR::BLUE);

Vec3 p3{p2.x, p1.y, p2.z};
graphics::drawLine(p3, FACING::NEG_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p3, FACING::POS_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p3, FACING::NEG_Z, dz, graphics::COLOR::WHITE);
Vec3 p4{p2.x, p2.y, p1.z};
graphics::drawLine(p4, FACING::NEG_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p4, FACING::NEG_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p4, FACING::POS_Z, dz, graphics::COLOR::WHITE);

Vec3 p5{p1.x, p2.y, p2.z};
graphics::drawLine(p5, FACING::POS_X, dx, graphics::COLOR::WHITE);
graphics::drawLine(p5, FACING::NEG_Y, dy, graphics::COLOR::WHITE);
graphics::drawLine(p5, FACING::NEG_Z, dz, graphics::COLOR::WHITE);
Vec3 p5{p1.x, p2.y, p2.z};
graphics::drawLine(p5, FACING::POS_X, dx, color);
graphics::drawLine(p5, FACING::NEG_Y, dy, color);
graphics::drawLine(p5, FACING::NEG_Z, dz, color);
}
10 changes: 5 additions & 5 deletions graphics/Particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#include <string>

#include "Graphics.h"
#include "lib/pch.h"

void spawnParticle(Vec3 p, std::string& type);

void spawnParticle(Vec3 p, std::string &type);

void spawnRectangleParticle(const AABB &aabb);

#endif //TRAPDOOR_PARTICLE_H
void spawnRectangleParticle(const AABB& aabb);
void spawnRectangleParticleColor(const AABB& aabb, graphics::COLOR color);
#endif // TRAPDOOR_PARTICLE_H

0 comments on commit cdf7273

Please sign in to comment.