Moved the whole logic to a new file (TooltipManager.cpp), and rewrote most of the logic to profit from object oriented programming. The side-effect is that the changes are scattered across entities, tiles and items because moving everything to OOP requires to add the tooltip to every .cpp file for every tile/item/entities (or their class, on plants for example which all use the tooltip IDS_TOOLTIPS_PLANT)
The issue with the default tooltips loop written by 4J is that:
Its running in the main Minecraft::tick loop and is more than a thousand lines long, polluting the function.
Not using C++'s full potential with object oriented programming, 4J decided to use a big switch case (probably because it could run better on hardware without branch prediction like the WiiU or Xbox 360 ?)
And seems to be better off in its own file than in the main Minecraft.cpp file
116 lines
2.9 KiB
C++
116 lines
2.9 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.levelgen.feature.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "Dimension.h"
|
|
#include "Mushroom.h"
|
|
|
|
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
|
#include "../Minecraft.Server/FourKitBridge.h"
|
|
#endif
|
|
|
|
Mushroom::Mushroom(int id) : Bush(id)
|
|
{
|
|
this->updateDefaultShape();
|
|
this->setTicking(true);
|
|
}
|
|
|
|
// 4J Added override
|
|
void Mushroom::updateDefaultShape()
|
|
{
|
|
float ss = 0.2f;
|
|
this->setShape(0.5f - ss, 0, 0.5f - ss, 0.5f + ss, ss * 2, 0.5f + ss);
|
|
}
|
|
|
|
void Mushroom::tick(Level *level, int x, int y, int z, Random *random)
|
|
{
|
|
if (random->nextInt(25) == 0)
|
|
{
|
|
int r = 4;
|
|
int max = 5;
|
|
for (int xx = x - r; xx <= x + r; xx++)
|
|
for (int zz = z - r; zz <= z + r; zz++)
|
|
for (int yy = y - 1; yy <= y + 1; yy++)
|
|
{
|
|
if (level->getTile(xx, yy, zz) == id && --max <= 0) return;
|
|
}
|
|
|
|
int x2 = x + random->nextInt(3) - 1;
|
|
int y2 = y + random->nextInt(2) - random->nextInt(2);
|
|
int z2 = z + random->nextInt(3) - 1;
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
if (level->isEmptyTile(x2, y2, z2) && canSurvive(level, x2, y2, z2))
|
|
{
|
|
x = x2;
|
|
y = y2;
|
|
z = z2;
|
|
}
|
|
x2 = x + random->nextInt(3) - 1;
|
|
y2 = y + random->nextInt(2) - random->nextInt(2);
|
|
z2 = z + random->nextInt(3) - 1;
|
|
}
|
|
|
|
if (level->isEmptyTile(x2, y2, z2) && canSurvive(level, x2, y2, z2))
|
|
{
|
|
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
|
if (!FourKitBridge::FireBlockSpread(level->dimension->id, x2, y2, z2, x, y, z, id, 0))
|
|
#endif
|
|
level->setTileAndData(x2, y2, z2, id, 0, UPDATE_CLIENTS);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool Mushroom::mayPlace(Level *level, int x, int y, int z)
|
|
{
|
|
return Bush::mayPlace(level, x, y, z) && canSurvive(level, x, y, z);
|
|
}
|
|
|
|
bool Mushroom::mayPlaceOn(int tile)
|
|
{
|
|
return Tile::solid[tile];
|
|
}
|
|
|
|
bool Mushroom::canSurvive(Level *level, int x, int y, int z)
|
|
{
|
|
if (y < 0 || y >= Level::maxBuildHeight) return false;
|
|
|
|
int below = level->getTile(x, y - 1, z);
|
|
|
|
return below == Tile::mycelium_Id || (level->getDaytimeRawBrightness(x, y, z) < 13 && mayPlaceOn(below));
|
|
}
|
|
bool Mushroom::growTree(Level *level, int x, int y, int z, Random *random, bool naturalGrowth, int entityId)
|
|
{
|
|
int data = level->getData(x, y, z);
|
|
|
|
level->removeTile(x, y, z);
|
|
Feature *f = nullptr;
|
|
|
|
if (id == Tile::mushroom_brown_Id)
|
|
{
|
|
f = new HugeMushroomFeature(0);
|
|
}
|
|
else if (id == Tile::mushroom_red_Id)
|
|
{
|
|
f = new HugeMushroomFeature(1);
|
|
}
|
|
|
|
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
|
if (FourKitBridge::FireStructureGrow(level->dimension->id, x, y, z, (id == Tile::mushroom_brown_Id ? 6 : 7), !naturalGrowth, entityId)) {
|
|
if (f != nullptr) delete f;
|
|
f = nullptr;
|
|
}
|
|
#endif
|
|
|
|
if (f == nullptr || !f->place(level, random, x, y, z))
|
|
{
|
|
level->setTileAndData(x, y, z, id, data, Tile::UPDATE_ALL);
|
|
if( f != nullptr )
|
|
delete f;
|
|
return false;
|
|
}
|
|
if( f != nullptr )
|
|
delete f;
|
|
return true;
|
|
}
|