TU43 Release 4

+ Banners, Banners, Banners!
This commit is contained in:
Tranqlmao
2026-07-07 19:47:42 -04:00
parent d1bf3952cd
commit be3bf0aebd
114 changed files with 798 additions and 7 deletions
+81
View File
@@ -0,0 +1,81 @@
#include "stdafx.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "ItemInstance.h"
#include "BannerItem.h"
#include "BannerTileEntity.h"
#include "Mth.h"
const unsigned int BannerItem::COLOR_DESCS[16] =
{
IDS_TILE_BANNER_BLACK,
IDS_TILE_BANNER_RED,
IDS_TILE_BANNER_GREEN,
IDS_TILE_BANNER_BROWN,
IDS_TILE_BANNER_BLUE,
IDS_TILE_BANNER_PURPLE,
IDS_TILE_BANNER_CYAN,
IDS_TILE_BANNER_SILVER,
IDS_TILE_BANNER_GRAY,
IDS_TILE_BANNER_PINK,
IDS_TILE_BANNER_LIME,
IDS_TILE_BANNER_YELLOW,
IDS_TILE_BANNER_LIGHT_BLUE,
IDS_TILE_BANNER_MAGENTA,
IDS_TILE_BANNER_ORANGE,
IDS_TILE_BANNER_WHITE,
};
BannerItem::BannerItem(int id) : Item(id)
{
maxStackSize = 16;
setStackedByData(true);
setMaxDamage(0);
}
unsigned int BannerItem::getDescriptionId(shared_ptr<ItemInstance> instance)
{
int color = instance->getAuxValue() & 15;
return COLOR_DESCS[color];
}
bool BannerItem::useOn(shared_ptr<ItemInstance> instance, shared_ptr<Player> player, Level *level,
int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
{
if (face == 0) return false;
if (!level->getMaterial(x, y, z)->isSolid()) return false;
if (face == 1) y++;
if (face == 2) z--;
if (face == 3) z++;
if (face == 4) x--;
if (face == 5) x++;
if (!player->mayUseItemAt(x, y, z, face, instance)) return false;
if (!bTestUseOnOnly)
{
if (face == 1)
{
int rot = Mth::floor(((player->yRot + 180.0f) * 16.0f) / 360.0f + 0.5f) & 15;
level->setTileAndData(x, y, z, Tile::standing_banner_Id, rot, Tile::UPDATE_CLIENTS);
}
else
{
level->setTileAndData(x, y, z, Tile::wall_banner_Id, face, Tile::UPDATE_CLIENTS);
}
shared_ptr<BannerTileEntity> bte = dynamic_pointer_cast<BannerTileEntity>(level->getTileEntity(x, y, z));
if (bte != nullptr)
{
int color = instance->getAuxValue() & 15;
bte->setBaseColor(color);
bte->setChanged();
}
instance->count--;
}
return true;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "Item.h"
class IconRegister;
class BannerItem : public Item
{
private:
static const unsigned int COLOR_DESCS[16];
public:
BannerItem(int id);
virtual unsigned int getDescriptionId(shared_ptr<ItemInstance> instance) override;
virtual bool useOn(shared_ptr<ItemInstance> instance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly = false) override;
};
+155
View File
@@ -0,0 +1,155 @@
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.player.h"
#include "Material.h"
#include "ItemInstance.h"
#include "Random.h"
#include "BannerTileEntity.h"
#include "BannerTile.h"
BannerTile::BannerTile(int id, bool onGround) : BaseEntityTile(id, Material::wood, isSolidRender())
{
this->onGround = onGround;
this->m_dropColor = 15;
updateDefaultShape();
}
Icon *BannerTile::getTexture(int face, int data)
{
return Tile::wood->getTexture(face);
}
void BannerTile::updateDefaultShape()
{
if (onGround)
{
float r = 4 / 16.0f;
float h = 16 / 16.0f;
this->setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r);
}
else
{
this->setShape(0, 0, 0, 1, 1, 1);
}
}
AABB *BannerTile::getAABB(Level *level, int x, int y, int z)
{
return nullptr;
}
AABB *BannerTile::getTileAABB(Level *level, int x, int y, int z)
{
updateShape(level, x, y, z);
return BaseEntityTile::getTileAABB(level, x, y, z);
}
void BannerTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity)
{
if (onGround) return;
int face = level->getData(x, y, z);
float h0 = 0 / 16.0f;
float h1 = 16 / 16.0f;
float d0 = 2 / 16.0f;
float w0 = 2 / 16.0f;
float w1 = 14 / 16.0f;
setShape(0, 0, 0, 1, 1, 1);
if (face == 2) setShape(w0, h0, 1 - d0, w1, h1, 1);
if (face == 3) setShape(w0, h0, 0, w1, h1, d0);
if (face == 4) setShape(1 - d0, h0, w0, 1, h1, w1);
if (face == 5) setShape(0, h0, w0, d0, h1, w1);
}
int BannerTile::getRenderShape()
{
return Tile::SHAPE_INVISIBLE;
}
bool BannerTile::isCubeShaped()
{
return false;
}
bool BannerTile::isPathfindable(LevelSource *level, int x, int y, int z)
{
return true;
}
bool BannerTile::isSolidRender(bool isServerLevel)
{
return false;
}
shared_ptr<TileEntity> BannerTile::newTileEntity(Level *level)
{
return std::make_shared<BannerTileEntity>();
}
int BannerTile::getResource(int data, Random *random, int playerBonusLevel)
{
return Tile::standing_banner_Id;
}
void BannerTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
bool remove = false;
if (onGround)
{
if (!level->getMaterial(x, y - 1, z)->isSolid()) remove = true;
}
else
{
int face = level->getData(x, y, z);
remove = true;
if (face == 2 && level->getMaterial(x, y, z + 1)->isSolid()) remove = false;
if (face == 3 && level->getMaterial(x, y, z - 1)->isSolid()) remove = false;
if (face == 4 && level->getMaterial(x + 1, y, z)->isSolid()) remove = false;
if (face == 5 && level->getMaterial(x - 1, y, z)->isSolid()) remove = false;
}
if (remove)
{
spawnResources(level, x, y, z, level->getData(x, y, z), 0);
level->removeTile(x, y, z);
level->removeTileEntity(x, y, z);
}
BaseEntityTile::neighborChanged(level, x, y, z, type);
}
int BannerTile::cloneTileId(Level *level, int x, int y, int z)
{
return Tile::standing_banner_Id;
}
void BannerTile::registerIcons(IconRegister *iconRegister)
{
}
void BannerTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
{
shared_ptr<BannerTileEntity> bte = dynamic_pointer_cast<BannerTileEntity>(level->getTileEntity(x, y, z));
m_dropColor = (bte != nullptr) ? (bte->getBaseColor() & 15) : 15;
BaseEntityTile::playerWillDestroy(level, x, y, z, data, player);
}
void BannerTile::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel)
{
if (level->isClientSide) return;
int color = m_dropColor;
shared_ptr<BannerTileEntity> bte = dynamic_pointer_cast<BannerTileEntity>(level->getTileEntity(x, y, z));
if (bte != nullptr) color = bte->getBaseColor() & 15;
int count = getResourceCountForLootBonus(playerBonusLevel, level->random);
for (int i = 0; i < count; i++)
{
if (level->random->nextFloat() > odds) continue;
popResource(level, x, y, z, std::make_shared<ItemInstance>(Tile::standing_banner_Id, 1, color));
}
}
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "BaseEntityTile.h"
#include "TileEntity.h"
#include "stdafx.h"
#include "Material.h"
class Player;
class BannerTile : public BaseEntityTile
{
friend class Tile;
private:
bool onGround;
int m_dropColor;
protected:
BannerTile(int id, bool onGround);
public:
Icon *getTexture(int face, int data);
virtual void updateDefaultShape();
AABB *getAABB(Level *level, int x, int y, int z);
AABB *getTileAABB(Level *level, int x, int y, int z);
void updateShape(LevelSource *level, int x, int y, int z, int forceData = -1, shared_ptr<TileEntity> forceEntity = shared_ptr<TileEntity>());
int getRenderShape();
bool isCubeShaped();
virtual bool isPathfindable(LevelSource *level, int x, int y, int z);
bool isSolidRender(bool isServerLevel = false);
protected:
shared_ptr<TileEntity> newTileEntity(Level *level);
public:
int getResource(int data, Random *random, int playerBonusLevel);
void neighborChanged(Level *level, int x, int y, int z, int type);
int cloneTileId(Level *level, int x, int y, int z);
void registerIcons(IconRegister *iconRegister);
virtual void playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player) override;
virtual void spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel) override;
using BaseEntityTile::spawnResources;
};
+70
View File
@@ -0,0 +1,70 @@
#include "stdafx.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.network.packet.h"
#include "BannerTileEntity.h"
#include "TileEntityDataPacket.h"
BannerTileEntity::BannerTileEntity() : TileEntity()
{
baseColor = 15;
}
void BannerTileEntity::save(CompoundTag *tag)
{
TileEntity::save(tag);
tag->putInt(L"Base", baseColor);
if (!patterns.empty())
{
ListTag<CompoundTag> *list = new ListTag<CompoundTag>();
for (const BannerPattern &bp : patterns)
{
CompoundTag *entry = new CompoundTag();
entry->putString(L"Pattern", bp.pattern);
entry->putInt(L"Color", bp.color);
list->add(entry);
}
tag->put(L"Patterns", list);
}
}
void BannerTileEntity::load(CompoundTag *tag)
{
TileEntity::load(tag);
baseColor = tag->getInt(L"Base");
patterns.clear();
if (tag->contains(L"Patterns"))
{
ListTag<CompoundTag> *list = static_cast<ListTag<CompoundTag> *>(
static_cast<void *>(tag->getList(L"Patterns")));
if (list)
{
for (int i = 0; i < list->size(); i++)
{
CompoundTag *entry = list->get(i);
BannerPattern bp;
bp.pattern = entry->getString(L"Pattern");
bp.color = entry->getInt(L"Color");
patterns.push_back(bp);
if (patterns.size() >= 6) break;
}
}
}
}
shared_ptr<Packet> BannerTileEntity::getUpdatePacket()
{
CompoundTag *tag = new CompoundTag();
save(tag);
return std::make_shared<TileEntityDataPacket>(x, y, z, TileEntityDataPacket::TYPE_BANNER, tag);
}
shared_ptr<TileEntity> BannerTileEntity::clone()
{
shared_ptr<BannerTileEntity> result = std::make_shared<BannerTileEntity>();
TileEntity::clone(result);
result->baseColor = baseColor;
result->patterns = patterns;
return result;
}
+38
View File
@@ -0,0 +1,38 @@
#pragma once
using namespace std;
#include "TileEntity.h"
#include <vector>
struct BannerPattern
{
wstring pattern;
int color;
};
class BannerTileEntity : public TileEntity
{
public:
eINSTANCEOF GetType() { return eTYPE_BANNERTILEENTITY; }
static TileEntity *create() { return new BannerTileEntity(); }
private:
int baseColor;
vector<BannerPattern> patterns;
public:
BannerTileEntity();
virtual ~BannerTileEntity() {}
int getBaseColor() const { return baseColor; }
void setBaseColor(int color) { baseColor = color; }
const vector<BannerPattern> &getPatterns() const { return patterns; }
void addPattern(const wstring &pattern, int color) { patterns.push_back({ pattern, color }); }
void clearPatterns() { patterns.clear(); }
virtual void save(CompoundTag *tag);
virtual void load(CompoundTag *tag);
virtual shared_ptr<Packet> getUpdatePacket();
virtual shared_ptr<TileEntity> clone();
};
+2
View File
@@ -319,6 +319,7 @@ enum eINSTANCEOF
eTYPE_COMPARATORTILEENTITY = eTYPE_TILEENTITY | 0x0F,
eTYPE_DAYLIGHTDETECTORTILEENTITY = eTYPE_TILEENTITY | 0x10,
eTYPE_HOPPERTILEENTITY = eTYPE_TILEENTITY | 0x11,
eTYPE_BANNERTILEENTITY = eTYPE_TILEENTITY | 0x12,
eTYPE_DISPENSERTILEENTITY = eTYPE_TILEENTITY | BIT_DISPENSERTILEENTITY,
eTYPE_DROPPERTILEENTITY = eTYPE_DISPENSERTILEENTITY | 0x1,
@@ -546,6 +547,7 @@ public:
classes->push_back( SUBCLASS(eTYPE_COMPARATORTILEENTITY )->addParent( eTYPE_TILEENTITY ) );
classes->push_back( SUBCLASS(eTYPE_DAYLIGHTDETECTORTILEENTITY )->addParent( eTYPE_TILEENTITY ) );
classes->push_back( SUBCLASS(eTYPE_HOPPERTILEENTITY )->addParent( eTYPE_TILEENTITY ) );
classes->push_back( SUBCLASS(eTYPE_BANNERTILEENTITY )->addParent( eTYPE_TILEENTITY ) );
classes->push_back( SUBCLASS(eTYPE_DISPENSERTILEENTITY )->addParent( eTYPE_TILEENTITY ) );
classes->push_back( SUBCLASS(eTYPE_DROPPERTILEENTITY )->addParent( eTYPE_DISPENSERTILEENTITY ) );
+5 -3
View File
@@ -5,7 +5,7 @@
#include "Facing.h"
#include "GrassPathTile.h"
GrassPathTile::GrassPathTile(int id) : Tile(id, Material::dirt), iconTop(nullptr)
GrassPathTile::GrassPathTile(int id) : Tile(id, Material::dirt), iconTop(nullptr), iconBottom(nullptr)
{
}
@@ -26,13 +26,15 @@ bool GrassPathTile::isCubeShaped()
void GrassPathTile::registerIcons(IconRegister *iconRegister)
{
iconTop = iconRegister->registerIcon(L"grass_path_top");
icon = iconRegister->registerIcon(L"grass_path_side");
iconTop = iconRegister->registerIcon(L"grass_path_top");
iconBottom = iconRegister->registerIcon(L"dirt");
icon = iconRegister->registerIcon(L"grass_path_side");
}
Icon *GrassPathTile::getTexture(int face, int data)
{
if (face == Facing::UP) return iconTop;
if (face == Facing::DOWN) return iconBottom;
return icon;
}
+1
View File
@@ -4,6 +4,7 @@
class GrassPathTile : public Tile
{
Icon *iconTop;
Icon *iconBottom;
public:
GrassPathTile(int id);
+7
View File
@@ -277,6 +277,8 @@ BoneBlockTile* Tile::bone_block = nullptr;
Tile* Tile::barrier = nullptr;
TallGrass2* Tile::double_plant = nullptr;
BannerTile* Tile::standing_banner = nullptr;
BannerTile* Tile::wall_banner = nullptr;
DWORD Tile::tlsIdxShape = TlsAlloc();
@@ -619,6 +621,11 @@ void Tile::staticCtor()
Tile::double_plant = static_cast<TallGrass2*>((new TallGrass2(175))->setDestroyTime(0.0f)->setSoundType(Tile::SOUND_GRASS)->setIconName(L"tallgrass2_tall_grass_upper")->setDescriptionId(IDS_DESC_DOUBLE_TALL_GRASS)->setUseDescriptionId(IDS_DESC_TALL_GRASS)->disableMipmap()->sendTileData(0xFF));
Tile::standing_banner = static_cast<BannerTile*>((new BannerTile(176, true))->setDestroyTime(1.0f)->setSoundType(Tile::SOUND_WOOD)->setIconName(L"planks_oak")->setNotCollectStatistics()->sendTileData()->setUseDescriptionId(IDS_DESC_SIGN));
Tile::wall_banner = static_cast<BannerTile*>((new BannerTile(177, false))->setDestroyTime(1.0f)->setSoundType(Tile::SOUND_WOOD)->setIconName(L"planks_oak")->setNotCollectStatistics()->sendTileData()->setUseDescriptionId(IDS_DESC_SIGN));
Item::items[standing_banner_Id] = (new BannerItem(standing_banner_Id - 256))->setIconName(L"sign")->setDescriptionId(IDS_TILE_BANNER)->setUseDescriptionId(IDS_DESC_SIGN);
// Special cases for certain items since they can have different icons
Item::items[wool_Id] = ( new WoolTileItem(Tile::wool_Id- 256) )->setIconName(L"cloth")->setDescriptionId(IDS_TILE_CLOTH)->setUseDescriptionId(IDS_DESC_WOOL);
Item::items[stained_hardened_clay_Id]= ( new WoolTileItem(Tile::stained_hardened_clay_Id - 256))->setIconName(L"clayHardenedStained")->setDescriptionId(IDS_TILE_STAINED_CLAY)->setUseDescriptionId(IDS_DESC_STAINED_CLAY);
+6 -3
View File
@@ -49,6 +49,7 @@ class GrassPathTile;
class BeetrootTile;
class MagmaTile;
class BoneBlockTile;
class BannerTile;
class ChunkRebuildData;
@@ -415,8 +416,8 @@ public:
static const int coal_block_Id = 173;
static const int packed_ice_Id = 174;
static const int double_plant_Id = 175;
//176 standing_banner
//177 wall_banner
static const int standing_banner_Id = 176;
static const int wall_banner_Id = 177;
static const int daylight_detector_inverted_Id = 178;
static const int red_sandstone_Id = 179;
static const int red_sandstone_stairs_Id = 180;
@@ -679,7 +680,9 @@ public:
static Tile* prismarine;
static TallGrass2* double_plant;
static BannerTile* standing_banner;
static BannerTile* wall_banner;
static void staticCtor();
+1
View File
@@ -32,6 +32,7 @@ void TileEntity::staticCtor()
TileEntity::setId(DaylightDetectorTileEntity::create, eTYPE_DAYLIGHTDETECTORTILEENTITY, L"DLDetector");
TileEntity::setId(HopperTileEntity::create, eTYPE_HOPPERTILEENTITY, L"Hopper");
TileEntity::setId(ComparatorTileEntity::create, eTYPE_COMPARATORTILEENTITY, L"Comparator");
TileEntity::setId(BannerTileEntity::create, eTYPE_BANNERTILEENTITY, L"Banner");
}
void TileEntity::setId(tileEntityCreateFn createFn, eINSTANCEOF clas, wstring id)
+1
View File
@@ -12,6 +12,7 @@ public:
static const int TYPE_ADV_COMMAND = 2;
static const int TYPE_BEACON = 3;
static const int TYPE_SKULL = 4;
static const int TYPE_BANNER = 5;
int x, y, z;
int type;
@@ -2055,6 +2055,12 @@ set(_MINECRAFT_WORLD_COMMON_NET_MINECRAFT_WORLD_LEVEL_TILE
"${CMAKE_CURRENT_SOURCE_DIR}/MagmaTile.h"
"${CMAKE_CURRENT_SOURCE_DIR}/BoneBlockTile.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/BoneBlockTile.h"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerTile.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerTile.h"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerTileEntity.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerTileEntity.h"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerItem.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/BannerItem.h"
"${CMAKE_CURRENT_SOURCE_DIR}/RedSandStoneTile.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/SeaLanternTile.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/PrismarineTile.cpp"
@@ -44,6 +44,7 @@
// 1.8.2
#include "AuxDataTileItem.h"
#include "BannerItem.h"
#include "ColoredTileItem.h"
#include "UseAnim.h"
@@ -21,3 +21,4 @@
#include "SkullTileEntity.h"
#include "EnderChestTileEntity.h"
#include "ItemFrame.h"
#include "BannerTileEntity.h"
@@ -149,5 +149,6 @@
#include "BeetrootTile.h"
#include "MagmaTile.h"
#include "BoneBlockTile.h"
#include "BannerTile.h"