mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 12:02:27 +00:00
chore: format Minecraft.World
This commit is contained in:
+137
-164
@@ -5,225 +5,198 @@
|
||||
#include "../Headers/com.mojang.nbt.h"
|
||||
#include "ArmorItem.h"
|
||||
|
||||
const int ArmorItem::healthPerSlot[] = {
|
||||
11, 16, 15, 13
|
||||
};
|
||||
const int ArmorItem::healthPerSlot[] = {11, 16, 15, 13};
|
||||
|
||||
const std::wstring ArmorItem::LEATHER_OVERLAYS[] = {
|
||||
L"helmetCloth_overlay", L"chestplateCloth_overlay", L"leggingsCloth_overlay", L"bootsCloth_overlay"
|
||||
};
|
||||
L"helmetCloth_overlay", L"chestplateCloth_overlay",
|
||||
L"leggingsCloth_overlay", L"bootsCloth_overlay"};
|
||||
|
||||
const std::wstring ArmorItem::TEXTURE_EMPTY_SLOTS[] = {
|
||||
L"slot_empty_helmet", L"slot_empty_chestplate", L"slot_empty_leggings", L"slot_empty_boots"
|
||||
};
|
||||
L"slot_empty_helmet", L"slot_empty_chestplate", L"slot_empty_leggings",
|
||||
L"slot_empty_boots"};
|
||||
|
||||
typedef ArmorItem::ArmorMaterial _ArmorMaterial;
|
||||
|
||||
const int _ArmorMaterial::clothArray[] = {1,3,2,1};
|
||||
const int _ArmorMaterial::clothArray[] = {1, 3, 2, 1};
|
||||
const int _ArmorMaterial::chainArray[] = {2, 5, 4, 1};
|
||||
const int _ArmorMaterial::ironArray[] = {2, 6, 5, 2};
|
||||
const int _ArmorMaterial::goldArray[] = {2, 5, 3, 1};
|
||||
const int _ArmorMaterial::diamondArray[] = {3, 8, 6, 3};
|
||||
const _ArmorMaterial *_ArmorMaterial::CLOTH = new _ArmorMaterial(5, _ArmorMaterial::clothArray, 15);
|
||||
const _ArmorMaterial *_ArmorMaterial::CHAIN = new _ArmorMaterial(15, _ArmorMaterial::chainArray, 12);
|
||||
const _ArmorMaterial *_ArmorMaterial::IRON = new _ArmorMaterial(15, _ArmorMaterial::ironArray, 9);
|
||||
const _ArmorMaterial *_ArmorMaterial::GOLD = new _ArmorMaterial(7, _ArmorMaterial::goldArray, 25);
|
||||
const _ArmorMaterial *_ArmorMaterial::DIAMOND = new _ArmorMaterial(33, _ArmorMaterial::diamondArray, 10);
|
||||
const _ArmorMaterial* _ArmorMaterial::CLOTH =
|
||||
new _ArmorMaterial(5, _ArmorMaterial::clothArray, 15);
|
||||
const _ArmorMaterial* _ArmorMaterial::CHAIN =
|
||||
new _ArmorMaterial(15, _ArmorMaterial::chainArray, 12);
|
||||
const _ArmorMaterial* _ArmorMaterial::IRON =
|
||||
new _ArmorMaterial(15, _ArmorMaterial::ironArray, 9);
|
||||
const _ArmorMaterial* _ArmorMaterial::GOLD =
|
||||
new _ArmorMaterial(7, _ArmorMaterial::goldArray, 25);
|
||||
const _ArmorMaterial* _ArmorMaterial::DIAMOND =
|
||||
new _ArmorMaterial(33, _ArmorMaterial::diamondArray, 10);
|
||||
|
||||
_ArmorMaterial::ArmorMaterial(int durabilityMultiplier, const int slotProtections[], int enchantmentValue)
|
||||
{
|
||||
this->durabilityMultiplier = durabilityMultiplier;
|
||||
this->slotProtections = (int *)slotProtections;
|
||||
this->enchantmentValue = enchantmentValue;
|
||||
_ArmorMaterial::ArmorMaterial(int durabilityMultiplier,
|
||||
const int slotProtections[],
|
||||
int enchantmentValue) {
|
||||
this->durabilityMultiplier = durabilityMultiplier;
|
||||
this->slotProtections = (int*)slotProtections;
|
||||
this->enchantmentValue = enchantmentValue;
|
||||
}
|
||||
|
||||
_ArmorMaterial::~ArmorMaterial()
|
||||
{
|
||||
delete [] slotProtections;
|
||||
_ArmorMaterial::~ArmorMaterial() { delete[] slotProtections; }
|
||||
|
||||
int _ArmorMaterial::getHealthForSlot(int slot) const {
|
||||
return healthPerSlot[slot] * durabilityMultiplier;
|
||||
}
|
||||
|
||||
int _ArmorMaterial::getHealthForSlot(int slot) const
|
||||
{
|
||||
return healthPerSlot[slot] * durabilityMultiplier;
|
||||
int _ArmorMaterial::getDefenseForSlot(int slot) const {
|
||||
return slotProtections[slot];
|
||||
}
|
||||
|
||||
int _ArmorMaterial::getDefenseForSlot(int slot) const
|
||||
{
|
||||
return slotProtections[slot];
|
||||
int _ArmorMaterial::getEnchantmentValue() const { return enchantmentValue; }
|
||||
|
||||
int _ArmorMaterial::getTierItemId() const {
|
||||
if (this == CLOTH) {
|
||||
return Item::leather_Id;
|
||||
} else if (this == CHAIN) {
|
||||
return Item::ironIngot_Id;
|
||||
} else if (this == GOLD) {
|
||||
return Item::goldIngot_Id;
|
||||
} else if (this == IRON) {
|
||||
return Item::ironIngot_Id;
|
||||
} else if (this == DIAMOND) {
|
||||
return Item::diamond_Id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _ArmorMaterial::getEnchantmentValue() const
|
||||
{
|
||||
return enchantmentValue;
|
||||
ArmorItem::ArmorItem(int id, const ArmorMaterial* armorType, int icon, int slot)
|
||||
: Item(id),
|
||||
armorType(armorType),
|
||||
slot(slot),
|
||||
modelIndex(icon),
|
||||
defense(armorType->getDefenseForSlot(slot)) {
|
||||
setMaxDamage(armorType->getHealthForSlot(slot));
|
||||
maxStackSize = 1;
|
||||
}
|
||||
|
||||
int _ArmorMaterial::getTierItemId() const
|
||||
{
|
||||
if (this == CLOTH)
|
||||
{
|
||||
return Item::leather_Id;
|
||||
}
|
||||
else if (this == CHAIN)
|
||||
{
|
||||
return Item::ironIngot_Id;
|
||||
}
|
||||
else if (this == GOLD)
|
||||
{
|
||||
return Item::goldIngot_Id;
|
||||
}
|
||||
else if (this == IRON)
|
||||
{
|
||||
return Item::ironIngot_Id;
|
||||
}
|
||||
else if (this == DIAMOND)
|
||||
{
|
||||
return Item::diamond_Id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int ArmorItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer) {
|
||||
if (spriteLayer > 0) {
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
ArmorItem::ArmorItem(int id, const ArmorMaterial *armorType, int icon, int slot) : Item( id ), armorType( armorType ), slot( slot ), modelIndex( icon ), defense( armorType->getDefenseForSlot(slot) )
|
||||
{
|
||||
setMaxDamage(armorType->getHealthForSlot(slot));
|
||||
maxStackSize = 1;
|
||||
}
|
||||
|
||||
int ArmorItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer)
|
||||
{
|
||||
if (spriteLayer > 0)
|
||||
{
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
int color = getColor(item);
|
||||
if (color < 0) color = 0xFFFFFF;
|
||||
return color;
|
||||
int color = getColor(item);
|
||||
if (color < 0) color = 0xFFFFFF;
|
||||
return color;
|
||||
}
|
||||
|
||||
//@Override
|
||||
bool ArmorItem::hasMultipleSpriteLayers()
|
||||
{
|
||||
return armorType == ArmorMaterial::CLOTH;
|
||||
bool ArmorItem::hasMultipleSpriteLayers() {
|
||||
return armorType == ArmorMaterial::CLOTH;
|
||||
}
|
||||
|
||||
int ArmorItem::getEnchantmentValue()
|
||||
{
|
||||
return armorType->getEnchantmentValue();
|
||||
int ArmorItem::getEnchantmentValue() {
|
||||
return armorType->getEnchantmentValue();
|
||||
}
|
||||
|
||||
const _ArmorMaterial *ArmorItem::getMaterial()
|
||||
{
|
||||
return armorType;
|
||||
const _ArmorMaterial* ArmorItem::getMaterial() { return armorType; }
|
||||
|
||||
bool ArmorItem::hasCustomColor(std::shared_ptr<ItemInstance> item) {
|
||||
if (armorType != ArmorMaterial::CLOTH) return false;
|
||||
if (!item->hasTag()) return false;
|
||||
if (!item->getTag()->contains(L"display")) return false;
|
||||
if (!item->getTag()->getCompound(L"display")->contains(L"color"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArmorItem::hasCustomColor(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
if (armorType != ArmorMaterial::CLOTH) return false;
|
||||
if (!item->hasTag()) return false;
|
||||
if (!item->getTag()->contains(L"display")) return false;
|
||||
if (!item->getTag()->getCompound(L"display")->contains(L"color")) return false;
|
||||
int ArmorItem::getColor(std::shared_ptr<ItemInstance> item) {
|
||||
if (armorType != ArmorMaterial::CLOTH) return -1;
|
||||
|
||||
return true;
|
||||
}
|
||||
CompoundTag* tag = item->getTag();
|
||||
if (tag == NULL)
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor(
|
||||
DEFAULT_LEATHER_COLOR);
|
||||
CompoundTag* display = tag->getCompound(L"display");
|
||||
if (display == NULL)
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor(
|
||||
DEFAULT_LEATHER_COLOR);
|
||||
|
||||
int ArmorItem::getColor(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
if (armorType != ArmorMaterial::CLOTH) return -1;
|
||||
|
||||
CompoundTag *tag = item->getTag();
|
||||
if (tag == NULL) return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
|
||||
CompoundTag *display = tag->getCompound(L"display");
|
||||
if (display == NULL) return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
|
||||
|
||||
if (display->contains(L"color"))
|
||||
{
|
||||
return display->getInt(L"color");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
|
||||
}
|
||||
if (display->contains(L"color")) {
|
||||
return display->getInt(L"color");
|
||||
} else {
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor(
|
||||
DEFAULT_LEATHER_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
Icon *ArmorItem::getLayerIcon(int auxValue, int spriteLayer)
|
||||
{
|
||||
if (spriteLayer == 1)
|
||||
{
|
||||
return overlayIcon;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
Icon* ArmorItem::getLayerIcon(int auxValue, int spriteLayer) {
|
||||
if (spriteLayer == 1) {
|
||||
return overlayIcon;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
}
|
||||
|
||||
void ArmorItem::clearColor(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
if (armorType != ArmorMaterial::CLOTH) return;
|
||||
CompoundTag *tag = item->getTag();
|
||||
if (tag == NULL) return;
|
||||
CompoundTag *display = tag->getCompound(L"display");
|
||||
if (display->contains(L"color")) display->remove(L"color");
|
||||
void ArmorItem::clearColor(std::shared_ptr<ItemInstance> item) {
|
||||
if (armorType != ArmorMaterial::CLOTH) return;
|
||||
CompoundTag* tag = item->getTag();
|
||||
if (tag == NULL) return;
|
||||
CompoundTag* display = tag->getCompound(L"display");
|
||||
if (display->contains(L"color")) display->remove(L"color");
|
||||
}
|
||||
|
||||
void ArmorItem::setColor(std::shared_ptr<ItemInstance> item, int color)
|
||||
{
|
||||
if (armorType != ArmorMaterial::CLOTH)
|
||||
{
|
||||
void ArmorItem::setColor(std::shared_ptr<ItemInstance> item, int color) {
|
||||
if (armorType != ArmorMaterial::CLOTH) {
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
printf("Can't dye non-leather!");
|
||||
__debugbreak();
|
||||
printf("Can't dye non-leather!");
|
||||
__debugbreak();
|
||||
#endif
|
||||
//throw new UnsupportedOperationException("Can't dye non-leather!");
|
||||
}
|
||||
// throw new UnsupportedOperationException("Can't dye non-leather!");
|
||||
}
|
||||
|
||||
CompoundTag *tag = item->getTag();
|
||||
CompoundTag* tag = item->getTag();
|
||||
|
||||
if (tag == NULL)
|
||||
{
|
||||
tag = new CompoundTag();
|
||||
item->setTag(tag);
|
||||
}
|
||||
if (tag == NULL) {
|
||||
tag = new CompoundTag();
|
||||
item->setTag(tag);
|
||||
}
|
||||
|
||||
CompoundTag *display = tag->getCompound(L"display");
|
||||
if (!tag->contains(L"display")) tag->putCompound(L"display", display);
|
||||
CompoundTag* display = tag->getCompound(L"display");
|
||||
if (!tag->contains(L"display")) tag->putCompound(L"display", display);
|
||||
|
||||
display->putInt(L"color", color);
|
||||
display->putInt(L"color", color);
|
||||
}
|
||||
|
||||
bool ArmorItem::isValidRepairItem(std::shared_ptr<ItemInstance> source, std::shared_ptr<ItemInstance> repairItem)
|
||||
{
|
||||
if (armorType->getTierItemId() == repairItem->id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Item::isValidRepairItem(source, repairItem);
|
||||
bool ArmorItem::isValidRepairItem(std::shared_ptr<ItemInstance> source,
|
||||
std::shared_ptr<ItemInstance> repairItem) {
|
||||
if (armorType->getTierItemId() == repairItem->id) {
|
||||
return true;
|
||||
}
|
||||
return Item::isValidRepairItem(source, repairItem);
|
||||
}
|
||||
|
||||
//@Override
|
||||
void ArmorItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
void ArmorItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
if (armorType == ArmorMaterial::CLOTH)
|
||||
{
|
||||
overlayIcon = iconRegister->registerIcon(LEATHER_OVERLAYS[slot]);
|
||||
}
|
||||
if (armorType == ArmorMaterial::CLOTH) {
|
||||
overlayIcon = iconRegister->registerIcon(LEATHER_OVERLAYS[slot]);
|
||||
}
|
||||
|
||||
iconEmpty = iconRegister->registerIcon(TEXTURE_EMPTY_SLOTS[slot]);
|
||||
iconEmpty = iconRegister->registerIcon(TEXTURE_EMPTY_SLOTS[slot]);
|
||||
}
|
||||
|
||||
Icon *ArmorItem::getEmptyIcon(int slot)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case 0:
|
||||
return Item::helmet_diamond->iconEmpty;
|
||||
case 1:
|
||||
return Item::chestplate_diamond->iconEmpty;
|
||||
case 2:
|
||||
return Item::leggings_diamond->iconEmpty;
|
||||
case 3:
|
||||
return Item::boots_diamond->iconEmpty;
|
||||
}
|
||||
Icon* ArmorItem::getEmptyIcon(int slot) {
|
||||
switch (slot) {
|
||||
case 0:
|
||||
return Item::helmet_diamond->iconEmpty;
|
||||
case 1:
|
||||
return Item::chestplate_diamond->iconEmpty;
|
||||
case 2:
|
||||
return Item::leggings_diamond->iconEmpty;
|
||||
case 3:
|
||||
return Item::boots_diamond->iconEmpty;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
@@ -2,89 +2,91 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class ArmorItem : public Item
|
||||
{
|
||||
class ArmorItem : public Item {
|
||||
public:
|
||||
static const int SLOT_HEAD = 0;
|
||||
static const int SLOT_TORSO = 1;
|
||||
static const int SLOT_LEGS = 2;
|
||||
static const int SLOT_FEET = 3;
|
||||
static const eMinecraftColour DEFAULT_LEATHER_COLOR = eMinecraftColour_Armour_Default_Leather_Colour;
|
||||
static const int SLOT_HEAD = 0;
|
||||
static const int SLOT_TORSO = 1;
|
||||
static const int SLOT_LEGS = 2;
|
||||
static const int SLOT_FEET = 3;
|
||||
static const eMinecraftColour DEFAULT_LEATHER_COLOR =
|
||||
eMinecraftColour_Armour_Default_Leather_Colour;
|
||||
|
||||
private:
|
||||
static const int healthPerSlot[];
|
||||
static const std::wstring LEATHER_OVERLAYS[] ;
|
||||
static const int healthPerSlot[];
|
||||
static const std::wstring LEATHER_OVERLAYS[];
|
||||
|
||||
public:
|
||||
static const std::wstring TEXTURE_EMPTY_SLOTS[];
|
||||
static const std::wstring TEXTURE_EMPTY_SLOTS[];
|
||||
|
||||
public:
|
||||
class ArmorMaterial
|
||||
{
|
||||
public:
|
||||
static const int clothArray[];
|
||||
static const int chainArray[];
|
||||
static const int ironArray[];
|
||||
static const int goldArray[];
|
||||
static const int diamondArray[];
|
||||
public:
|
||||
static const ArmorMaterial *CLOTH;
|
||||
static const ArmorMaterial *CHAIN;
|
||||
static const ArmorMaterial *IRON;
|
||||
static const ArmorMaterial *GOLD;
|
||||
static const ArmorMaterial *DIAMOND;
|
||||
class ArmorMaterial {
|
||||
public:
|
||||
static const int clothArray[];
|
||||
static const int chainArray[];
|
||||
static const int ironArray[];
|
||||
static const int goldArray[];
|
||||
static const int diamondArray[];
|
||||
|
||||
private:
|
||||
int durabilityMultiplier;
|
||||
int *slotProtections;
|
||||
int enchantmentValue;
|
||||
public:
|
||||
static const ArmorMaterial* CLOTH;
|
||||
static const ArmorMaterial* CHAIN;
|
||||
static const ArmorMaterial* IRON;
|
||||
static const ArmorMaterial* GOLD;
|
||||
static const ArmorMaterial* DIAMOND;
|
||||
|
||||
// 4J Stu - Had to make this public but was private
|
||||
// We shouldn't be creating these except the static initialisation
|
||||
public:
|
||||
ArmorMaterial(int durabilityMultiplier, const int slotProtections[], int enchantmentValue);
|
||||
~ArmorMaterial();
|
||||
private:
|
||||
int durabilityMultiplier;
|
||||
int* slotProtections;
|
||||
int enchantmentValue;
|
||||
|
||||
public:
|
||||
int getHealthForSlot(int slot) const;
|
||||
int getDefenseForSlot(int slot) const;
|
||||
int getEnchantmentValue() const;
|
||||
int getTierItemId() const;
|
||||
};
|
||||
// 4J Stu - Had to make this public but was private
|
||||
// We shouldn't be creating these except the static initialisation
|
||||
public:
|
||||
ArmorMaterial(int durabilityMultiplier, const int slotProtections[],
|
||||
int enchantmentValue);
|
||||
~ArmorMaterial();
|
||||
|
||||
const int slot;
|
||||
const int defense;
|
||||
const int modelIndex;
|
||||
public:
|
||||
int getHealthForSlot(int slot) const;
|
||||
int getDefenseForSlot(int slot) const;
|
||||
int getEnchantmentValue() const;
|
||||
int getTierItemId() const;
|
||||
};
|
||||
|
||||
const int slot;
|
||||
const int defense;
|
||||
const int modelIndex;
|
||||
|
||||
private:
|
||||
const ArmorMaterial *armorType;
|
||||
Icon *overlayIcon;
|
||||
Icon *iconEmpty;
|
||||
const ArmorMaterial* armorType;
|
||||
Icon* overlayIcon;
|
||||
Icon* iconEmpty;
|
||||
|
||||
public:
|
||||
ArmorItem(int id, const ArmorMaterial *armorType, int icon, int slot);
|
||||
ArmorItem(int id, const ArmorMaterial* armorType, int icon, int slot);
|
||||
|
||||
//@Override
|
||||
int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
//@Override
|
||||
int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
|
||||
//@Override
|
||||
bool hasMultipleSpriteLayers();
|
||||
//@Override
|
||||
bool hasMultipleSpriteLayers();
|
||||
|
||||
virtual int getEnchantmentValue();
|
||||
virtual int getEnchantmentValue();
|
||||
|
||||
const ArmorMaterial *getMaterial();
|
||||
bool hasCustomColor(std::shared_ptr<ItemInstance> item);
|
||||
int getColor(std::shared_ptr<ItemInstance> item);
|
||||
const ArmorMaterial* getMaterial();
|
||||
bool hasCustomColor(std::shared_ptr<ItemInstance> item);
|
||||
int getColor(std::shared_ptr<ItemInstance> item);
|
||||
|
||||
//@Override
|
||||
Icon *getLayerIcon(int auxValue, int spriteLayer);
|
||||
void clearColor(std::shared_ptr<ItemInstance> item);
|
||||
void setColor(std::shared_ptr<ItemInstance> item, int color);
|
||||
//@Override
|
||||
Icon* getLayerIcon(int auxValue, int spriteLayer);
|
||||
void clearColor(std::shared_ptr<ItemInstance> item);
|
||||
void setColor(std::shared_ptr<ItemInstance> item, int color);
|
||||
|
||||
bool isValidRepairItem(std::shared_ptr<ItemInstance> source, std::shared_ptr<ItemInstance> repairItem);
|
||||
bool isValidRepairItem(std::shared_ptr<ItemInstance> source,
|
||||
std::shared_ptr<ItemInstance> repairItem);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
|
||||
static Icon *getEmptyIcon(int slot);
|
||||
static Icon* getEmptyIcon(int slot);
|
||||
};
|
||||
@@ -8,52 +8,56 @@
|
||||
#include "../Stats/GenericStats.h"
|
||||
#include "BedItem.h"
|
||||
|
||||
BedItem::BedItem(int id) : Item( id )
|
||||
{
|
||||
}
|
||||
|
||||
bool BedItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (face != Facing::UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// place on top of tile
|
||||
y = y + 1;
|
||||
|
||||
BedTile *tile = (BedTile *) Tile::bed;
|
||||
|
||||
int dir = ( Mth::floor(player->yRot * 4 / (360) + 0.5f) ) & 3;
|
||||
int xra = 0;
|
||||
int zra = 0;
|
||||
|
||||
if (dir == Direction::SOUTH) zra = 1;
|
||||
if (dir == Direction::WEST) xra = -1;
|
||||
if (dir == Direction::NORTH) zra = -1;
|
||||
if (dir == Direction::EAST) xra = 1;
|
||||
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x + xra, y, z + zra)) return false;
|
||||
|
||||
if (level->isEmptyTile(x, y, z) && level->isEmptyTile(x + xra, y, z + zra) && level->isTopSolidBlocking(x, y - 1, z) && level->isTopSolidBlocking(x + xra, y - 1, z + zra))
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
level->setTileAndData(x, y, z, tile->id, dir);
|
||||
// double-check that the bed was successfully placed
|
||||
if (level->getTile(x, y, z) == tile->id)
|
||||
{
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(GenericStats::blocksPlaced(tile->id), GenericStats::param_blocksPlaced(tile->id,itemInstance->getAuxValue(),1));
|
||||
|
||||
level->setTileAndData(x + xra, y, z + zra, tile->id, dir + BedTile::HEAD_PIECE_DATA);
|
||||
}
|
||||
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
BedItem::BedItem(int id) : Item(id) {}
|
||||
|
||||
bool BedItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly) {
|
||||
if (face != Facing::UP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// place on top of tile
|
||||
y = y + 1;
|
||||
|
||||
BedTile* tile = (BedTile*)Tile::bed;
|
||||
|
||||
int dir = (Mth::floor(player->yRot * 4 / (360) + 0.5f)) & 3;
|
||||
int xra = 0;
|
||||
int zra = 0;
|
||||
|
||||
if (dir == Direction::SOUTH) zra = 1;
|
||||
if (dir == Direction::WEST) xra = -1;
|
||||
if (dir == Direction::NORTH) zra = -1;
|
||||
if (dir == Direction::EAST) xra = 1;
|
||||
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x + xra, y, z + zra))
|
||||
return false;
|
||||
|
||||
if (level->isEmptyTile(x, y, z) &&
|
||||
level->isEmptyTile(x + xra, y, z + zra) &&
|
||||
level->isTopSolidBlocking(x, y - 1, z) &&
|
||||
level->isTopSolidBlocking(x + xra, y - 1, z + zra)) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (!bTestUseOnOnly) {
|
||||
level->setTileAndData(x, y, z, tile->id, dir);
|
||||
// double-check that the bed was successfully placed
|
||||
if (level->getTile(x, y, z) == tile->id) {
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced(tile->id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
tile->id, itemInstance->getAuxValue(), 1));
|
||||
|
||||
level->setTileAndData(x + xra, y, z + zra, tile->id,
|
||||
dir + BedTile::HEAD_PIECE_DATA);
|
||||
}
|
||||
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class BedItem : public Item
|
||||
{
|
||||
|
||||
class BedItem : public Item {
|
||||
public:
|
||||
BedItem(int id);
|
||||
BedItem(int id);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
+103
-107
@@ -7,123 +7,119 @@
|
||||
#include "ItemInstance.h"
|
||||
#include "BoatItem.h"
|
||||
|
||||
BoatItem::BoatItem(int id) : Item( id )
|
||||
{
|
||||
this->maxStackSize = 1;
|
||||
BoatItem::BoatItem(int id) : Item(id) { this->maxStackSize = 1; }
|
||||
|
||||
bool BoatItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
// 4J-PB - added for tooltips to test use
|
||||
// 4J TODO really we should have the crosshair hitresult telling us if it
|
||||
// hit water, and at what distance, so we don't need to do this again if the
|
||||
// player happens to have a boat in their hand
|
||||
|
||||
float xRot = player->xRotO + (player->xRot - player->xRotO);
|
||||
float yRot = player->yRotO + (player->yRot - player->yRotO);
|
||||
|
||||
double x = player->xo + (player->x - player->xo);
|
||||
double y =
|
||||
player->yo + (player->y - player->yo) + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo);
|
||||
|
||||
Vec3* from = Vec3::newTemp(x, y, z);
|
||||
|
||||
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
|
||||
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
|
||||
|
||||
float xa = ySin * xCos;
|
||||
float ya = xSin;
|
||||
float za = yCos * xCos;
|
||||
|
||||
double range = 5;
|
||||
Vec3* to = from->add(xa * range, ya * range, za * range);
|
||||
HitResult* hr = level->clip(from, to, true);
|
||||
if (hr == NULL) return false;
|
||||
|
||||
if (hr->type == HitResult::TILE) {
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
delete hr;
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<ItemInstance> BoatItem::use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
float a = 1;
|
||||
|
||||
bool BoatItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
// 4J-PB - added for tooltips to test use
|
||||
// 4J TODO really we should have the crosshair hitresult telling us if it hit water, and at what distance, so we don't need to do this again
|
||||
// if the player happens to have a boat in their hand
|
||||
float xRot = player->xRotO + (player->xRot - player->xRotO) * a;
|
||||
float yRot = player->yRotO + (player->yRot - player->yRotO) * a;
|
||||
|
||||
float xRot = player->xRotO + (player->xRot - player->xRotO);
|
||||
float yRot = player->yRotO + (player->yRot - player->yRotO);
|
||||
double x = player->xo + (player->x - player->xo) * a;
|
||||
double y =
|
||||
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo) * a;
|
||||
|
||||
double x = player->xo + (player->x - player->xo);
|
||||
double y = player->yo + (player->y - player->yo) + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo);
|
||||
Vec3* from = Vec3::newTemp(x, y, z);
|
||||
|
||||
Vec3 *from = Vec3::newTemp(x, y, z);
|
||||
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
|
||||
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
|
||||
|
||||
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
|
||||
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
|
||||
float xa = ySin * xCos;
|
||||
float ya = xSin;
|
||||
float za = yCos * xCos;
|
||||
|
||||
float xa = ySin * xCos;
|
||||
float ya = xSin;
|
||||
float za = yCos * xCos;
|
||||
double range = 5;
|
||||
Vec3* to = from->add(xa * range, ya * range, za * range);
|
||||
HitResult* hr = level->clip(from, to, true);
|
||||
if (hr == NULL) return itemInstance;
|
||||
|
||||
double range = 5;
|
||||
Vec3 *to = from->add(xa * range, ya * range, za * range);
|
||||
HitResult *hr = level->clip(from, to, true);
|
||||
if (hr == NULL) return false;
|
||||
// check entity collision
|
||||
Vec3* b = player->getViewVector(a);
|
||||
bool hitEntity = false;
|
||||
float overlap = 1;
|
||||
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
|
||||
player,
|
||||
player->bb->expand(b->x * (range), b->y * (range), b->z * (range))
|
||||
->grow(overlap, overlap, overlap));
|
||||
// for (int i = 0; i < objects.size(); i++) {
|
||||
for (AUTO_VAR(it, objects->begin()); it != objects->end(); ++it) {
|
||||
std::shared_ptr<Entity> e = *it; // objects.get(i);
|
||||
if (!e->isPickable()) continue;
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
delete hr;
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<ItemInstance> BoatItem::use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
float a = 1;
|
||||
float rr = e->getPickRadius();
|
||||
AABB* bb = e->bb->grow(rr, rr, rr);
|
||||
if (bb->contains(from)) {
|
||||
hitEntity = true;
|
||||
}
|
||||
}
|
||||
if (hitEntity) {
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
float xRot = player->xRotO + (player->xRot - player->xRotO) * a;
|
||||
float yRot = player->yRotO + (player->yRot - player->yRotO) * a;
|
||||
if (hr->type == HitResult::TILE) {
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
|
||||
double x = player->xo + (player->x - player->xo) * a;
|
||||
double y = player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo) * a;
|
||||
if (!level->isClientSide) {
|
||||
if (level->getTile(xt, yt, zt) == Tile::topSnow_Id) yt--;
|
||||
if (level->countInstanceOf(eTYPE_BOAT, true) <
|
||||
Level::MAX_XBOX_BOATS) // 4J - added limit
|
||||
{
|
||||
level->addEntity(std::shared_ptr<Boat>(
|
||||
new Boat(level, xt + 0.5f, yt + 1.0f, zt + 0.5f)));
|
||||
if (!player->abilities.instabuild) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
} else {
|
||||
// display a message to say max boats has been hit
|
||||
player->displayClientMessage(IDS_MAX_BOATS);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
|
||||
Vec3 *from = Vec3::newTemp(x, y, z);
|
||||
|
||||
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
|
||||
float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
|
||||
float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD);
|
||||
|
||||
float xa = ySin * xCos;
|
||||
float ya = xSin;
|
||||
float za = yCos * xCos;
|
||||
|
||||
double range = 5;
|
||||
Vec3 *to = from->add(xa * range, ya * range, za * range);
|
||||
HitResult *hr = level->clip(from, to, true);
|
||||
if (hr == NULL) return itemInstance;
|
||||
|
||||
// check entity collision
|
||||
Vec3 *b = player->getViewVector(a);
|
||||
bool hitEntity = false;
|
||||
float overlap = 1;
|
||||
std::vector<std::shared_ptr<Entity> > *objects = level->getEntities(player, player->bb->expand(b->x * (range), b->y * (range), b->z * (range))->grow(overlap, overlap, overlap));
|
||||
//for (int i = 0; i < objects.size(); i++) {
|
||||
for(AUTO_VAR(it, objects->begin()); it != objects->end(); ++it)
|
||||
{
|
||||
std::shared_ptr<Entity> e = *it; //objects.get(i);
|
||||
if (!e->isPickable()) continue;
|
||||
|
||||
float rr = e->getPickRadius();
|
||||
AABB *bb = e->bb->grow(rr, rr, rr);
|
||||
if (bb->contains(from))
|
||||
{
|
||||
hitEntity = true;
|
||||
}
|
||||
}
|
||||
if (hitEntity)
|
||||
{
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
if (level->getTile(xt, yt, zt) == Tile::topSnow_Id) yt--;
|
||||
if( level->countInstanceOf(eTYPE_BOAT, true) < Level::MAX_XBOX_BOATS ) // 4J - added limit
|
||||
{
|
||||
level->addEntity( std::shared_ptr<Boat>( new Boat(level, xt + 0.5f, yt + 1.0f, zt + 0.5f) ) );
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// display a message to say max boats has been hit
|
||||
player->displayClientMessage(IDS_MAX_BOATS );
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
|
||||
return itemInstance;
|
||||
return itemInstance;
|
||||
}
|
||||
@@ -5,20 +5,20 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class BoatItem : public Item
|
||||
{
|
||||
class BoatItem : public Item {
|
||||
public:
|
||||
BoatItem(int id);
|
||||
|
||||
BoatItem(int id);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
|
||||
/*
|
||||
* public boolean useOn(ItemInstance instance, Player player, Level level,
|
||||
* int x, int y, int z, int face) { // if (face != 1) return false; int
|
||||
* targetType = level.getTile(x, y, z); if (targetType == Tile.rail.id) {
|
||||
* level.addEntity(new Minecart(level, x + 0.5f, y + 0.5f, z + 0.5f));
|
||||
* instance.count--; return true; } return false; }
|
||||
*/
|
||||
/*
|
||||
* public boolean useOn(ItemInstance instance, Player player, Level level,
|
||||
* int x, int y, int z, int face) { // if (face != 1) return false; int
|
||||
* targetType = level.getTile(x, y, z); if (targetType == Tile.rail.id) {
|
||||
* level.addEntity(new Minecart(level, x + 0.5f, y + 0.5f, z + 0.5f));
|
||||
* instance.count--; return true; } return false; }
|
||||
*/
|
||||
};
|
||||
@@ -2,16 +2,10 @@
|
||||
|
||||
#include "BookItem.h"
|
||||
|
||||
BookItem::BookItem(int id) : Item(id)
|
||||
{
|
||||
BookItem::BookItem(int id) : Item(id) {}
|
||||
|
||||
bool BookItem::isEnchantable(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return itemInstance->count == 1;
|
||||
}
|
||||
|
||||
bool BookItem::isEnchantable(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return itemInstance->count == 1;
|
||||
}
|
||||
|
||||
int BookItem::getEnchantmentValue()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int BookItem::getEnchantmentValue() { return 1; }
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class BookItem : public Item
|
||||
{
|
||||
class BookItem : public Item {
|
||||
public:
|
||||
BookItem(int id);
|
||||
BookItem(int id);
|
||||
|
||||
bool isEnchantable(std::shared_ptr<ItemInstance> itemInstance);
|
||||
int getEnchantmentValue();
|
||||
bool isEnchantable(std::shared_ptr<ItemInstance> itemInstance);
|
||||
int getEnchantmentValue();
|
||||
};
|
||||
@@ -6,94 +6,75 @@
|
||||
#include "../Headers/net.minecraft.world.item.h"
|
||||
#include "BottleItem.h"
|
||||
|
||||
BottleItem::BottleItem(int id) : Item(id)
|
||||
{
|
||||
}
|
||||
BottleItem::BottleItem(int id) : Item(id) {}
|
||||
|
||||
Icon *BottleItem::getIcon(int auxValue)
|
||||
{
|
||||
return Item::potion->getIcon(0);
|
||||
}
|
||||
Icon* BottleItem::getIcon(int auxValue) { return Item::potion->getIcon(0); }
|
||||
|
||||
std::shared_ptr<ItemInstance> BottleItem::use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
||||
if (hr == NULL) return itemInstance;
|
||||
std::shared_ptr<ItemInstance> BottleItem::use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, true);
|
||||
if (hr == NULL) return itemInstance;
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
delete hr;
|
||||
if (hr->type == HitResult::TILE) {
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
delete hr;
|
||||
|
||||
if (!level->mayInteract(player, xt, yt, zt, 0))
|
||||
{
|
||||
return itemInstance;
|
||||
}
|
||||
if (!player->mayBuild(xt, yt, zt))
|
||||
{
|
||||
return itemInstance;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water)
|
||||
{
|
||||
itemInstance->count--;
|
||||
if (itemInstance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance( (Item *)Item::potion) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>( new ItemInstance( (Item *)Item::potion) )))
|
||||
{
|
||||
player->drop( std::shared_ptr<ItemInstance>( new ItemInstance(Item::potion_Id, 1, 0) ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete hr;
|
||||
}
|
||||
if (!level->mayInteract(player, xt, yt, zt, 0)) {
|
||||
return itemInstance;
|
||||
}
|
||||
if (!player->mayBuild(xt, yt, zt)) {
|
||||
return itemInstance;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water) {
|
||||
itemInstance->count--;
|
||||
if (itemInstance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance((Item*)Item::potion));
|
||||
} else {
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance((Item*)Item::potion)))) {
|
||||
player->drop(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::potion_Id, 1, 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete hr;
|
||||
}
|
||||
|
||||
return itemInstance;
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
// 4J-PB - added to allow tooltips
|
||||
bool BottleItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
||||
if (hr == NULL) return false;
|
||||
bool BottleItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, true);
|
||||
if (hr == NULL) return false;
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
delete hr;
|
||||
if (hr->type == HitResult::TILE) {
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
delete hr;
|
||||
|
||||
if (!level->mayInteract(player, xt, yt, zt, 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!player->mayBuild(xt, yt, zt))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete hr;
|
||||
}
|
||||
if (!level->mayInteract(player, xt, yt, zt, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!player->mayBuild(xt, yt, zt)) {
|
||||
return false;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
delete hr;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void BottleItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
// We reuse another texture.
|
||||
void BottleItem::registerIcons(IconRegister* iconRegister) {
|
||||
// We reuse another texture.
|
||||
}
|
||||
@@ -4,17 +4,18 @@
|
||||
|
||||
class Icon;
|
||||
|
||||
class BottleItem : public Item
|
||||
{
|
||||
class BottleItem : public Item {
|
||||
public:
|
||||
BottleItem(int id);
|
||||
BottleItem(int id);
|
||||
|
||||
//@Override
|
||||
Icon *getIcon(int auxValue);
|
||||
//@Override
|
||||
Icon* getIcon(int auxValue);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -8,102 +8,96 @@
|
||||
#include "BowItem.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
const std::wstring BowItem::TEXTURE_PULL[] = {L"bow_pull_0", L"bow_pull_1", L"bow_pull_2"};
|
||||
const std::wstring BowItem::TEXTURE_PULL[] = {L"bow_pull_0", L"bow_pull_1",
|
||||
L"bow_pull_2"};
|
||||
|
||||
BowItem::BowItem(int id) : Item( id )
|
||||
{
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(384);
|
||||
BowItem::BowItem(int id) : Item(id) {
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(384);
|
||||
|
||||
icons = NULL;
|
||||
icons = NULL;
|
||||
}
|
||||
|
||||
void BowItem::releaseUsing(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player, int durationLeft)
|
||||
{
|
||||
bool infiniteArrows = player->abilities.instabuild || EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowInfinite->id, itemInstance) > 0;
|
||||
void BowItem::releaseUsing(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Player> player,
|
||||
int durationLeft) {
|
||||
bool infiniteArrows = player->abilities.instabuild ||
|
||||
EnchantmentHelper::getEnchantmentLevel(
|
||||
Enchantment::arrowInfinite->id, itemInstance) > 0;
|
||||
|
||||
if (infiniteArrows || player->inventory->hasResource(Item::arrow_Id))
|
||||
{
|
||||
int timeHeld = getUseDuration(itemInstance) - durationLeft;
|
||||
float pow = timeHeld / (float) MAX_DRAW_DURATION;
|
||||
pow = ((pow * pow) + pow * 2) / 3;
|
||||
if (pow < 0.1) return;
|
||||
if (pow > 1) pow = 1;
|
||||
if (infiniteArrows || player->inventory->hasResource(Item::arrow_Id)) {
|
||||
int timeHeld = getUseDuration(itemInstance) - durationLeft;
|
||||
float pow = timeHeld / (float)MAX_DRAW_DURATION;
|
||||
pow = ((pow * pow) + pow * 2) / 3;
|
||||
if (pow < 0.1) return;
|
||||
if (pow > 1) pow = 1;
|
||||
|
||||
std::shared_ptr<Arrow> arrow = std::shared_ptr<Arrow>( new Arrow(level, player, pow * 2.0f) );
|
||||
if (pow == 1) arrow->setCritArrow(true);
|
||||
int damageBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowBonus->id, itemInstance);
|
||||
if (damageBonus > 0)
|
||||
{
|
||||
arrow->setBaseDamage(arrow->getBaseDamage() + (double) damageBonus * .5 + .5);
|
||||
}
|
||||
int knockbackBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowKnockback->id, itemInstance);
|
||||
if (knockbackBonus > 0)
|
||||
{
|
||||
arrow->setKnockback(knockbackBonus);
|
||||
}
|
||||
if (EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowFire->id, itemInstance) > 0)
|
||||
{
|
||||
arrow->setOnFire(100);
|
||||
}
|
||||
itemInstance->hurt(1, player);
|
||||
std::shared_ptr<Arrow> arrow =
|
||||
std::shared_ptr<Arrow>(new Arrow(level, player, pow * 2.0f));
|
||||
if (pow == 1) arrow->setCritArrow(true);
|
||||
int damageBonus = EnchantmentHelper::getEnchantmentLevel(
|
||||
Enchantment::arrowBonus->id, itemInstance);
|
||||
if (damageBonus > 0) {
|
||||
arrow->setBaseDamage(arrow->getBaseDamage() +
|
||||
(double)damageBonus * .5 + .5);
|
||||
}
|
||||
int knockbackBonus = EnchantmentHelper::getEnchantmentLevel(
|
||||
Enchantment::arrowKnockback->id, itemInstance);
|
||||
if (knockbackBonus > 0) {
|
||||
arrow->setKnockback(knockbackBonus);
|
||||
}
|
||||
if (EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowFire->id,
|
||||
itemInstance) > 0) {
|
||||
arrow->setOnFire(100);
|
||||
}
|
||||
itemInstance->hurt(1, player);
|
||||
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 1.0f, 1 / (random->nextFloat() * 0.4f + 1.2f) + pow * 0.5f);
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 1.0f,
|
||||
1 / (random->nextFloat() * 0.4f + 1.2f) + pow * 0.5f);
|
||||
|
||||
if (infiniteArrows)
|
||||
{
|
||||
arrow->pickup = Arrow::PICKUP_CREATIVE_ONLY;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->inventory->removeResource(Item::arrow_Id);
|
||||
}
|
||||
if (!level->isClientSide) level->addEntity(arrow);
|
||||
}
|
||||
if (infiniteArrows) {
|
||||
arrow->pickup = Arrow::PICKUP_CREATIVE_ONLY;
|
||||
} else {
|
||||
player->inventory->removeResource(Item::arrow_Id);
|
||||
}
|
||||
if (!level->isClientSide) level->addEntity(arrow);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> BowItem::useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
return instance;
|
||||
std::shared_ptr<ItemInstance> BowItem::useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
int BowItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return 20 * 60 * 60;
|
||||
int BowItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return 20 * 60 * 60;
|
||||
}
|
||||
|
||||
UseAnim BowItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return UseAnim_bow;
|
||||
UseAnim BowItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return UseAnim_bow;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> BowItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (player->abilities.instabuild || player->inventory->hasResource(Item::arrow_Id))
|
||||
{
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
}
|
||||
return instance;
|
||||
std::shared_ptr<ItemInstance> BowItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (player->abilities.instabuild ||
|
||||
player->inventory->hasResource(Item::arrow_Id)) {
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
int BowItem::getEnchantmentValue()
|
||||
{
|
||||
return 1;
|
||||
int BowItem::getEnchantmentValue() { return 1; }
|
||||
|
||||
void BowItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
icons = new Icon*[BOW_ICONS_COUNT];
|
||||
|
||||
for (int i = 0; i < BOW_ICONS_COUNT; i++) {
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PULL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void BowItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
icons = new Icon *[BOW_ICONS_COUNT];
|
||||
|
||||
for (int i = 0; i < BOW_ICONS_COUNT; i++)
|
||||
{
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PULL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Icon *BowItem::getDrawnIcon(int amount)
|
||||
{
|
||||
return icons[amount];
|
||||
}
|
||||
Icon* BowItem::getDrawnIcon(int amount) { return icons[amount]; }
|
||||
@@ -5,27 +5,32 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class BowItem : public Item
|
||||
{
|
||||
class BowItem : public Item {
|
||||
public:
|
||||
static const std::wstring TEXTURE_PULL[];
|
||||
static const int MAX_DRAW_DURATION = 20 * 1;
|
||||
static const std::wstring TEXTURE_PULL[];
|
||||
static const int MAX_DRAW_DURATION = 20 * 1;
|
||||
|
||||
private:
|
||||
static const int BOW_ICONS_COUNT = 3;
|
||||
Icon **icons;
|
||||
static const int BOW_ICONS_COUNT = 3;
|
||||
Icon** icons;
|
||||
|
||||
public:
|
||||
BowItem(int id);
|
||||
BowItem(int id);
|
||||
|
||||
virtual void releaseUsing(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player, int durationLeft);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual int getEnchantmentValue();
|
||||
virtual void releaseUsing(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Player> player,
|
||||
int durationLeft);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual int getEnchantmentValue();
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
Icon *getDrawnIcon(int amount);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
Icon* getDrawnIcon(int amount);
|
||||
};
|
||||
@@ -3,14 +3,15 @@
|
||||
#include "ItemInstance.h"
|
||||
#include "BowlFoodItem.h"
|
||||
|
||||
BowlFoodItem::BowlFoodItem(int id, int nutrition) : FoodItem( id, nutrition, false )
|
||||
{
|
||||
setMaxStackSize(1);
|
||||
BowlFoodItem::BowlFoodItem(int id, int nutrition)
|
||||
: FoodItem(id, nutrition, false) {
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> BowlFoodItem::useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
FoodItem::useTimeDepleted(instance, level, player);
|
||||
std::shared_ptr<ItemInstance> BowlFoodItem::useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
FoodItem::useTimeDepleted(instance, level, player);
|
||||
|
||||
return std::shared_ptr<ItemInstance>(new ItemInstance(Item::bowl));
|
||||
return std::shared_ptr<ItemInstance>(new ItemInstance(Item::bowl));
|
||||
}
|
||||
@@ -5,10 +5,11 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class BowlFoodItem : public FoodItem
|
||||
{
|
||||
class BowlFoodItem : public FoodItem {
|
||||
public:
|
||||
BowlFoodItem(int id, int nutrition);
|
||||
BowlFoodItem(int id, int nutrition);
|
||||
|
||||
std::shared_ptr<ItemInstance> useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -18,239 +18,214 @@
|
||||
#include "../Network/Packets/ChatPacket.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
BucketItem::BucketItem(int id, int content) : Item( id )
|
||||
{
|
||||
maxStackSize = 1;
|
||||
this->content = content;
|
||||
BucketItem::BucketItem(int id, int content) : Item(id) {
|
||||
maxStackSize = 1;
|
||||
this->content = content;
|
||||
}
|
||||
|
||||
bool BucketItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
// double x = player->xo + (player->x - player->xo);
|
||||
// double y = player->yo + (player->y - player->yo) + 1.62 - player->heightOffset;
|
||||
// double z = player->zo + (player->z - player->zo);
|
||||
bool BucketItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
// double x = player->xo + (player->x - player->xo);
|
||||
// double y = player->yo + (player->y - player->yo) + 1.62 -
|
||||
// player->heightOffset; double z = player->zo + (player->z - player->zo);
|
||||
|
||||
bool pickLiquid = content == 0;
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
||||
if (hr == NULL) return false;
|
||||
bool pickLiquid = content == 0;
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
||||
if (hr == NULL) return false;
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
if (hr->type == HitResult::TILE) {
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
|
||||
if (!level->mayInteract(player, xt, yt, zt, content))
|
||||
{
|
||||
delete hr;
|
||||
return false;
|
||||
}
|
||||
if (!level->mayInteract(player, xt, yt, zt, content)) {
|
||||
delete hr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (content == 0)
|
||||
{
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0)
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::lava && level->getData(xt, yt, zt) == 0)
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (content < 0)
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hr->f == 0) yt--;
|
||||
if (hr->f == 1) yt++;
|
||||
if (hr->f == 2) zt--;
|
||||
if (hr->f == 3) zt++;
|
||||
if (hr->f == 4) xt--;
|
||||
if (hr->f == 5) xt++;
|
||||
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
if (content == 0) {
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water &&
|
||||
level->getData(xt, yt, zt) == 0) {
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::lava &&
|
||||
level->getData(xt, yt, zt) == 0) {
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
} else if (content < 0) {
|
||||
delete hr;
|
||||
return true;
|
||||
} else {
|
||||
if (hr->f == 0) yt--;
|
||||
if (hr->f == 1) yt++;
|
||||
if (hr->f == 2) zt--;
|
||||
if (hr->f == 3) zt++;
|
||||
if (hr->f == 4) xt--;
|
||||
if (hr->f == 5) xt++;
|
||||
|
||||
if (level->isEmptyTile(xt, yt, zt) || !level->getMaterial(xt, yt, zt)->isSolid())
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (content == 0)
|
||||
{
|
||||
if (hr->entity->GetType() == eTYPE_COW)
|
||||
{
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
|
||||
return false;
|
||||
if (level->isEmptyTile(xt, yt, zt) ||
|
||||
!level->getMaterial(xt, yt, zt)->isSolid()) {
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (content == 0) {
|
||||
if (hr->entity->GetType() == eTYPE_COW) {
|
||||
delete hr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> BucketItem::use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
float a = 1;
|
||||
std::shared_ptr<ItemInstance> BucketItem::use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
float a = 1;
|
||||
|
||||
double x = player->xo + (player->x - player->xo) * a;
|
||||
double y = player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo) * a;
|
||||
double x = player->xo + (player->x - player->xo) * a;
|
||||
double y =
|
||||
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
|
||||
double z = player->zo + (player->z - player->zo) * a;
|
||||
|
||||
bool pickLiquid = content == 0;
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
||||
if (hr == NULL) return itemInstance;
|
||||
bool pickLiquid = content == 0;
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
||||
if (hr == NULL) return itemInstance;
|
||||
|
||||
if (hr->type == HitResult::TILE)
|
||||
{
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
if (hr->type == HitResult::TILE) {
|
||||
int xt = hr->x;
|
||||
int yt = hr->y;
|
||||
int zt = hr->z;
|
||||
|
||||
if (!level->mayInteract(player, xt, yt, zt,content))
|
||||
{
|
||||
app.DebugPrintf("!!!!!!!!!!! Can't place that here\n");
|
||||
std::shared_ptr<ServerPlayer> servPlayer = std::dynamic_pointer_cast<ServerPlayer>(player);
|
||||
if( servPlayer != NULL )
|
||||
{
|
||||
app.DebugPrintf("Sending ChatPacket::e_ChatCannotPlaceLava to player\n");
|
||||
servPlayer->connection->send( std::shared_ptr<ChatPacket>( new ChatPacket(L"", ChatPacket::e_ChatCannotPlaceLava ) ) );
|
||||
}
|
||||
|
||||
delete hr;
|
||||
return itemInstance;
|
||||
}
|
||||
if (!level->mayInteract(player, xt, yt, zt, content)) {
|
||||
app.DebugPrintf("!!!!!!!!!!! Can't place that here\n");
|
||||
std::shared_ptr<ServerPlayer> servPlayer =
|
||||
std::dynamic_pointer_cast<ServerPlayer>(player);
|
||||
if (servPlayer != NULL) {
|
||||
app.DebugPrintf(
|
||||
"Sending ChatPacket::e_ChatCannotPlaceLava to player\n");
|
||||
servPlayer->connection->send(std::shared_ptr<ChatPacket>(
|
||||
new ChatPacket(L"", ChatPacket::e_ChatCannotPlaceLava)));
|
||||
}
|
||||
|
||||
if (content == 0)
|
||||
{
|
||||
if (!player->mayBuild(xt, yt, zt)) return itemInstance;
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0)
|
||||
{
|
||||
level->setTile(xt, yt, zt, 0);
|
||||
delete hr;
|
||||
if (player->abilities.instabuild)
|
||||
{
|
||||
return itemInstance;
|
||||
}
|
||||
delete hr;
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
if (--itemInstance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_water) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_water))))
|
||||
{
|
||||
player->drop(std::shared_ptr<ItemInstance>(new ItemInstance(Item::bucket_water_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::lava && level->getData(xt, yt, zt) == 0)
|
||||
{
|
||||
if( level->dimension->id == -1 )
|
||||
player->awardStat(
|
||||
GenericStats::netherLavaCollected(),
|
||||
GenericStats::param_noArgs()
|
||||
);
|
||||
if (content == 0) {
|
||||
if (!player->mayBuild(xt, yt, zt)) return itemInstance;
|
||||
if (level->getMaterial(xt, yt, zt) == Material::water &&
|
||||
level->getData(xt, yt, zt) == 0) {
|
||||
level->setTile(xt, yt, zt, 0);
|
||||
delete hr;
|
||||
if (player->abilities.instabuild) {
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
level->setTile(xt, yt, zt, 0);
|
||||
delete hr;
|
||||
if (player->abilities.instabuild)
|
||||
{
|
||||
return itemInstance;
|
||||
}
|
||||
if (--itemInstance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_lava) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_lava))))
|
||||
{
|
||||
player->drop(std::shared_ptr<ItemInstance>(new ItemInstance(Item::bucket_lava_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (content < 0)
|
||||
{
|
||||
delete hr;
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_empty) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hr->f == 0) yt--;
|
||||
if (hr->f == 1) yt++;
|
||||
if (hr->f == 2) zt--;
|
||||
if (hr->f == 3) zt++;
|
||||
if (hr->f == 4) xt--;
|
||||
if (hr->f == 5) xt++;
|
||||
|
||||
if (!player->mayBuild(xt, yt, zt)) return itemInstance;
|
||||
if (--itemInstance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_water));
|
||||
} else {
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_water)))) {
|
||||
player->drop(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_water_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
if (level->getMaterial(xt, yt, zt) == Material::lava &&
|
||||
level->getData(xt, yt, zt) == 0) {
|
||||
if (level->dimension->id == -1)
|
||||
player->awardStat(GenericStats::netherLavaCollected(),
|
||||
GenericStats::param_noArgs());
|
||||
|
||||
level->setTile(xt, yt, zt, 0);
|
||||
delete hr;
|
||||
if (player->abilities.instabuild) {
|
||||
return itemInstance;
|
||||
}
|
||||
if (--itemInstance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_lava));
|
||||
} else {
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_lava)))) {
|
||||
player->drop(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_lava_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
} else if (content < 0) {
|
||||
delete hr;
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_empty));
|
||||
} else {
|
||||
if (hr->f == 0) yt--;
|
||||
if (hr->f == 1) yt++;
|
||||
if (hr->f == 2) zt--;
|
||||
if (hr->f == 3) zt++;
|
||||
if (hr->f == 4) xt--;
|
||||
if (hr->f == 5) xt++;
|
||||
|
||||
if (emptyBucket(level, x, y, z, xt, yt, zt) && !player->abilities.instabuild)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_empty) );
|
||||
}
|
||||
if (!player->mayBuild(xt, yt, zt)) return itemInstance;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (content == 0)
|
||||
{
|
||||
if (hr->entity->GetType() == eTYPE_COW)
|
||||
{
|
||||
delete hr;
|
||||
if (--itemInstance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::milk) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>( new ItemInstance(Item::milk))))
|
||||
{
|
||||
player->drop(std::shared_ptr<ItemInstance>(new ItemInstance(Item::milk_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
return itemInstance;
|
||||
if (emptyBucket(level, x, y, z, xt, yt, zt) &&
|
||||
!player->abilities.instabuild) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_empty));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (content == 0) {
|
||||
if (hr->entity->GetType() == eTYPE_COW) {
|
||||
delete hr;
|
||||
if (--itemInstance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::milk));
|
||||
} else {
|
||||
if (!player->inventory->add(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::milk)))) {
|
||||
player->drop(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::milk_Id, 1, 0)));
|
||||
}
|
||||
return itemInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete hr;
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
bool BucketItem::emptyBucket(Level *level, double x, double y, double z, int xt, int yt, int zt)
|
||||
{
|
||||
bool BucketItem::emptyBucket(Level* level, double x, double y, double z, int xt,
|
||||
int yt, int zt) {
|
||||
if (content <= 0) return false;
|
||||
|
||||
if (level->isEmptyTile(xt, yt, zt) || !level->getMaterial(xt, yt, zt)->isSolid())
|
||||
{
|
||||
if (level->dimension->ultraWarm && content == Tile::water_Id)
|
||||
{
|
||||
level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, eSoundType_RANDOM_FIZZ, 0.5f, 2.6f + (level->random->nextFloat() - level->random->nextFloat()) * 0.8f);
|
||||
if (level->isEmptyTile(xt, yt, zt) ||
|
||||
!level->getMaterial(xt, yt, zt)->isSolid()) {
|
||||
if (level->dimension->ultraWarm && content == Tile::water_Id) {
|
||||
level->playSound(
|
||||
x + 0.5f, y + 0.5f, z + 0.5f, eSoundType_RANDOM_FIZZ, 0.5f,
|
||||
2.6f +
|
||||
(level->random->nextFloat() - level->random->nextFloat()) *
|
||||
0.8f);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
level->addParticle(eParticleType_largesmoke, xt + Math::random(), yt + Math::random(), zt + Math::random(), 0, 0, 0);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
level->addParticle(eParticleType_largesmoke,
|
||||
xt + Math::random(), yt + Math::random(),
|
||||
zt + Math::random(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
level->setTileAndData(xt, yt, zt, content, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,27 +5,29 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class BucketItem : public Item
|
||||
{
|
||||
class BucketItem : public Item {
|
||||
private:
|
||||
int content;
|
||||
int content;
|
||||
|
||||
public:
|
||||
BucketItem(int id, int content);
|
||||
BucketItem(int id, int content);
|
||||
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
|
||||
// TU9
|
||||
bool emptyBucket(Level *level, double x, double y, double z, int xt, int yt, int zt);
|
||||
// TU9
|
||||
bool emptyBucket(Level* level, double x, double y, double z, int xt, int yt,
|
||||
int zt);
|
||||
|
||||
/*
|
||||
* public boolean useOn(ItemInstance instance, Player player, Level level,
|
||||
* int x, int y, int z, int face) { if (content == 0) { } else { if (face ==
|
||||
* 0) y--; if (face == 1) y++; if (face == 2) z--; if (face == 3) z++; if
|
||||
* (face == 4) x--; if (face == 5) x++; int targetType = level.getTile(x, y,
|
||||
* z); if (targetType == 0) { level.setTile(x, y, z, content); }
|
||||
* player->inventory.items[player->inventory.selected] = new
|
||||
* ItemInstance(Item.bucket_empty); } return true; }
|
||||
*/
|
||||
/*
|
||||
* public boolean useOn(ItemInstance instance, Player player, Level level,
|
||||
* int x, int y, int z, int face) { if (content == 0) { } else { if (face ==
|
||||
* 0) y--; if (face == 1) y++; if (face == 2) z--; if (face == 3) z++; if
|
||||
* (face == 4) x--; if (face == 5) x++; int targetType = level.getTile(x, y,
|
||||
* z); if (targetType == 0) { level.setTile(x, y, z, content); }
|
||||
* player->inventory.items[player->inventory.selected] = new
|
||||
* ItemInstance(Item.bucket_empty); } return true; }
|
||||
*/
|
||||
};
|
||||
@@ -5,43 +5,38 @@
|
||||
#include "../Headers/net.minecraft.world.item.h"
|
||||
#include "CarrotOnAStickItem.h"
|
||||
|
||||
CarrotOnAStickItem::CarrotOnAStickItem(int id) : Item(id)
|
||||
{
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(25);
|
||||
CarrotOnAStickItem::CarrotOnAStickItem(int id) : Item(id) {
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(25);
|
||||
}
|
||||
|
||||
bool CarrotOnAStickItem::isHandEquipped()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CarrotOnAStickItem::isHandEquipped() { return true; }
|
||||
|
||||
bool CarrotOnAStickItem::isMirroredArt()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CarrotOnAStickItem::isMirroredArt() { return true; }
|
||||
|
||||
std::shared_ptr<ItemInstance> CarrotOnAStickItem::use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (player->isRiding())
|
||||
{
|
||||
std::shared_ptr<Pig> pig = std::dynamic_pointer_cast<Pig>(player->riding);
|
||||
if(pig)
|
||||
{
|
||||
if (pig->getControlGoal()->canBoost() && itemInstance->getMaxDamage() - itemInstance->getAuxValue() >= 7)
|
||||
{
|
||||
pig->getControlGoal()->boost();
|
||||
itemInstance->hurt(7, player);
|
||||
std::shared_ptr<ItemInstance> CarrotOnAStickItem::use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (player->isRiding()) {
|
||||
std::shared_ptr<Pig> pig =
|
||||
std::dynamic_pointer_cast<Pig>(player->riding);
|
||||
if (pig) {
|
||||
if (pig->getControlGoal()->canBoost() &&
|
||||
itemInstance->getMaxDamage() - itemInstance->getAuxValue() >=
|
||||
7) {
|
||||
pig->getControlGoal()->boost();
|
||||
itemInstance->hurt(7, player);
|
||||
|
||||
if (itemInstance->count == 0)
|
||||
{
|
||||
std::shared_ptr<ItemInstance> replacement = std::shared_ptr<ItemInstance>(new ItemInstance(Item::fishingRod));
|
||||
replacement->setTag(itemInstance->tag);
|
||||
return replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemInstance->count == 0) {
|
||||
std::shared_ptr<ItemInstance> replacement =
|
||||
std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::fishingRod));
|
||||
replacement->setTag(itemInstance->tag);
|
||||
return replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemInstance;
|
||||
return itemInstance;
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class CarrotOnAStickItem : public Item
|
||||
{
|
||||
class CarrotOnAStickItem : public Item {
|
||||
public:
|
||||
CarrotOnAStickItem(int id);
|
||||
CarrotOnAStickItem(int id);
|
||||
|
||||
bool isHandEquipped();
|
||||
bool isMirroredArt();
|
||||
std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
bool isHandEquipped();
|
||||
bool isMirroredArt();
|
||||
std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -5,37 +5,33 @@
|
||||
#include "../Headers/net.minecraft.world.h"
|
||||
|
||||
#ifdef __PSVITA__
|
||||
const std::wstring ClockItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {L"clockP0"};
|
||||
const std::wstring ClockItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {
|
||||
L"clockP0"};
|
||||
#else
|
||||
const std::wstring ClockItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {L"clockP0",L"clockP1",L"clockP2",L"clockP3"};
|
||||
const std::wstring ClockItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {
|
||||
L"clockP0", L"clockP1", L"clockP2", L"clockP3"};
|
||||
#endif
|
||||
|
||||
ClockItem::ClockItem(int id) : Item(id)
|
||||
{
|
||||
icons = NULL;
|
||||
ClockItem::ClockItem(int id) : Item(id) { icons = NULL; }
|
||||
|
||||
// 4J Added so that we can override the icon id used to calculate the texture
|
||||
// UV's for each player
|
||||
Icon* ClockItem::getIcon(int auxValue) {
|
||||
Icon* icon = Item::getIcon(auxValue);
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
|
||||
if (pMinecraft->player != NULL && auxValue == 0) {
|
||||
icon = icons[pMinecraft->player->GetXboxPad()];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
// 4J Added so that we can override the icon id used to calculate the texture UV's for each player
|
||||
Icon *ClockItem::getIcon(int auxValue)
|
||||
{
|
||||
Icon *icon = Item::getIcon(auxValue);
|
||||
Minecraft *pMinecraft = Minecraft::GetInstance();
|
||||
void ClockItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
if( pMinecraft->player != NULL && auxValue == 0 )
|
||||
{
|
||||
icon = icons[pMinecraft->player->GetXboxPad()];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
void ClockItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
icons = new Icon *[XUSER_MAX_COUNT];
|
||||
|
||||
for (int i = 0; i < XUSER_MAX_COUNT; i++)
|
||||
{
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PLAYER_ICON[i]);
|
||||
}
|
||||
icons = new Icon*[XUSER_MAX_COUNT];
|
||||
|
||||
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PLAYER_ICON[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
// 4J Added so that we can override the icon id used to calculate the texture UV's for each player
|
||||
// 4J Added so that we can override the icon id used to calculate the texture
|
||||
// UV's for each player
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class ClockItem : public Item
|
||||
{
|
||||
class ClockItem : public Item {
|
||||
private:
|
||||
Icon **icons;
|
||||
static const std::wstring TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT];
|
||||
Icon** icons;
|
||||
static const std::wstring TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT];
|
||||
|
||||
public:
|
||||
ClockItem(int id);
|
||||
ClockItem(int id);
|
||||
|
||||
virtual Icon *getIcon(int auxValue);
|
||||
virtual Icon* getIcon(int auxValue);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -6,17 +6,15 @@
|
||||
#include "../Headers/net.minecraft.world.entity.player.h"
|
||||
#include "CoalItem.h"
|
||||
|
||||
CoalItem::CoalItem(int id) : Item( id )
|
||||
{
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
CoalItem::CoalItem(int id) : Item(id) {
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
}
|
||||
|
||||
unsigned int CoalItem::getDescriptionId(std::shared_ptr<ItemInstance> instance)
|
||||
{
|
||||
if (instance->getAuxValue() == CHAR_COAL)
|
||||
{
|
||||
return IDS_ITEM_CHARCOAL;
|
||||
}
|
||||
return IDS_ITEM_COAL;
|
||||
unsigned int CoalItem::getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance) {
|
||||
if (instance->getAuxValue() == CHAR_COAL) {
|
||||
return IDS_ITEM_CHARCOAL;
|
||||
}
|
||||
return IDS_ITEM_COAL;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class ItemInstance;
|
||||
|
||||
class CoalItem : public Item
|
||||
{
|
||||
class CoalItem : public Item {
|
||||
public:
|
||||
static const int STONE_COAL = 0;
|
||||
static const int CHAR_COAL = 1;
|
||||
static const int STONE_COAL = 0;
|
||||
static const int CHAR_COAL = 1;
|
||||
|
||||
CoalItem(int id);
|
||||
CoalItem(int id);
|
||||
|
||||
virtual unsigned int getDescriptionId(std::shared_ptr<ItemInstance> instance);
|
||||
virtual unsigned int getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance);
|
||||
};
|
||||
@@ -5,38 +5,34 @@
|
||||
#include "../Headers/net.minecraft.world.h"
|
||||
|
||||
#ifdef __PSVITA__
|
||||
const std::wstring CompassItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {L"compassP0"};
|
||||
const std::wstring CompassItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {
|
||||
L"compassP0"};
|
||||
#else
|
||||
const std::wstring CompassItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {L"compassP0",L"compassP1",L"compassP2",L"compassP3"};
|
||||
const std::wstring CompassItem::TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT] = {
|
||||
L"compassP0", L"compassP1", L"compassP2", L"compassP3"};
|
||||
#endif
|
||||
|
||||
CompassItem::CompassItem(int id) : Item(id)
|
||||
{
|
||||
icons = NULL;
|
||||
CompassItem::CompassItem(int id) : Item(id) { icons = NULL; }
|
||||
|
||||
// 4J Added so that we can override the icon id used to calculate the texture
|
||||
// UV's for each player
|
||||
|
||||
Icon* CompassItem::getIcon(int auxValue) {
|
||||
Icon* icon = Item::getIcon(auxValue);
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
|
||||
if (pMinecraft->player != NULL && auxValue == 0) {
|
||||
icon = icons[pMinecraft->player->GetXboxPad()];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
// 4J Added so that we can override the icon id used to calculate the texture UV's for each player
|
||||
void CompassItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
Icon *CompassItem::getIcon(int auxValue)
|
||||
{
|
||||
Icon *icon = Item::getIcon(auxValue);
|
||||
Minecraft *pMinecraft = Minecraft::GetInstance();
|
||||
icons = new Icon*[XUSER_MAX_COUNT];
|
||||
|
||||
if( pMinecraft->player != NULL && auxValue == 0 )
|
||||
{
|
||||
icon = icons[pMinecraft->player->GetXboxPad()];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
void CompassItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
|
||||
icons = new Icon *[XUSER_MAX_COUNT];
|
||||
|
||||
for (int i = 0; i < XUSER_MAX_COUNT; i++)
|
||||
{
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PLAYER_ICON[i]);
|
||||
}
|
||||
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
icons[i] = iconRegister->registerIcon(TEXTURE_PLAYER_ICON[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
// 4J Added so that we can override the icon id used to calculate the texture UV's for each player
|
||||
// 4J Added so that we can override the icon id used to calculate the texture
|
||||
// UV's for each player
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class CompassItem : public Item
|
||||
{
|
||||
class CompassItem : public Item {
|
||||
private:
|
||||
Icon **icons;
|
||||
static const std::wstring TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT];
|
||||
Icon** icons;
|
||||
static const std::wstring TEXTURE_PLAYER_ICON[XUSER_MAX_COUNT];
|
||||
|
||||
public:
|
||||
CompassItem(int id);
|
||||
CompassItem(int id);
|
||||
|
||||
virtual Icon *getIcon(int auxValue);
|
||||
virtual Icon* getIcon(int auxValue);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -4,16 +4,12 @@
|
||||
#include "../Headers/net.minecraft.world.level.h"
|
||||
#include "ComplexItem.h"
|
||||
|
||||
ComplexItem::ComplexItem(int id) : Item(id)
|
||||
{
|
||||
}
|
||||
ComplexItem::ComplexItem(int id) : Item(id) {}
|
||||
|
||||
bool ComplexItem::isComplex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool ComplexItem::isComplex() { return true; }
|
||||
|
||||
std::shared_ptr<Packet> ComplexItem::getUpdatePacket(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
std::shared_ptr<Packet> ComplexItem::getUpdatePacket(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
class Packet;
|
||||
class Level;
|
||||
|
||||
class ComplexItem : public Item
|
||||
{
|
||||
class ComplexItem : public Item {
|
||||
protected:
|
||||
ComplexItem(int id);
|
||||
ComplexItem(int id);
|
||||
|
||||
public:
|
||||
virtual bool isComplex();
|
||||
virtual std::shared_ptr<Packet> getUpdatePacket(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool isComplex();
|
||||
virtual std::shared_ptr<Packet> getUpdatePacket(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
|
||||
@@ -4,61 +4,54 @@
|
||||
#include "../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "DiggerItem.h"
|
||||
|
||||
DiggerItem::DiggerItem(int id, int attackDamage, const Tier *tier, TileArray *tiles) : Item( id ), tier( tier )
|
||||
{
|
||||
//this->tier = tier;
|
||||
this->tiles = tiles;
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(tier->getUses());
|
||||
this->speed = tier->getSpeed();
|
||||
this->attackDamage = attackDamage + tier->getAttackDamageBonus();
|
||||
DiggerItem::DiggerItem(int id, int attackDamage, const Tier* tier,
|
||||
TileArray* tiles)
|
||||
: Item(id), tier(tier) {
|
||||
// this->tier = tier;
|
||||
this->tiles = tiles;
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(tier->getUses());
|
||||
this->speed = tier->getSpeed();
|
||||
this->attackDamage = attackDamage + tier->getAttackDamageBonus();
|
||||
}
|
||||
|
||||
float DiggerItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile)
|
||||
{
|
||||
for (unsigned int i = 0; i < tiles->length; i++)
|
||||
if ( (*tiles)[i] == tile) return speed;
|
||||
return 1;
|
||||
float DiggerItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile) {
|
||||
for (unsigned int i = 0; i < tiles->length; i++)
|
||||
if ((*tiles)[i] == tile) return speed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool DiggerItem::hurtEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob, std::shared_ptr<Mob> attacker)
|
||||
{
|
||||
itemInstance->hurt(2, attacker);
|
||||
return true;
|
||||
bool DiggerItem::hurtEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob,
|
||||
std::shared_ptr<Mob> attacker) {
|
||||
itemInstance->hurt(2, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DiggerItem::mineBlock(std::shared_ptr<ItemInstance> itemInstance, Level *level, int tile, int x, int y, int z, std::shared_ptr<Mob> owner)
|
||||
{
|
||||
// Don't damage tools if the tile can be destroyed in one hit.
|
||||
if (Tile::tiles[tile]->getDestroySpeed(level, x, y, z) != 0.0) itemInstance->hurt(1, owner);
|
||||
return true;
|
||||
bool DiggerItem::mineBlock(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, int tile, int x, int y, int z,
|
||||
std::shared_ptr<Mob> owner) {
|
||||
// Don't damage tools if the tile can be destroyed in one hit.
|
||||
if (Tile::tiles[tile]->getDestroySpeed(level, x, y, z) != 0.0)
|
||||
itemInstance->hurt(1, owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
int DiggerItem::getAttackDamage(std::shared_ptr<Entity> entity)
|
||||
{
|
||||
return attackDamage;
|
||||
int DiggerItem::getAttackDamage(std::shared_ptr<Entity> entity) {
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
bool DiggerItem::isHandEquipped()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool DiggerItem::isHandEquipped() { return true; }
|
||||
|
||||
int DiggerItem::getEnchantmentValue()
|
||||
{
|
||||
return tier->getEnchantmentValue();
|
||||
}
|
||||
int DiggerItem::getEnchantmentValue() { return tier->getEnchantmentValue(); }
|
||||
|
||||
const Item::Tier *DiggerItem::getTier()
|
||||
{
|
||||
return tier;
|
||||
}
|
||||
const Item::Tier* DiggerItem::getTier() { return tier; }
|
||||
|
||||
bool DiggerItem::isValidRepairItem(std::shared_ptr<ItemInstance> source, std::shared_ptr<ItemInstance> repairItem)
|
||||
{
|
||||
if (tier->getTierItemId() == repairItem->id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Item::isValidRepairItem(source, repairItem);
|
||||
bool DiggerItem::isValidRepairItem(std::shared_ptr<ItemInstance> source,
|
||||
std::shared_ptr<ItemInstance> repairItem) {
|
||||
if (tier->getTierItemId() == repairItem->id) {
|
||||
return true;
|
||||
}
|
||||
return Item::isValidRepairItem(source, repairItem);
|
||||
}
|
||||
@@ -4,28 +4,35 @@
|
||||
|
||||
class Mob;
|
||||
|
||||
class DiggerItem : public Item
|
||||
{
|
||||
class DiggerItem : public Item {
|
||||
private:
|
||||
TileArray *tiles;
|
||||
protected:
|
||||
float speed;
|
||||
private:
|
||||
int attackDamage;
|
||||
TileArray* tiles;
|
||||
|
||||
protected:
|
||||
const Tier *tier;
|
||||
float speed;
|
||||
|
||||
DiggerItem(int id, int attackDamage, const Tier *tier, TileArray *tiles);
|
||||
private:
|
||||
int attackDamage;
|
||||
|
||||
protected:
|
||||
const Tier* tier;
|
||||
|
||||
DiggerItem(int id, int attackDamage, const Tier* tier, TileArray* tiles);
|
||||
|
||||
public:
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile);
|
||||
virtual bool hurtEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob, std::shared_ptr<Mob> attacker);
|
||||
virtual bool mineBlock(std::shared_ptr<ItemInstance> itemInstance, Level *level, int tile, int x, int y, int z, std::shared_ptr<Mob> owner);
|
||||
virtual int getAttackDamage(std::shared_ptr<Entity> entity);
|
||||
virtual bool isHandEquipped();
|
||||
virtual int getEnchantmentValue();
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile);
|
||||
virtual bool hurtEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob,
|
||||
std::shared_ptr<Mob> attacker);
|
||||
virtual bool mineBlock(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, int tile, int x, int y, int z,
|
||||
std::shared_ptr<Mob> owner);
|
||||
virtual int getAttackDamage(std::shared_ptr<Entity> entity);
|
||||
virtual bool isHandEquipped();
|
||||
virtual int getEnchantmentValue();
|
||||
|
||||
const Tier *getTier();
|
||||
bool isValidRepairItem(std::shared_ptr<ItemInstance> source, std::shared_ptr<ItemInstance> repairItem);
|
||||
const Tier* getTier();
|
||||
bool isValidRepairItem(std::shared_ptr<ItemInstance> source,
|
||||
std::shared_ptr<ItemInstance> repairItem);
|
||||
};
|
||||
@@ -12,64 +12,74 @@
|
||||
#include "../Stats/GenericStats.h"
|
||||
#include "DoorItem.h"
|
||||
|
||||
DoorItem::DoorItem(int id, Material *material) : Item(id)
|
||||
{
|
||||
this->material = material;
|
||||
maxStackSize = 1;
|
||||
DoorItem::DoorItem(int id, Material* material) : Item(id) {
|
||||
this->material = material;
|
||||
maxStackSize = 1;
|
||||
}
|
||||
|
||||
bool DoorItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (face != Facing::UP) return false;
|
||||
y++;
|
||||
bool DoorItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly) {
|
||||
if (face != Facing::UP) return false;
|
||||
y++;
|
||||
|
||||
Tile *tile;
|
||||
Tile* tile;
|
||||
|
||||
if (material == Material::wood) tile = Tile::door_wood;
|
||||
else tile = Tile::door_iron;
|
||||
if (material == Material::wood)
|
||||
tile = Tile::door_wood;
|
||||
else
|
||||
tile = Tile::door_iron;
|
||||
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z)) return false;
|
||||
if (!tile->mayPlace(level, x, y, z)) return false;
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z))
|
||||
return false;
|
||||
if (!tile->mayPlace(level, x, y, z)) return false;
|
||||
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if(bTestUseOnOnly) return true;
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (bTestUseOnOnly) return true;
|
||||
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(GenericStats::blocksPlaced(tile->id),GenericStats::param_blocksPlaced(tile->id,instance->getAuxValue(),1));
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced(tile->id),
|
||||
GenericStats::param_blocksPlaced(tile->id, instance->getAuxValue(), 1));
|
||||
|
||||
int dir = Mth::floor(((player->yRot + 180) * 4) / 360 - 0.5) & 3;
|
||||
place(level, x, y, z, dir, tile);
|
||||
int dir = Mth::floor(((player->yRot + 180) * 4) / 360 - 0.5) & 3;
|
||||
place(level, x, y, z, dir, tile);
|
||||
|
||||
instance->count--;
|
||||
return true;
|
||||
instance->count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DoorItem::place(Level *level, int x, int y, int z, int dir, Tile *tile)
|
||||
{
|
||||
void DoorItem::place(Level* level, int x, int y, int z, int dir, Tile* tile) {
|
||||
int xra = 0;
|
||||
int zra = 0;
|
||||
if (dir == 0) zra = +1;
|
||||
if (dir == 1) xra = -1;
|
||||
if (dir == 2) zra = -1;
|
||||
if (dir == 3) xra = +1;
|
||||
|
||||
int xra = 0;
|
||||
int zra = 0;
|
||||
if (dir == 0) zra = +1;
|
||||
if (dir == 1) xra = -1;
|
||||
if (dir == 2) zra = -1;
|
||||
if (dir == 3) xra = +1;
|
||||
int solidLeft =
|
||||
(level->isSolidBlockingTile(x - xra, y, z - zra) ? 1 : 0) +
|
||||
(level->isSolidBlockingTile(x - xra, y + 1, z - zra) ? 1 : 0);
|
||||
int solidRight =
|
||||
(level->isSolidBlockingTile(x + xra, y, z + zra) ? 1 : 0) +
|
||||
(level->isSolidBlockingTile(x + xra, y + 1, z + zra) ? 1 : 0);
|
||||
|
||||
bool doorLeft = (level->getTile(x - xra, y, z - zra) == tile->id) ||
|
||||
(level->getTile(x - xra, y + 1, z - zra) == tile->id);
|
||||
bool doorRight = (level->getTile(x + xra, y, z + zra) == tile->id) ||
|
||||
(level->getTile(x + xra, y + 1, z + zra) == tile->id);
|
||||
|
||||
int solidLeft = (level->isSolidBlockingTile(x - xra, y, z - zra) ? 1 : 0) + (level->isSolidBlockingTile(x - xra, y + 1, z - zra) ? 1 : 0);
|
||||
int solidRight = (level->isSolidBlockingTile(x + xra, y, z + zra) ? 1 : 0) + (level->isSolidBlockingTile(x + xra, y + 1, z + zra) ? 1 : 0);
|
||||
bool flip = false;
|
||||
if (doorLeft && !doorRight)
|
||||
flip = true;
|
||||
else if (solidRight > solidLeft)
|
||||
flip = true;
|
||||
|
||||
bool doorLeft = (level->getTile(x - xra, y, z - zra) == tile->id) || (level->getTile(x - xra, y + 1, z - zra) == tile->id);
|
||||
bool doorRight = (level->getTile(x + xra, y, z + zra) == tile->id) || (level->getTile(x + xra, y + 1, z + zra) == tile->id);
|
||||
|
||||
bool flip = false;
|
||||
if (doorLeft && !doorRight) flip = true;
|
||||
else if (solidRight > solidLeft) flip = true;
|
||||
|
||||
level->noNeighborUpdate = true;
|
||||
level->setTileAndData(x, y, z, tile->id, dir);
|
||||
level->setTileAndData(x, y + 1, z, tile->id, 8 | (flip ? 1 : 0));
|
||||
level->noNeighborUpdate = false;
|
||||
level->updateNeighborsAt(x, y, z, tile->id);
|
||||
level->updateNeighborsAt(x, y + 1, z, tile->id);
|
||||
level->noNeighborUpdate = true;
|
||||
level->setTileAndData(x, y, z, tile->id, dir);
|
||||
level->setTileAndData(x, y + 1, z, tile->id, 8 | (flip ? 1 : 0));
|
||||
level->noNeighborUpdate = false;
|
||||
level->updateNeighborsAt(x, y, z, tile->id);
|
||||
level->updateNeighborsAt(x, y + 1, z, tile->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
class Material;
|
||||
class Level;
|
||||
|
||||
class DoorItem : public Item
|
||||
{
|
||||
class DoorItem : public Item {
|
||||
private:
|
||||
Material *material;
|
||||
Material* material;
|
||||
|
||||
public:
|
||||
DoorItem(int id, Material *material);
|
||||
DoorItem(int id, Material* material);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
static void place(Level *level, int x, int y, int z, int dir, Tile *tile);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
static void place(Level* level, int x, int y, int z, int dir, Tile* tile);
|
||||
};
|
||||
|
||||
@@ -14,76 +14,42 @@
|
||||
#include "../Blocks/Material.h"
|
||||
#include "DyePowderItem.h"
|
||||
|
||||
DyePowderItem::DyePowderItem(int id) : Item( id )
|
||||
{
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
icons = NULL;
|
||||
DyePowderItem::DyePowderItem(int id) : Item(id) {
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
icons = NULL;
|
||||
}
|
||||
|
||||
const unsigned int DyePowderItem::COLOR_DESCS[] =
|
||||
{
|
||||
IDS_ITEM_DYE_POWDER_BLACK,
|
||||
IDS_ITEM_DYE_POWDER_RED,
|
||||
IDS_ITEM_DYE_POWDER_GREEN,
|
||||
IDS_ITEM_DYE_POWDER_BROWN,
|
||||
IDS_ITEM_DYE_POWDER_BLUE,
|
||||
IDS_ITEM_DYE_POWDER_PURPLE,
|
||||
IDS_ITEM_DYE_POWDER_CYAN,
|
||||
IDS_ITEM_DYE_POWDER_SILVER,
|
||||
IDS_ITEM_DYE_POWDER_GRAY,
|
||||
IDS_ITEM_DYE_POWDER_PINK,
|
||||
IDS_ITEM_DYE_POWDER_LIME,
|
||||
IDS_ITEM_DYE_POWDER_YELLOW,
|
||||
IDS_ITEM_DYE_POWDER_LIGHT_BLUE,
|
||||
IDS_ITEM_DYE_POWDER_MAGENTA,
|
||||
IDS_ITEM_DYE_POWDER_ORANGE,
|
||||
IDS_ITEM_DYE_POWDER_WHITE
|
||||
};
|
||||
const unsigned int DyePowderItem::COLOR_DESCS[] = {
|
||||
IDS_ITEM_DYE_POWDER_BLACK, IDS_ITEM_DYE_POWDER_RED,
|
||||
IDS_ITEM_DYE_POWDER_GREEN, IDS_ITEM_DYE_POWDER_BROWN,
|
||||
IDS_ITEM_DYE_POWDER_BLUE, IDS_ITEM_DYE_POWDER_PURPLE,
|
||||
IDS_ITEM_DYE_POWDER_CYAN, IDS_ITEM_DYE_POWDER_SILVER,
|
||||
IDS_ITEM_DYE_POWDER_GRAY, IDS_ITEM_DYE_POWDER_PINK,
|
||||
IDS_ITEM_DYE_POWDER_LIME, IDS_ITEM_DYE_POWDER_YELLOW,
|
||||
IDS_ITEM_DYE_POWDER_LIGHT_BLUE, IDS_ITEM_DYE_POWDER_MAGENTA,
|
||||
IDS_ITEM_DYE_POWDER_ORANGE, IDS_ITEM_DYE_POWDER_WHITE};
|
||||
|
||||
const unsigned int DyePowderItem::COLOR_USE_DESCS[] =
|
||||
{
|
||||
IDS_DESC_DYE_BLACK,
|
||||
IDS_DESC_DYE_RED,
|
||||
IDS_DESC_DYE_GREEN,
|
||||
IDS_DESC_DYE_BROWN,
|
||||
IDS_DESC_DYE_BLUE,
|
||||
IDS_DESC_DYE_PURPLE,
|
||||
IDS_DESC_DYE_CYAN,
|
||||
IDS_DESC_DYE_LIGHTGRAY,
|
||||
IDS_DESC_DYE_GRAY,
|
||||
IDS_DESC_DYE_PINK,
|
||||
IDS_DESC_DYE_LIME,
|
||||
IDS_DESC_DYE_YELLOW,
|
||||
IDS_DESC_DYE_LIGHTBLUE,
|
||||
IDS_DESC_DYE_MAGENTA,
|
||||
IDS_DESC_DYE_ORANGE,
|
||||
IDS_DESC_DYE_WHITE
|
||||
};
|
||||
const unsigned int DyePowderItem::COLOR_USE_DESCS[] = {
|
||||
IDS_DESC_DYE_BLACK, IDS_DESC_DYE_RED, IDS_DESC_DYE_GREEN,
|
||||
IDS_DESC_DYE_BROWN, IDS_DESC_DYE_BLUE, IDS_DESC_DYE_PURPLE,
|
||||
IDS_DESC_DYE_CYAN, IDS_DESC_DYE_LIGHTGRAY, IDS_DESC_DYE_GRAY,
|
||||
IDS_DESC_DYE_PINK, IDS_DESC_DYE_LIME, IDS_DESC_DYE_YELLOW,
|
||||
IDS_DESC_DYE_LIGHTBLUE, IDS_DESC_DYE_MAGENTA, IDS_DESC_DYE_ORANGE,
|
||||
IDS_DESC_DYE_WHITE};
|
||||
|
||||
const std::wstring DyePowderItem::COLOR_TEXTURES[] =
|
||||
{ L"dyePowder_black", L"dyePowder_red", L"dyePowder_green", L"dyePowder_brown", L"dyePowder_blue", L"dyePowder_purple", L"dyePowder_cyan", L"dyePowder_silver", L"dyePowder_gray", L"dyePowder_pink",
|
||||
L"dyePowder_lime", L"dyePowder_yellow", L"dyePowder_lightBlue", L"dyePowder_magenta", L"dyePowder_orange", L"dyePowder_white"};
|
||||
const std::wstring DyePowderItem::COLOR_TEXTURES[] = {
|
||||
L"dyePowder_black", L"dyePowder_red", L"dyePowder_green",
|
||||
L"dyePowder_brown", L"dyePowder_blue", L"dyePowder_purple",
|
||||
L"dyePowder_cyan", L"dyePowder_silver", L"dyePowder_gray",
|
||||
L"dyePowder_pink", L"dyePowder_lime", L"dyePowder_yellow",
|
||||
L"dyePowder_lightBlue", L"dyePowder_magenta", L"dyePowder_orange",
|
||||
L"dyePowder_white"};
|
||||
|
||||
const int DyePowderItem::COLOR_RGB[] =
|
||||
{
|
||||
0x1e1b1b,
|
||||
0xb3312c,
|
||||
0x3b511a,
|
||||
0x51301a,
|
||||
0x253192,
|
||||
0x7b2fbe,
|
||||
0xababab,
|
||||
0x287697,
|
||||
0x434343,
|
||||
0xd88198,
|
||||
0x41cd34,
|
||||
0xdecf2a,
|
||||
0x6689d3,
|
||||
0xc354cd,
|
||||
0xeb8844,
|
||||
0xf0f0f0
|
||||
};
|
||||
const int DyePowderItem::COLOR_RGB[] = {0x1e1b1b, 0xb3312c, 0x3b511a, 0x51301a,
|
||||
0x253192, 0x7b2fbe, 0xababab, 0x287697,
|
||||
0x434343, 0xd88198, 0x41cd34, 0xdecf2a,
|
||||
0x6689d3, 0xc354cd, 0xeb8844, 0xf0f0f0};
|
||||
|
||||
const int DyePowderItem::BLACK = 0;
|
||||
const int DyePowderItem::RED = 1;
|
||||
@@ -102,216 +68,189 @@ const int DyePowderItem::MAGENTA = 13;
|
||||
const int DyePowderItem::ORANGE = 14;
|
||||
const int DyePowderItem::WHITE = 15;
|
||||
|
||||
Icon *DyePowderItem::getIcon(int itemAuxValue)
|
||||
{
|
||||
int colorValue = Mth::clamp(itemAuxValue, 0, 15);
|
||||
return icons[colorValue];
|
||||
Icon* DyePowderItem::getIcon(int itemAuxValue) {
|
||||
int colorValue = Mth::clamp(itemAuxValue, 0, 15);
|
||||
return icons[colorValue];
|
||||
}
|
||||
|
||||
unsigned int DyePowderItem::getDescriptionId(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
int colorValue = Mth::clamp(itemInstance->getAuxValue(), 0, 15);
|
||||
return COLOR_DESCS[colorValue];
|
||||
unsigned int DyePowderItem::getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
int colorValue = Mth::clamp(itemInstance->getAuxValue(), 0, 15);
|
||||
return COLOR_DESCS[colorValue];
|
||||
}
|
||||
|
||||
unsigned int DyePowderItem::getUseDescriptionId(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return COLOR_USE_DESCS[itemInstance->getAuxValue()];
|
||||
unsigned int DyePowderItem::getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return COLOR_USE_DESCS[itemInstance->getAuxValue()];
|
||||
}
|
||||
|
||||
bool DyePowderItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
bool DyePowderItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (itemInstance->getAuxValue() == WHITE)
|
||||
{
|
||||
// bone meal is a fertilizer, so instantly grow trees and stuff
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (itemInstance->getAuxValue() == WHITE) {
|
||||
// bone meal is a fertilizer, so instantly grow trees and stuff
|
||||
|
||||
int tile = level->getTile(x, y, z);
|
||||
if (tile == Tile::sapling_Id)
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
((Sapling *) Tile::sapling)->growTree(level, x, y, z, level->random);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::mushroom1_Id || tile == Tile::mushroom2_Id)
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
if (((Mushroom *) Tile::tiles[tile])->growTree(level, x, y, z, level->random))
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id)
|
||||
{
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
((StemTile *) Tile::tiles[tile])->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::carrots_Id || tile == Tile::potatoes_Id)
|
||||
{
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
((CropTile *) Tile::tiles[tile])->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::crops_Id)
|
||||
{
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
((CropTile *) Tile::crops)->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::cocoa_Id)
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
level->setData(x, y, z, (2 << 2) | DirectionalTile::getDirection(level->getData(x, y, z)));
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (tile == Tile::grass_Id)
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
itemInstance->count--;
|
||||
int tile = level->getTile(x, y, z);
|
||||
if (tile == Tile::sapling_Id) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
((Sapling*)Tile::sapling)
|
||||
->growTree(level, x, y, z, level->random);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::mushroom1_Id || tile == Tile::mushroom2_Id) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
if (((Mushroom*)Tile::tiles[tile])
|
||||
->growTree(level, x, y, z, level->random)) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id) {
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
((StemTile*)Tile::tiles[tile])
|
||||
->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::carrots_Id || tile == Tile::potatoes_Id) {
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
((CropTile*)Tile::tiles[tile])
|
||||
->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::crops_Id) {
|
||||
if (level->getData(x, y, z) == 7) return false;
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
((CropTile*)Tile::crops)->growCropsToMax(level, x, y, z);
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::cocoa_Id) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
level->setData(x, y, z,
|
||||
(2 << 2) | DirectionalTile::getDirection(
|
||||
level->getData(x, y, z)));
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (tile == Tile::grass_Id) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
itemInstance->count--;
|
||||
|
||||
for (int j = 0; j < 128; j++)
|
||||
{
|
||||
int xx = x;
|
||||
int yy = y + 1;
|
||||
int zz = z;
|
||||
for (int i = 0; i < j / 16; i++)
|
||||
{
|
||||
xx += random->nextInt(3) - 1;
|
||||
yy += (random->nextInt(3) - 1) * random->nextInt(3) / 2;
|
||||
zz += random->nextInt(3) - 1;
|
||||
if (level->getTile(xx, yy - 1, zz) != Tile::grass_Id || level->isSolidBlockingTile(xx, yy, zz))
|
||||
{
|
||||
goto mainloop;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 128; j++) {
|
||||
int xx = x;
|
||||
int yy = y + 1;
|
||||
int zz = z;
|
||||
for (int i = 0; i < j / 16; i++) {
|
||||
xx += random->nextInt(3) - 1;
|
||||
yy += (random->nextInt(3) - 1) *
|
||||
random->nextInt(3) / 2;
|
||||
zz += random->nextInt(3) - 1;
|
||||
if (level->getTile(xx, yy - 1, zz) !=
|
||||
Tile::grass_Id ||
|
||||
level->isSolidBlockingTile(xx, yy, zz)) {
|
||||
goto mainloop;
|
||||
}
|
||||
}
|
||||
|
||||
if (level->getTile(xx, yy, zz) == 0)
|
||||
{
|
||||
if (random->nextInt(10) != 0)
|
||||
{
|
||||
if (Tile::tallgrass->canSurvive(level, xx, yy, zz)) level->setTileAndData(xx, yy, zz, Tile::tallgrass_Id, TallGrass::TALL_GRASS);
|
||||
}
|
||||
else if (random->nextInt(3) != 0)
|
||||
{
|
||||
if (Tile::flower->canSurvive(level, xx, yy, zz)) level->setTile(xx, yy, zz, Tile::flower_Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Tile::rose->canSurvive(level, xx, yy, zz)) level->setTile(xx, yy, zz, Tile::rose_Id);
|
||||
}
|
||||
}
|
||||
if (level->getTile(xx, yy, zz) == 0) {
|
||||
if (random->nextInt(10) != 0) {
|
||||
if (Tile::tallgrass->canSurvive(level, xx, yy,
|
||||
zz))
|
||||
level->setTileAndData(
|
||||
xx, yy, zz, Tile::tallgrass_Id,
|
||||
TallGrass::TALL_GRASS);
|
||||
} else if (random->nextInt(3) != 0) {
|
||||
if (Tile::flower->canSurvive(level, xx, yy, zz))
|
||||
level->setTile(xx, yy, zz, Tile::flower_Id);
|
||||
} else {
|
||||
if (Tile::rose->canSurvive(level, xx, yy, zz))
|
||||
level->setTile(xx, yy, zz, Tile::rose_Id);
|
||||
}
|
||||
}
|
||||
|
||||
// 4J - Stops infinite loops.
|
||||
mainloop: continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 4J - Stops infinite loops.
|
||||
mainloop:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (itemInstance->getAuxValue() == BROWN)
|
||||
{
|
||||
// plant cocoa
|
||||
return true;
|
||||
}
|
||||
} else if (itemInstance->getAuxValue() == BROWN) {
|
||||
// plant cocoa
|
||||
|
||||
int tile = level->getTile(x, y, z);
|
||||
int data = level->getData(x, y, z);
|
||||
int tile = level->getTile(x, y, z);
|
||||
int data = level->getData(x, y, z);
|
||||
|
||||
if (tile == Tile::treeTrunk_Id && TreeTile::getWoodType(data) == TreeTile::JUNGLE_TRUNK)
|
||||
{
|
||||
if (face == 0) return false;
|
||||
if (face == 1) return false;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
if (tile == Tile::treeTrunk_Id &&
|
||||
TreeTile::getWoodType(data) == TreeTile::JUNGLE_TRUNK) {
|
||||
if (face == 0) return false;
|
||||
if (face == 1) return false;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (level->isEmptyTile(x, y, z))
|
||||
{
|
||||
int cocoaData = Tile::tiles[Tile::cocoa_Id]->getPlacedOnFaceDataValue(level, x, y, z, face, clickX, clickY, clickZ, 0);
|
||||
level->setTileAndData(x, y, z, Tile::cocoa_Id, cocoaData);
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (!bTestUseOnOnly) {
|
||||
if (level->isEmptyTile(x, y, z)) {
|
||||
int cocoaData =
|
||||
Tile::tiles[Tile::cocoa_Id]->getPlacedOnFaceDataValue(
|
||||
level, x, y, z, face, clickX, clickY, clickZ, 0);
|
||||
level->setTileAndData(x, y, z, Tile::cocoa_Id, cocoaData);
|
||||
if (!player->abilities.instabuild) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DyePowderItem::interactEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob)
|
||||
{
|
||||
if (std::dynamic_pointer_cast<Sheep>( mob ) != NULL)
|
||||
{
|
||||
std::shared_ptr<Sheep> sheep = std::dynamic_pointer_cast<Sheep>(mob);
|
||||
// convert to tile-based color value (0 is white instead of black)
|
||||
int newColor = ClothTile::getTileDataForItemAuxValue(itemInstance->getAuxValue());
|
||||
if (!sheep->isSheared() && sheep->getColor() != newColor)
|
||||
{
|
||||
sheep->setColor(newColor);
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
bool DyePowderItem::interactEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob) {
|
||||
if (std::dynamic_pointer_cast<Sheep>(mob) != NULL) {
|
||||
std::shared_ptr<Sheep> sheep = std::dynamic_pointer_cast<Sheep>(mob);
|
||||
// convert to tile-based color value (0 is white instead of black)
|
||||
int newColor =
|
||||
ClothTile::getTileDataForItemAuxValue(itemInstance->getAuxValue());
|
||||
if (!sheep->isSheared() && sheep->getColor() != newColor) {
|
||||
sheep->setColor(newColor);
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DyePowderItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
icons = new Icon *[DYE_POWDER_ITEM_TEXTURE_COUNT];
|
||||
void DyePowderItem::registerIcons(IconRegister* iconRegister) {
|
||||
icons = new Icon*[DYE_POWDER_ITEM_TEXTURE_COUNT];
|
||||
|
||||
for (int i = 0; i < DYE_POWDER_ITEM_TEXTURE_COUNT; i++)
|
||||
{
|
||||
icons[i] = iconRegister->registerIcon(COLOR_TEXTURES[i]);
|
||||
}
|
||||
for (int i = 0; i < DYE_POWDER_ITEM_TEXTURE_COUNT; i++) {
|
||||
icons[i] = iconRegister->registerIcon(COLOR_TEXTURES[i]);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
class Mob;
|
||||
class Level;
|
||||
|
||||
class DyePowderItem : public Item
|
||||
{
|
||||
class DyePowderItem : public Item {
|
||||
public:
|
||||
static const unsigned int COLOR_DESCS[];
|
||||
static const unsigned int COLOR_USE_DESCS[];
|
||||
static const std::wstring COLOR_TEXTURES[];
|
||||
static const int COLOR_RGB[];
|
||||
static const unsigned int COLOR_DESCS[];
|
||||
static const unsigned int COLOR_USE_DESCS[];
|
||||
static const std::wstring COLOR_TEXTURES[];
|
||||
static const int COLOR_RGB[];
|
||||
|
||||
static const int BLACK;
|
||||
static const int RED;
|
||||
static const int GREEN;
|
||||
static const int BROWN;
|
||||
static const int BLUE;
|
||||
static const int PURPLE;
|
||||
static const int CYAN;
|
||||
static const int SILVER;
|
||||
static const int GRAY;
|
||||
static const int PINK;
|
||||
static const int LIME;
|
||||
static const int YELLOW;
|
||||
static const int LIGHT_BLUE;
|
||||
static const int MAGENTA;
|
||||
static const int ORANGE;
|
||||
static const int WHITE;
|
||||
static const int BLACK;
|
||||
static const int RED;
|
||||
static const int GREEN;
|
||||
static const int BROWN;
|
||||
static const int BLUE;
|
||||
static const int PURPLE;
|
||||
static const int CYAN;
|
||||
static const int SILVER;
|
||||
static const int GRAY;
|
||||
static const int PINK;
|
||||
static const int LIME;
|
||||
static const int YELLOW;
|
||||
static const int LIGHT_BLUE;
|
||||
static const int MAGENTA;
|
||||
static const int ORANGE;
|
||||
static const int WHITE;
|
||||
|
||||
private:
|
||||
static const int DYE_POWDER_ITEM_TEXTURE_COUNT = 16;
|
||||
Icon **icons;
|
||||
static const int DYE_POWDER_ITEM_TEXTURE_COUNT = 16;
|
||||
Icon** icons;
|
||||
|
||||
public:
|
||||
DyePowderItem(int id);
|
||||
DyePowderItem(int id);
|
||||
|
||||
virtual Icon *getIcon(int itemAuxValue);
|
||||
virtual unsigned int getDescriptionId(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual unsigned int getUseDescriptionId(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool interactEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob);
|
||||
virtual Icon* getIcon(int itemAuxValue);
|
||||
virtual unsigned int getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual unsigned int getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
virtual bool interactEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
|
||||
@@ -13,19 +13,19 @@
|
||||
#include "EggItem.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
EggItem::EggItem(int id) : Item(id) { this->maxStackSize = 16; }
|
||||
|
||||
EggItem::EggItem(int id) : Item( id )
|
||||
{
|
||||
this->maxStackSize = 16;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EggItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
level->playSound( std::dynamic_pointer_cast<Entity>(player), eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) level->addEntity( std::shared_ptr<ThrownEgg>( new ThrownEgg(level, std::dynamic_pointer_cast<Mob>( player )) ));
|
||||
std::shared_ptr<ItemInstance> EggItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (!player->abilities.instabuild) {
|
||||
instance->count--;
|
||||
}
|
||||
level->playSound(std::dynamic_pointer_cast<Entity>(player),
|
||||
eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
level->addEntity(std::shared_ptr<ThrownEgg>(
|
||||
new ThrownEgg(level, std::dynamic_pointer_cast<Mob>(player))));
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class EggItem : public Item
|
||||
{
|
||||
class EggItem : public Item {
|
||||
public:
|
||||
EggItem(int id);
|
||||
EggItem(int id);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
|
||||
@@ -4,141 +4,150 @@
|
||||
#include "../Util/WeighedTreasure.h"
|
||||
#include "EnchantedBookItem.h"
|
||||
|
||||
const std::wstring EnchantedBookItem::TAG_STORED_ENCHANTMENTS = L"StoredEnchantments";
|
||||
const std::wstring EnchantedBookItem::TAG_STORED_ENCHANTMENTS =
|
||||
L"StoredEnchantments";
|
||||
|
||||
EnchantedBookItem::EnchantedBookItem(int id) : Item(id)
|
||||
{
|
||||
EnchantedBookItem::EnchantedBookItem(int id) : Item(id) {}
|
||||
|
||||
bool EnchantedBookItem::isFoil(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnchantedBookItem::isFoil(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return true;
|
||||
bool EnchantedBookItem::isEnchantable(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EnchantedBookItem::isEnchantable(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return false;
|
||||
const Rarity* EnchantedBookItem::getRarity(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
ListTag<CompoundTag>* enchantments = getEnchantments(itemInstance);
|
||||
if (enchantments && enchantments->size() > 0) {
|
||||
return Rarity::uncommon;
|
||||
} else {
|
||||
return Item::getRarity(itemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
const Rarity *EnchantedBookItem::getRarity(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
ListTag<CompoundTag> *enchantments = getEnchantments(itemInstance);
|
||||
if (enchantments && enchantments->size() > 0)
|
||||
{
|
||||
return Rarity::uncommon;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Item::getRarity(itemInstance);
|
||||
}
|
||||
ListTag<CompoundTag>* EnchantedBookItem::getEnchantments(
|
||||
std::shared_ptr<ItemInstance> item) {
|
||||
if (item->tag == NULL ||
|
||||
!item->tag->contains((wchar_t*)TAG_STORED_ENCHANTMENTS.c_str())) {
|
||||
return new ListTag<CompoundTag>();
|
||||
}
|
||||
|
||||
return (ListTag<CompoundTag>*)item->tag->get(
|
||||
(wchar_t*)TAG_STORED_ENCHANTMENTS.c_str());
|
||||
}
|
||||
|
||||
ListTag<CompoundTag> *EnchantedBookItem::getEnchantments(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
if (item->tag == NULL || !item->tag->contains((wchar_t *)TAG_STORED_ENCHANTMENTS.c_str()))
|
||||
{
|
||||
return new ListTag<CompoundTag>();
|
||||
}
|
||||
void EnchantedBookItem::appendHoverText(
|
||||
std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings) {
|
||||
Item::appendHoverText(itemInstance, player, lines, advanced,
|
||||
unformattedStrings);
|
||||
|
||||
return (ListTag<CompoundTag> *) item->tag->get((wchar_t *)TAG_STORED_ENCHANTMENTS.c_str());
|
||||
ListTag<CompoundTag>* list = getEnchantments(itemInstance);
|
||||
|
||||
if (list != NULL) {
|
||||
std::wstring unformatted = L"";
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
int type =
|
||||
list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_ID);
|
||||
int level =
|
||||
list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL);
|
||||
|
||||
if (Enchantment::enchantments[type] != NULL) {
|
||||
lines->push_back(Enchantment::enchantments[type]->getFullname(
|
||||
level, unformatted));
|
||||
unformattedStrings.push_back(unformatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EnchantedBookItem::appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings)
|
||||
{
|
||||
Item::appendHoverText(itemInstance, player, lines, advanced, unformattedStrings);
|
||||
void EnchantedBookItem::addEnchantment(std::shared_ptr<ItemInstance> item,
|
||||
EnchantmentInstance* enchantment) {
|
||||
ListTag<CompoundTag>* enchantments = getEnchantments(item);
|
||||
bool add = true;
|
||||
|
||||
ListTag<CompoundTag> *list = getEnchantments(itemInstance);
|
||||
for (int i = 0; i < enchantments->size(); i++) {
|
||||
CompoundTag* tag = enchantments->get(i);
|
||||
|
||||
if (list != NULL)
|
||||
{
|
||||
std::wstring unformatted = L"";
|
||||
for (int i = 0; i < list->size(); i++)
|
||||
{
|
||||
int type = list->get(i)->getShort((wchar_t *)ItemInstance::TAG_ENCH_ID);
|
||||
int level = list->get(i)->getShort((wchar_t *)ItemInstance::TAG_ENCH_LEVEL);
|
||||
if (tag->getShort((wchar_t*)ItemInstance::TAG_ENCH_ID) ==
|
||||
enchantment->enchantment->id) {
|
||||
if (tag->getShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL) <
|
||||
enchantment->level) {
|
||||
tag->putShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL,
|
||||
(short)enchantment->level);
|
||||
}
|
||||
|
||||
if (Enchantment::enchantments[type] != NULL)
|
||||
{
|
||||
lines->push_back(Enchantment::enchantments[type]->getFullname(level, unformatted));
|
||||
unformattedStrings.push_back(unformatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (add) {
|
||||
CompoundTag* tag = new CompoundTag();
|
||||
|
||||
tag->putShort((wchar_t*)ItemInstance::TAG_ENCH_ID,
|
||||
(short)enchantment->enchantment->id);
|
||||
tag->putShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL,
|
||||
(short)enchantment->level);
|
||||
|
||||
enchantments->add(tag);
|
||||
}
|
||||
|
||||
if (!item->hasTag()) item->setTag(new CompoundTag());
|
||||
item->getTag()->put((wchar_t*)TAG_STORED_ENCHANTMENTS.c_str(),
|
||||
enchantments);
|
||||
}
|
||||
|
||||
void EnchantedBookItem::addEnchantment(std::shared_ptr<ItemInstance> item, EnchantmentInstance *enchantment)
|
||||
{
|
||||
ListTag<CompoundTag> *enchantments = getEnchantments(item);
|
||||
bool add = true;
|
||||
|
||||
for (int i = 0; i < enchantments->size(); i++)
|
||||
{
|
||||
CompoundTag *tag = enchantments->get(i);
|
||||
|
||||
if (tag->getShort((wchar_t *)ItemInstance::TAG_ENCH_ID) == enchantment->enchantment->id)
|
||||
{
|
||||
if (tag->getShort((wchar_t *)ItemInstance::TAG_ENCH_LEVEL) < enchantment->level)
|
||||
{
|
||||
tag->putShort((wchar_t *)ItemInstance::TAG_ENCH_LEVEL, (short) enchantment->level);
|
||||
}
|
||||
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (add)
|
||||
{
|
||||
CompoundTag *tag = new CompoundTag();
|
||||
|
||||
tag->putShort((wchar_t *)ItemInstance::TAG_ENCH_ID, (short) enchantment->enchantment->id);
|
||||
tag->putShort((wchar_t *)ItemInstance::TAG_ENCH_LEVEL, (short) enchantment->level);
|
||||
|
||||
enchantments->add(tag);
|
||||
}
|
||||
|
||||
if (!item->hasTag()) item->setTag(new CompoundTag());
|
||||
item->getTag()->put((wchar_t *)TAG_STORED_ENCHANTMENTS.c_str(), enchantments);
|
||||
std::shared_ptr<ItemInstance> EnchantedBookItem::createForEnchantment(
|
||||
EnchantmentInstance* enchant) {
|
||||
std::shared_ptr<ItemInstance> item =
|
||||
std::shared_ptr<ItemInstance>(new ItemInstance(this));
|
||||
addEnchantment(item, enchant);
|
||||
return item;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EnchantedBookItem::createForEnchantment(EnchantmentInstance *enchant)
|
||||
{
|
||||
std::shared_ptr<ItemInstance> item = std::shared_ptr<ItemInstance>(new ItemInstance(this));
|
||||
addEnchantment(item, enchant);
|
||||
return item;
|
||||
void EnchantedBookItem::createForEnchantment(
|
||||
Enchantment* enchant, std::vector<std::shared_ptr<ItemInstance> >* items) {
|
||||
for (int i = enchant->getMinLevel(); i <= enchant->getMaxLevel(); i++) {
|
||||
items->push_back(
|
||||
createForEnchantment(new EnchantmentInstance(enchant, i)));
|
||||
}
|
||||
}
|
||||
|
||||
void EnchantedBookItem::createForEnchantment(Enchantment *enchant, std::vector<std::shared_ptr<ItemInstance> > *items)
|
||||
{
|
||||
for (int i = enchant->getMinLevel(); i <= enchant->getMaxLevel(); i++)
|
||||
{
|
||||
items->push_back(createForEnchantment(new EnchantmentInstance(enchant, i)));
|
||||
}
|
||||
std::shared_ptr<ItemInstance> EnchantedBookItem::createForRandomLoot(
|
||||
Random* random) {
|
||||
Enchantment* enchantment = Enchantment::validEnchantments[random->nextInt(
|
||||
Enchantment::validEnchantments.size())];
|
||||
std::shared_ptr<ItemInstance> book =
|
||||
std::shared_ptr<ItemInstance>(new ItemInstance(id, 1, 0));
|
||||
int level = Mth::nextInt(random, enchantment->getMinLevel(),
|
||||
enchantment->getMaxLevel());
|
||||
|
||||
addEnchantment(book, new EnchantmentInstance(enchantment, level));
|
||||
|
||||
return book;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EnchantedBookItem::createForRandomLoot(Random *random)
|
||||
{
|
||||
Enchantment *enchantment = Enchantment::validEnchantments[random->nextInt(Enchantment::validEnchantments.size())];
|
||||
std::shared_ptr<ItemInstance> book = std::shared_ptr<ItemInstance>(new ItemInstance(id, 1, 0));
|
||||
int level = Mth::nextInt(random, enchantment->getMinLevel(), enchantment->getMaxLevel());
|
||||
|
||||
addEnchantment(book, new EnchantmentInstance(enchantment, level));
|
||||
|
||||
return book;
|
||||
WeighedTreasure* EnchantedBookItem::createForRandomTreasure(Random* random) {
|
||||
return createForRandomTreasure(random, 1, 1, 1);
|
||||
}
|
||||
|
||||
WeighedTreasure *EnchantedBookItem::createForRandomTreasure(Random *random)
|
||||
{
|
||||
return createForRandomTreasure(random, 1, 1, 1);
|
||||
}
|
||||
WeighedTreasure* EnchantedBookItem::createForRandomTreasure(Random* random,
|
||||
int minCount,
|
||||
int maxCount,
|
||||
int weight) {
|
||||
Enchantment* enchantment = Enchantment::validEnchantments[random->nextInt(
|
||||
Enchantment::validEnchantments.size())];
|
||||
std::shared_ptr<ItemInstance> book =
|
||||
std::shared_ptr<ItemInstance>(new ItemInstance(id, 1, 0));
|
||||
int level = Mth::nextInt(random, enchantment->getMinLevel(),
|
||||
enchantment->getMaxLevel());
|
||||
|
||||
WeighedTreasure *EnchantedBookItem::createForRandomTreasure(Random *random, int minCount, int maxCount, int weight)
|
||||
{
|
||||
Enchantment *enchantment = Enchantment::validEnchantments[random->nextInt(Enchantment::validEnchantments.size())];
|
||||
std::shared_ptr<ItemInstance> book = std::shared_ptr<ItemInstance>(new ItemInstance(id, 1, 0));
|
||||
int level = Mth::nextInt(random, enchantment->getMinLevel(), enchantment->getMaxLevel());
|
||||
addEnchantment(book, new EnchantmentInstance(enchantment, level));
|
||||
|
||||
addEnchantment(book, new EnchantmentInstance(enchantment, level));
|
||||
|
||||
return new WeighedTreasure(book, minCount, maxCount, weight);
|
||||
return new WeighedTreasure(book, minCount, maxCount, weight);
|
||||
}
|
||||
@@ -4,22 +4,29 @@
|
||||
|
||||
class EnchantmentInstance;
|
||||
|
||||
class EnchantedBookItem : public Item
|
||||
{
|
||||
class EnchantedBookItem : public Item {
|
||||
public:
|
||||
static const std::wstring TAG_STORED_ENCHANTMENTS;
|
||||
static const std::wstring TAG_STORED_ENCHANTMENTS;
|
||||
|
||||
EnchantedBookItem(int id);
|
||||
EnchantedBookItem(int id);
|
||||
|
||||
bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
bool isEnchantable(std::shared_ptr<ItemInstance> itemInstance);
|
||||
const Rarity *getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
ListTag<CompoundTag> *getEnchantments(std::shared_ptr<ItemInstance> item);
|
||||
void appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings);
|
||||
void addEnchantment(std::shared_ptr<ItemInstance> item, EnchantmentInstance *enchantment);
|
||||
std::shared_ptr<ItemInstance> createForEnchantment(EnchantmentInstance *enchant);
|
||||
void createForEnchantment(Enchantment *enchant, std::vector<std::shared_ptr<ItemInstance> > *items);
|
||||
std::shared_ptr<ItemInstance> createForRandomLoot(Random *random);
|
||||
WeighedTreasure *createForRandomTreasure(Random *random);
|
||||
WeighedTreasure *createForRandomTreasure(Random *random, int minCount, int maxCount, int weight);
|
||||
bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
bool isEnchantable(std::shared_ptr<ItemInstance> itemInstance);
|
||||
const Rarity* getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
ListTag<CompoundTag>* getEnchantments(std::shared_ptr<ItemInstance> item);
|
||||
void appendHoverText(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings);
|
||||
void addEnchantment(std::shared_ptr<ItemInstance> item,
|
||||
EnchantmentInstance* enchantment);
|
||||
std::shared_ptr<ItemInstance> createForEnchantment(
|
||||
EnchantmentInstance* enchant);
|
||||
void createForEnchantment(
|
||||
Enchantment* enchant,
|
||||
std::vector<std::shared_ptr<ItemInstance> >* items);
|
||||
std::shared_ptr<ItemInstance> createForRandomLoot(Random* random);
|
||||
WeighedTreasure* createForRandomTreasure(Random* random);
|
||||
WeighedTreasure* createForRandomTreasure(Random* random, int minCount,
|
||||
int maxCount, int weight);
|
||||
};
|
||||
@@ -9,230 +9,226 @@
|
||||
#include "../Util/SoundTypes.h"
|
||||
#include "../Level/LevelData.h"
|
||||
|
||||
EnderEyeItem::EnderEyeItem(int id) : Item(id)
|
||||
{
|
||||
EnderEyeItem::EnderEyeItem(int id) : Item(id) {}
|
||||
|
||||
bool EnderEyeItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
int targetType = level->getTile(x, y, z);
|
||||
int targetData = level->getData(x, y, z);
|
||||
|
||||
if (player->mayBuild(x, y, z) &&
|
||||
targetType == Tile::endPortalFrameTile_Id &&
|
||||
!TheEndPortalFrameTile::hasEye(targetData)) {
|
||||
if (bTestUseOnOnly) return true;
|
||||
if (level->isClientSide) return true;
|
||||
level->setData(x, y, z, targetData + TheEndPortalFrameTile::EYE_BIT);
|
||||
instance->count--;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
double xp = x + (5.0f + random->nextFloat() * 6.0f) / 16.0f;
|
||||
double yp = y + 13.0f / 16.0f;
|
||||
double zp = z + (5.0f + random->nextFloat() * 6.0f) / 16.0f;
|
||||
double xa = 0;
|
||||
double ya = 0;
|
||||
double za = 0;
|
||||
|
||||
level->addParticle(eParticleType_smoke, xp, yp, zp, xa, ya, za);
|
||||
}
|
||||
|
||||
// scan if the circle is complete
|
||||
int direction = targetData & 3;
|
||||
|
||||
// find borders
|
||||
int min = 0;
|
||||
int max = 0;
|
||||
bool firstFound = false;
|
||||
bool valid = true;
|
||||
int rightHandDirection = Direction::DIRECTION_CLOCKWISE[direction];
|
||||
for (int offset = -2; offset <= 2; offset++) {
|
||||
int testX = x + Direction::STEP_X[rightHandDirection] * offset;
|
||||
int testZ = z + Direction::STEP_Z[rightHandDirection] * offset;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
if (tile == Tile::endPortalFrameTile->id) {
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (!TheEndPortalFrameTile::hasEye(data)) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
max = offset;
|
||||
if (!firstFound) {
|
||||
min = offset;
|
||||
firstFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// got a full frame?
|
||||
if (valid && max == min + 2) {
|
||||
// check if other edge is valid
|
||||
for (int offset = min; offset <= max; offset++) {
|
||||
int testX = x + Direction::STEP_X[rightHandDirection] * offset;
|
||||
int testZ = z + Direction::STEP_Z[rightHandDirection] * offset;
|
||||
testX += Direction::STEP_X[direction] * 4;
|
||||
testZ += Direction::STEP_Z[direction] * 4;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (tile != Tile::endPortalFrameTile_Id ||
|
||||
!TheEndPortalFrameTile::hasEye(data)) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// check if edges on the sides are valid
|
||||
for (int side = (min - 1); side <= (max + 1); side += 4) {
|
||||
for (int offset = 1; offset <= 3; offset++) {
|
||||
int testX =
|
||||
x + Direction::STEP_X[rightHandDirection] * side;
|
||||
int testZ =
|
||||
z + Direction::STEP_Z[rightHandDirection] * side;
|
||||
testX += Direction::STEP_X[direction] * offset;
|
||||
testZ += Direction::STEP_Z[direction] * offset;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (tile != Tile::endPortalFrameTile_Id ||
|
||||
!TheEndPortalFrameTile::hasEye(data)) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (valid) {
|
||||
// fill portal
|
||||
for (int px = min; px <= max; px++) {
|
||||
for (int pz = 1; pz <= 3; pz++) {
|
||||
int targetX =
|
||||
x + Direction::STEP_X[rightHandDirection] * px;
|
||||
int targetZ =
|
||||
z + Direction::STEP_Z[rightHandDirection] * px;
|
||||
targetX += Direction::STEP_X[direction] * pz;
|
||||
targetZ += Direction::STEP_Z[direction] * pz;
|
||||
|
||||
level->setTile(targetX, y, targetZ,
|
||||
Tile::endPortalTile_Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EnderEyeItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
int targetType = level->getTile(x, y, z);
|
||||
int targetData = level->getData(x, y, z);
|
||||
bool EnderEyeItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, false);
|
||||
if (hr != NULL && hr->type == HitResult::TILE) {
|
||||
int tile = level->getTile(hr->x, hr->y, hr->z);
|
||||
delete hr;
|
||||
if (tile == Tile::endPortalFrameTile_Id) {
|
||||
return false;
|
||||
}
|
||||
} else if (hr != NULL) {
|
||||
delete hr;
|
||||
}
|
||||
|
||||
if (player->mayBuild(x, y, z) && targetType == Tile::endPortalFrameTile_Id && !TheEndPortalFrameTile::hasEye(targetData))
|
||||
{
|
||||
if(bTestUseOnOnly) return true;
|
||||
if (level->isClientSide) return true;
|
||||
level->setData(x, y, z, targetData + TheEndPortalFrameTile::EYE_BIT);
|
||||
instance->count--;
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
double xp = x + (5.0f + random->nextFloat() * 6.0f) / 16.0f;
|
||||
double yp = y + 13.0f / 16.0f;
|
||||
double zp = z + (5.0f + random->nextFloat() * 6.0f) / 16.0f;
|
||||
double xa = 0;
|
||||
double ya = 0;
|
||||
double za = 0;
|
||||
|
||||
level->addParticle(eParticleType_smoke, xp, yp, zp, xa, ya, za);
|
||||
}
|
||||
|
||||
// scan if the circle is complete
|
||||
int direction = targetData & 3;
|
||||
|
||||
// find borders
|
||||
int min = 0;
|
||||
int max = 0;
|
||||
bool firstFound = false;
|
||||
bool valid = true;
|
||||
int rightHandDirection = Direction::DIRECTION_CLOCKWISE[direction];
|
||||
for (int offset = -2; offset <= 2; offset++)
|
||||
{
|
||||
int testX = x + Direction::STEP_X[rightHandDirection] * offset;
|
||||
int testZ = z + Direction::STEP_Z[rightHandDirection] * offset;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
if (tile == Tile::endPortalFrameTile->id)
|
||||
{
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (!TheEndPortalFrameTile::hasEye(data))
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
max = offset;
|
||||
if (!firstFound)
|
||||
{
|
||||
min = offset;
|
||||
firstFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// got a full frame?
|
||||
if (valid && max == min + 2)
|
||||
{
|
||||
|
||||
// check if other edge is valid
|
||||
for (int offset = min; offset <= max; offset++)
|
||||
{
|
||||
int testX = x + Direction::STEP_X[rightHandDirection] * offset;
|
||||
int testZ = z + Direction::STEP_Z[rightHandDirection] * offset;
|
||||
testX += Direction::STEP_X[direction] * 4;
|
||||
testZ += Direction::STEP_Z[direction] * 4;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (tile != Tile::endPortalFrameTile_Id || !TheEndPortalFrameTile::hasEye(data))
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// check if edges on the sides are valid
|
||||
for (int side = (min - 1); side <= (max + 1); side += 4)
|
||||
{
|
||||
for (int offset = 1; offset <= 3; offset++)
|
||||
{
|
||||
int testX = x + Direction::STEP_X[rightHandDirection] * side;
|
||||
int testZ = z + Direction::STEP_Z[rightHandDirection] * side;
|
||||
testX += Direction::STEP_X[direction] * offset;
|
||||
testZ += Direction::STEP_Z[direction] * offset;
|
||||
|
||||
int tile = level->getTile(testX, y, testZ);
|
||||
int data = level->getData(testX, y, testZ);
|
||||
if (tile != Tile::endPortalFrameTile_Id || !TheEndPortalFrameTile::hasEye(data))
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (valid)
|
||||
{
|
||||
|
||||
// fill portal
|
||||
for (int px = min; px <= max; px++)
|
||||
{
|
||||
for (int pz = 1; pz <= 3; pz++)
|
||||
{
|
||||
int targetX = x + Direction::STEP_X[rightHandDirection] * px;
|
||||
int targetZ = z + Direction::STEP_Z[rightHandDirection] * px;
|
||||
targetX += Direction::STEP_X[direction] * pz;
|
||||
targetZ += Direction::STEP_Z[direction] * pz;
|
||||
|
||||
level->setTile(targetX, y, targetZ, Tile::endPortalTile_Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// if (!level->isClientSide)
|
||||
{
|
||||
if ((level->dimension->id == LevelData::DIMENSION_OVERWORLD) &&
|
||||
level->getLevelData()->getHasStronghold()) {
|
||||
return true;
|
||||
} else {
|
||||
// int x,z;
|
||||
// if(app.GetTerrainFeaturePosition(eTerrainFeature_Stronghold,&x,&z))
|
||||
// {
|
||||
// level->getLevelData()->setXStronghold(x);
|
||||
// level->getLevelData()->setZStronghold(z);
|
||||
// level->getLevelData()->setHasStronghold();
|
||||
//
|
||||
// app.DebugPrintf("=== FOUND stronghold in
|
||||
// terrain features list\n");
|
||||
//
|
||||
// app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_StrongholdPosition);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
// can't find the stronghold position in the terrain feature
|
||||
// list. Do we have to run a post-process?
|
||||
app.DebugPrintf(
|
||||
"=== Can't find stronghold in terrain features list\n");
|
||||
}
|
||||
}
|
||||
// TilePos *nearestMapFeature =
|
||||
// level->findNearestMapFeature(LargeFeature::STRONGHOLD, (int)
|
||||
// player->x, (int) player->y, (int) player->z); if (nearestMapFeature
|
||||
// != NULL)
|
||||
// {
|
||||
// delete nearestMapFeature;
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EnderEyeItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, false);
|
||||
if (hr != NULL && hr->type == HitResult::TILE)
|
||||
{
|
||||
int tile = level->getTile(hr->x, hr->y, hr->z);
|
||||
delete hr;
|
||||
if (tile == Tile::endPortalFrameTile_Id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( hr != NULL )
|
||||
{
|
||||
delete hr;
|
||||
}
|
||||
std::shared_ptr<ItemInstance> EnderEyeItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
HitResult* hr = getPlayerPOVHitResult(level, player, false);
|
||||
if (hr != NULL && hr->type == HitResult::TILE) {
|
||||
int tile = level->getTile(hr->x, hr->y, hr->z);
|
||||
delete hr;
|
||||
if (tile == Tile::endPortalFrameTile_Id) {
|
||||
return instance;
|
||||
}
|
||||
} else if (hr != NULL) {
|
||||
delete hr;
|
||||
}
|
||||
|
||||
//if (!level->isClientSide)
|
||||
{
|
||||
if((level->dimension->id==LevelData::DIMENSION_OVERWORLD) && level->getLevelData()->getHasStronghold())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// int x,z;
|
||||
// if(app.GetTerrainFeaturePosition(eTerrainFeature_Stronghold,&x,&z))
|
||||
// {
|
||||
// level->getLevelData()->setXStronghold(x);
|
||||
// level->getLevelData()->setZStronghold(z);
|
||||
// level->getLevelData()->setHasStronghold();
|
||||
//
|
||||
// app.DebugPrintf("=== FOUND stronghold in terrain features list\n");
|
||||
//
|
||||
// app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_StrongholdPosition);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
// can't find the stronghold position in the terrain feature list. Do we have to run a post-process?
|
||||
app.DebugPrintf("=== Can't find stronghold in terrain features list\n");
|
||||
}
|
||||
if (!level->isClientSide) {
|
||||
if ((level->dimension->id == LevelData::DIMENSION_OVERWORLD) &&
|
||||
level->getLevelData()->getHasStronghold()) {
|
||||
std::shared_ptr<EyeOfEnderSignal> eyeOfEnderSignal =
|
||||
std::shared_ptr<EyeOfEnderSignal>(new EyeOfEnderSignal(
|
||||
level, player->x, player->y + 1.62 - player->heightOffset,
|
||||
player->z));
|
||||
eyeOfEnderSignal->signalTo(
|
||||
level->getLevelData()->getXStronghold() << 4,
|
||||
player->y + 1.62 - player->heightOffset,
|
||||
level->getLevelData()->getZStronghold() << 4);
|
||||
level->addEntity(eyeOfEnderSignal);
|
||||
|
||||
}
|
||||
// TilePos *nearestMapFeature = level->findNearestMapFeature(LargeFeature::STRONGHOLD, (int) player->x, (int) player->y, (int) player->z);
|
||||
// if (nearestMapFeature != NULL)
|
||||
// {
|
||||
// delete nearestMapFeature;
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
level->levelEvent(nullptr, LevelEvent::SOUND_LAUNCH, (int)player->x,
|
||||
(int)player->y, (int)player->z, 0);
|
||||
if (!player->abilities.instabuild) {
|
||||
instance->count--;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EnderEyeItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
HitResult *hr = getPlayerPOVHitResult(level, player, false);
|
||||
if (hr != NULL && hr->type == HitResult::TILE)
|
||||
{
|
||||
int tile = level->getTile(hr->x, hr->y, hr->z);
|
||||
delete hr;
|
||||
if (tile == Tile::endPortalFrameTile_Id)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
else if( hr != NULL )
|
||||
{
|
||||
delete hr;
|
||||
}
|
||||
/*TilePos *nearestMapFeature =
|
||||
level->findNearestMapFeature(LargeFeature::STRONGHOLD, (int) player->x,
|
||||
(int) player->y, (int) player->z); if (nearestMapFeature != NULL)
|
||||
{
|
||||
std::shared_ptr<EyeOfEnderSignal> eyeOfEnderSignal =
|
||||
std::shared_ptr<EyeOfEnderSignal>( new EyeOfEnderSignal(level,
|
||||
player->x, player->y + 1.62 - player->heightOffset, player->z) );
|
||||
eyeOfEnderSignal->signalTo(nearestMapFeature->x,
|
||||
nearestMapFeature->y, nearestMapFeature->z); delete nearestMapFeature;
|
||||
level->addEntity(eyeOfEnderSignal);
|
||||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
if((level->dimension->id==LevelData::DIMENSION_OVERWORLD) && level->getLevelData()->getHasStronghold())
|
||||
{
|
||||
std::shared_ptr<EyeOfEnderSignal> eyeOfEnderSignal = std::shared_ptr<EyeOfEnderSignal>( new EyeOfEnderSignal(level, player->x, player->y + 1.62 - player->heightOffset, player->z) );
|
||||
eyeOfEnderSignal->signalTo(level->getLevelData()->getXStronghold()<<4, player->y + 1.62 - player->heightOffset, level->getLevelData()->getZStronghold()<<4);
|
||||
level->addEntity(eyeOfEnderSignal);
|
||||
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
level->levelEvent(nullptr, LevelEvent::SOUND_LAUNCH, (int) player->x, (int) player->y, (int) player->z, 0);
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
}
|
||||
|
||||
/*TilePos *nearestMapFeature = level->findNearestMapFeature(LargeFeature::STRONGHOLD, (int) player->x, (int) player->y, (int) player->z);
|
||||
if (nearestMapFeature != NULL)
|
||||
{
|
||||
std::shared_ptr<EyeOfEnderSignal> eyeOfEnderSignal = std::shared_ptr<EyeOfEnderSignal>( new EyeOfEnderSignal(level, player->x, player->y + 1.62 - player->heightOffset, player->z) );
|
||||
eyeOfEnderSignal->signalTo(nearestMapFeature->x, nearestMapFeature->y, nearestMapFeature->z);
|
||||
delete nearestMapFeature;
|
||||
level->addEntity(eyeOfEnderSignal);
|
||||
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
level->levelEvent(NULL, LevelEvent::SOUND_LAUNCH, (int) player->x, (int) player->y, (int) player->z, 0);
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return instance;
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f /
|
||||
(random->nextFloat() * 0.4f + 0.8f)); level->levelEvent(NULL,
|
||||
LevelEvent::SOUND_LAUNCH, (int) player->x, (int) player->y, (int)
|
||||
player->z, 0); if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class EnderEyeItem : public Item
|
||||
{
|
||||
class EnderEyeItem : public Item {
|
||||
public:
|
||||
EnderEyeItem(int id);
|
||||
EnderEyeItem(int id);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -5,30 +5,28 @@
|
||||
#include "EnderPearlItem.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
EnderpearlItem::EnderpearlItem(int id) : Item(id)
|
||||
{
|
||||
this->maxStackSize = 16;
|
||||
EnderpearlItem::EnderpearlItem(int id) : Item(id) { this->maxStackSize = 16; }
|
||||
|
||||
bool EnderpearlItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnderpearlItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<ItemInstance> EnderpearlItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
// 4J-PB - Not sure why this was disabled for creative mode, so commenting
|
||||
// out
|
||||
// if (player->abilities.instabuild) return instance;
|
||||
if (player->riding != NULL) return instance;
|
||||
if (!player->abilities.instabuild) {
|
||||
instance->count--;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EnderpearlItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
// 4J-PB - Not sure why this was disabled for creative mode, so commenting out
|
||||
//if (player->abilities.instabuild) return instance;
|
||||
if (player->riding != NULL) return instance;
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
level->addEntity( std::shared_ptr<ThrownEnderpearl>( new ThrownEnderpearl(level, player) ) );
|
||||
}
|
||||
return instance;
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) {
|
||||
level->addEntity(std::shared_ptr<ThrownEnderpearl>(
|
||||
new ThrownEnderpearl(level, player)));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class EnderpearlItem : public Item
|
||||
{
|
||||
class EnderpearlItem : public Item {
|
||||
public:
|
||||
EnderpearlItem(int id);
|
||||
EnderpearlItem(int id);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
// 4J added
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
// 4J added
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -6,27 +6,26 @@
|
||||
#include "../Util/SoundTypes.h"
|
||||
#include "ExperienceItem.h"
|
||||
|
||||
ExperienceItem::ExperienceItem(int id) : Item(id)
|
||||
{
|
||||
ExperienceItem::ExperienceItem(int id) : Item(id) {}
|
||||
|
||||
bool ExperienceItem::isFoil(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExperienceItem::isFoil(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return true;
|
||||
bool ExperienceItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExperienceItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> ExperienceItem::use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) level->addEntity( std::shared_ptr<ThrownExpBottle>( new ThrownExpBottle(level, player) ));
|
||||
return itemInstance;
|
||||
std::shared_ptr<ItemInstance> ExperienceItem::use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (!player->abilities.instabuild) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
level->addEntity(std::shared_ptr<ThrownExpBottle>(
|
||||
new ThrownExpBottle(level, player)));
|
||||
return itemInstance;
|
||||
}
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
class ItemInstance;
|
||||
|
||||
class ExperienceItem : public Item
|
||||
{
|
||||
class ExperienceItem : public Item {
|
||||
public:
|
||||
ExperienceItem(int id);
|
||||
ExperienceItem(int id);
|
||||
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -8,60 +8,54 @@
|
||||
#include "FireChargeItem.h"
|
||||
#include "../Blocks/Tile.h"
|
||||
|
||||
FireChargeItem::FireChargeItem(int id) : Item(id)
|
||||
{
|
||||
m_dragonFireballIcon = NULL;
|
||||
FireChargeItem::FireChargeItem(int id) : Item(id) {
|
||||
m_dragonFireballIcon = NULL;
|
||||
}
|
||||
|
||||
bool FireChargeItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (level->isClientSide)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool FireChargeItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
if (level->isClientSide) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
|
||||
if (!player->mayBuild(x, y, z))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!player->mayBuild(x, y, z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if(bTestUseOnOnly)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (bTestUseOnOnly) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int targetType = level->getTile(x, y, z);
|
||||
int targetType = level->getTile(x, y, z);
|
||||
|
||||
if (targetType == 0)
|
||||
{
|
||||
level->playSound( x + 0.5, y + 0.5, z + 0.5,eSoundType_FIRE_IGNITE, 1, random->nextFloat() * 0.4f + 0.8f);
|
||||
level->setTile(x, y, z, Tile::fire_Id);
|
||||
}
|
||||
if (targetType == 0) {
|
||||
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_FIRE_IGNITE, 1,
|
||||
random->nextFloat() * 0.4f + 0.8f);
|
||||
level->setTile(x, y, z, Tile::fire_Id);
|
||||
}
|
||||
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
if (!player->abilities.instabuild) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Icon *FireChargeItem::getIcon(int itemAuxValue)
|
||||
{
|
||||
if(itemAuxValue > 0) return m_dragonFireballIcon;
|
||||
return Item::getIcon(itemAuxValue);
|
||||
Icon* FireChargeItem::getIcon(int itemAuxValue) {
|
||||
if (itemAuxValue > 0) return m_dragonFireballIcon;
|
||||
return Item::getIcon(itemAuxValue);
|
||||
}
|
||||
|
||||
void FireChargeItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
m_dragonFireballIcon = iconRegister->registerIcon(L"dragonFireball");
|
||||
void FireChargeItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
m_dragonFireballIcon = iconRegister->registerIcon(L"dragonFireball");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,18 @@ class ItemInstance;
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class FireChargeItem : public Item
|
||||
{
|
||||
class FireChargeItem : public Item {
|
||||
private:
|
||||
Icon *m_dragonFireballIcon;
|
||||
Icon* m_dragonFireballIcon;
|
||||
|
||||
public:
|
||||
FireChargeItem(int id);
|
||||
FireChargeItem(int id);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly);
|
||||
|
||||
virtual Icon *getIcon(int itemAuxValue);
|
||||
virtual void registerIcons(IconRegister *iconRegister);
|
||||
virtual Icon* getIcon(int itemAuxValue);
|
||||
virtual void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -15,53 +15,42 @@
|
||||
|
||||
const std::wstring FishingRodItem::TEXTURE_EMPTY = L"fishingRod_empty";
|
||||
|
||||
FishingRodItem::FishingRodItem(int id) : Item(id)
|
||||
{
|
||||
setMaxDamage(64);
|
||||
setMaxStackSize(1);
|
||||
emptyIcon = NULL;
|
||||
FishingRodItem::FishingRodItem(int id) : Item(id) {
|
||||
setMaxDamage(64);
|
||||
setMaxStackSize(1);
|
||||
emptyIcon = NULL;
|
||||
}
|
||||
|
||||
bool FishingRodItem::isHandEquipped()
|
||||
{
|
||||
return true;
|
||||
bool FishingRodItem::isHandEquipped() { return true; }
|
||||
|
||||
bool FishingRodItem::isMirroredArt() { return true; }
|
||||
|
||||
std::shared_ptr<ItemInstance> FishingRodItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (player->fishing != NULL) {
|
||||
int dmg = player->fishing->retrieve();
|
||||
instance->hurt(dmg, player);
|
||||
player->swing();
|
||||
} else {
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) {
|
||||
// 4J Stu - Move the player->fishing out of the ctor as we cannot
|
||||
// reference 'this'
|
||||
std::shared_ptr<FishingHook> hook =
|
||||
std::shared_ptr<FishingHook>(new FishingHook(level, player));
|
||||
player->fishing = hook;
|
||||
level->addEntity(std::shared_ptr<FishingHook>(hook));
|
||||
}
|
||||
player->swing();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool FishingRodItem::isMirroredArt()
|
||||
{
|
||||
return true;
|
||||
void FishingRodItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
emptyIcon = iconRegister->registerIcon(TEXTURE_EMPTY);
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> FishingRodItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (player->fishing != NULL)
|
||||
{
|
||||
int dmg = player->fishing->retrieve();
|
||||
instance->hurt(dmg, player);
|
||||
player->swing();
|
||||
}
|
||||
else
|
||||
{
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
// 4J Stu - Move the player->fishing out of the ctor as we cannot reference 'this'
|
||||
std::shared_ptr<FishingHook> hook = std::shared_ptr<FishingHook>( new FishingHook(level, player) );
|
||||
player->fishing = hook;
|
||||
level->addEntity( std::shared_ptr<FishingHook>( hook ) );
|
||||
}
|
||||
player->swing();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FishingRodItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
emptyIcon = iconRegister->registerIcon(TEXTURE_EMPTY);
|
||||
}
|
||||
|
||||
Icon *FishingRodItem::getEmptyIcon()
|
||||
{
|
||||
return emptyIcon;
|
||||
}
|
||||
Icon* FishingRodItem::getEmptyIcon() { return emptyIcon; }
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class FishingRodItem : public Item
|
||||
{
|
||||
class FishingRodItem : public Item {
|
||||
public:
|
||||
static const std::wstring TEXTURE_EMPTY;
|
||||
static const std::wstring TEXTURE_EMPTY;
|
||||
|
||||
private:
|
||||
Icon *emptyIcon;
|
||||
Icon* emptyIcon;
|
||||
|
||||
public:
|
||||
FishingRodItem(int id);
|
||||
FishingRodItem(int id);
|
||||
|
||||
virtual bool isHandEquipped();
|
||||
virtual bool isMirroredArt();
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool isHandEquipped();
|
||||
virtual bool isMirroredArt();
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
Icon *getEmptyIcon();
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
Icon* getEmptyIcon();
|
||||
};
|
||||
|
||||
@@ -9,64 +9,57 @@
|
||||
#include "FlintAndSteelItem.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
FlintAndSteelItem::FlintAndSteelItem(int id) : Item( id )
|
||||
{
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(64);
|
||||
FlintAndSteelItem::FlintAndSteelItem(int id) : Item(id) {
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(64);
|
||||
}
|
||||
|
||||
bool FlintAndSteelItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
bool FlintAndSteelItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level,
|
||||
int x, int y, int z, int face, float clickX,
|
||||
float clickY, float clickZ, bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
|
||||
int targetType = level->getTile(x, y, z);
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (targetType == 0)
|
||||
{
|
||||
if( level->getTile(x, y-1, z) == Tile::obsidian_Id )
|
||||
{
|
||||
if( Tile::portalTile->trySpawnPortal(level, x, y, z, false) )
|
||||
{
|
||||
player->awardStat(
|
||||
GenericStats::portalsCreated(),
|
||||
GenericStats::param_noArgs()
|
||||
);
|
||||
int targetType = level->getTile(x, y, z);
|
||||
|
||||
// 4J : WESTY : Added for achievement.
|
||||
player->awardStat(GenericStats::InToTheNether(),GenericStats::param_InToTheNether());
|
||||
}
|
||||
}
|
||||
if (!bTestUseOnOnly) {
|
||||
if (targetType == 0) {
|
||||
if (level->getTile(x, y - 1, z) == Tile::obsidian_Id) {
|
||||
if (Tile::portalTile->trySpawnPortal(level, x, y, z, false)) {
|
||||
player->awardStat(GenericStats::portalsCreated(),
|
||||
GenericStats::param_noArgs());
|
||||
|
||||
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_FIRE_IGNITE, 1, random->nextFloat() * 0.4f + 0.8f);
|
||||
level->setTile(x, y, z, Tile::fire_Id);
|
||||
}
|
||||
// 4J : WESTY : Added for achievement.
|
||||
player->awardStat(GenericStats::InToTheNether(),
|
||||
GenericStats::param_InToTheNether());
|
||||
}
|
||||
}
|
||||
|
||||
instance->hurt(1, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(targetType == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_FIRE_IGNITE,
|
||||
1, random->nextFloat() * 0.4f + 0.8f);
|
||||
level->setTile(x, y, z, Tile::fire_Id);
|
||||
}
|
||||
|
||||
// 4J-PB - this function shouldn't really return true all the time, but I've added a special case for my test use for the tooltips display
|
||||
// and will leave it as is for the game use
|
||||
instance->hurt(1, player);
|
||||
} else {
|
||||
if (targetType == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
// 4J-PB - this function shouldn't really return true all the time, but I've
|
||||
// added a special case for my test use for the tooltips display and will
|
||||
// leave it as is for the game use
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class FlintAndSteelItem : public Item
|
||||
{
|
||||
class FlintAndSteelItem : public Item {
|
||||
public:
|
||||
FlintAndSteelItem(int id);
|
||||
FlintAndSteelItem(int id);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
|
||||
@@ -11,110 +11,103 @@
|
||||
// 4J : WESTY : Other award ... eating cooked pork chop.
|
||||
#include "../Headers/net.minecraft.stats.h"
|
||||
|
||||
void FoodItem::_init()
|
||||
{
|
||||
// 4J Initialisers
|
||||
canAlwaysEat = false;
|
||||
effectId = 0;
|
||||
effectDurationSeconds = 0;
|
||||
effectAmplifier = 0;
|
||||
effectProbability = 0.0f;
|
||||
void FoodItem::_init() {
|
||||
// 4J Initialisers
|
||||
canAlwaysEat = false;
|
||||
effectId = 0;
|
||||
effectDurationSeconds = 0;
|
||||
effectAmplifier = 0;
|
||||
effectProbability = 0.0f;
|
||||
}
|
||||
|
||||
FoodItem::FoodItem(int id, int nutrition, float saturationMod, bool isMeat)
|
||||
: Item( id ), nutrition(nutrition), saturationModifier( saturationMod ), m_isMeat( isMeat )
|
||||
{
|
||||
_init();
|
||||
: Item(id),
|
||||
nutrition(nutrition),
|
||||
saturationModifier(saturationMod),
|
||||
m_isMeat(isMeat) {
|
||||
_init();
|
||||
}
|
||||
|
||||
FoodItem::FoodItem(int id, int nutrition, bool isMeat)
|
||||
: Item( id ), nutrition(nutrition), saturationModifier( FoodConstants::FOOD_SATURATION_NORMAL ), m_isMeat( isMeat )
|
||||
{
|
||||
_init();
|
||||
: Item(id),
|
||||
nutrition(nutrition),
|
||||
saturationModifier(FoodConstants::FOOD_SATURATION_NORMAL),
|
||||
m_isMeat(isMeat) {
|
||||
_init();
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> FoodItem::useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
instance->count--;
|
||||
player->getFoodData()->eat(this);
|
||||
// 4J - new sound brought forward from 1.2.3
|
||||
level->playSound(player, eSoundType_RANDOM_BURP, 0.5f, level->random->nextFloat() * 0.1f + 0.9f);
|
||||
std::shared_ptr<ItemInstance> FoodItem::useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
instance->count--;
|
||||
player->getFoodData()->eat(this);
|
||||
// 4J - new sound brought forward from 1.2.3
|
||||
level->playSound(player, eSoundType_RANDOM_BURP, 0.5f,
|
||||
level->random->nextFloat() * 0.1f + 0.9f);
|
||||
|
||||
addEatEffect(instance, level, player);
|
||||
addEatEffect(instance, level, player);
|
||||
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FoodItem::addEatEffect(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!level->isClientSide && effectId > 0 && level->random->nextFloat() < effectProbability)
|
||||
{
|
||||
player->addEffect(new MobEffectInstance(effectId, effectDurationSeconds * SharedConstants::TICKS_PER_SECOND, effectAmplifier));
|
||||
}
|
||||
|
||||
void FoodItem::addEatEffect(std::shared_ptr<ItemInstance> instance,
|
||||
Level* level, std::shared_ptr<Player> player) {
|
||||
if (!level->isClientSide && effectId > 0 &&
|
||||
level->random->nextFloat() < effectProbability) {
|
||||
player->addEffect(new MobEffectInstance(
|
||||
effectId, effectDurationSeconds * SharedConstants::TICKS_PER_SECOND,
|
||||
effectAmplifier));
|
||||
}
|
||||
}
|
||||
|
||||
int FoodItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return EAT_DURATION;
|
||||
int FoodItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return EAT_DURATION;
|
||||
}
|
||||
|
||||
UseAnim FoodItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return UseAnim_eat;
|
||||
UseAnim FoodItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return UseAnim_eat;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> FoodItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (player->canEat(canAlwaysEat))
|
||||
{
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
}
|
||||
std::shared_ptr<ItemInstance> FoodItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (player->canEat(canAlwaysEat)) {
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
}
|
||||
|
||||
// 4J : WESTY : Other award ... eating cooked pork chop.
|
||||
// 4J-JEV: This is just for an avatar award on the xbox.
|
||||
#ifdef _XBOX
|
||||
if ( instance->getItem() == Item::porkChop_cooked )
|
||||
{
|
||||
player->awardStat(GenericStats::eatPorkChop(),GenericStats::param_eatPorkChop());
|
||||
}
|
||||
// 4J : WESTY : Other award ... eating cooked pork chop.
|
||||
// 4J-JEV: This is just for an avatar award on the xbox.
|
||||
#ifdef _XBOX
|
||||
if (instance->getItem() == Item::porkChop_cooked) {
|
||||
player->awardStat(GenericStats::eatPorkChop(),
|
||||
GenericStats::param_eatPorkChop());
|
||||
}
|
||||
#endif
|
||||
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
float FoodItem::getSaturationModifier()
|
||||
{
|
||||
return saturationModifier;
|
||||
float FoodItem::getSaturationModifier() { return saturationModifier; }
|
||||
|
||||
int FoodItem::getNutrition() { return nutrition; }
|
||||
|
||||
bool FoodItem::isMeat() { return m_isMeat; }
|
||||
|
||||
FoodItem* FoodItem::setEatEffect(int id, int durationInSecods, int amplifier,
|
||||
float effectProbability) {
|
||||
effectId = id;
|
||||
effectDurationSeconds = durationInSecods;
|
||||
effectAmplifier = amplifier;
|
||||
this->effectProbability = effectProbability;
|
||||
return this;
|
||||
}
|
||||
|
||||
int FoodItem::getNutrition()
|
||||
{
|
||||
return nutrition;
|
||||
}
|
||||
|
||||
bool FoodItem::isMeat()
|
||||
{
|
||||
return m_isMeat;
|
||||
}
|
||||
|
||||
FoodItem *FoodItem::setEatEffect(int id, int durationInSecods, int amplifier, float effectProbability)
|
||||
{
|
||||
effectId = id;
|
||||
effectDurationSeconds = durationInSecods;
|
||||
effectAmplifier = amplifier;
|
||||
this->effectProbability = effectProbability;
|
||||
return this;
|
||||
}
|
||||
|
||||
FoodItem *FoodItem::setCanAlwaysEat()
|
||||
{
|
||||
canAlwaysEat = true;
|
||||
return this;
|
||||
FoodItem* FoodItem::setCanAlwaysEat() {
|
||||
canAlwaysEat = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// 4J Added
|
||||
bool FoodItem::canEat(std::shared_ptr<Player> player)
|
||||
{
|
||||
return player->canEat(canAlwaysEat);
|
||||
bool FoodItem::canEat(std::shared_ptr<Player> player) {
|
||||
return player->canEat(canAlwaysEat);
|
||||
}
|
||||
|
||||
@@ -5,45 +5,51 @@
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class FoodItem : public Item
|
||||
{
|
||||
class FoodItem : public Item {
|
||||
public:
|
||||
static const int EAT_DURATION = (int) (20 * 1.6);
|
||||
static const int EAT_DURATION = (int)(20 * 1.6);
|
||||
|
||||
private:
|
||||
const int nutrition;
|
||||
const float saturationModifier;
|
||||
const bool m_isMeat;
|
||||
bool canAlwaysEat;
|
||||
const int nutrition;
|
||||
const float saturationModifier;
|
||||
const bool m_isMeat;
|
||||
bool canAlwaysEat;
|
||||
|
||||
int effectId;
|
||||
int effectDurationSeconds;
|
||||
int effectAmplifier;
|
||||
float effectProbability;
|
||||
int effectId;
|
||||
int effectDurationSeconds;
|
||||
int effectAmplifier;
|
||||
float effectProbability;
|
||||
|
||||
void _init();
|
||||
|
||||
void _init();
|
||||
public:
|
||||
FoodItem(int id, int nutrition, float saturationMod, bool isMeat);
|
||||
FoodItem(int id, int nutrition, bool isMeat);
|
||||
FoodItem(int id, int nutrition, float saturationMod, bool isMeat);
|
||||
FoodItem(int id, int nutrition, bool isMeat);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
|
||||
protected:
|
||||
virtual void addEatEffect(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual void addEatEffect(std::shared_ptr<ItemInstance> instance,
|
||||
Level* level, std::shared_ptr<Player> player);
|
||||
|
||||
public:
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
|
||||
int getNutrition();
|
||||
float getSaturationModifier();
|
||||
bool isMeat();
|
||||
int getNutrition();
|
||||
float getSaturationModifier();
|
||||
bool isMeat();
|
||||
|
||||
FoodItem *setEatEffect(int id, int durationInSecods, int amplifier, float effectProbability);
|
||||
FoodItem *setCanAlwaysEat();
|
||||
FoodItem* setEatEffect(int id, int durationInSecods, int amplifier,
|
||||
float effectProbability);
|
||||
FoodItem* setCanAlwaysEat();
|
||||
|
||||
// 4J Added
|
||||
bool canEat(std::shared_ptr<Player> player);
|
||||
// 4J Added
|
||||
bool canEat(std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -5,49 +5,52 @@
|
||||
#include "../Util/SharedConstants.h"
|
||||
#include "GoldenAppleItem.h"
|
||||
|
||||
GoldenAppleItem::GoldenAppleItem(int id, int nutrition, float saturationMod, bool isMeat) : FoodItem(id, nutrition, saturationMod, isMeat)
|
||||
{
|
||||
setStackedByData(true);
|
||||
GoldenAppleItem::GoldenAppleItem(int id, int nutrition, float saturationMod,
|
||||
bool isMeat)
|
||||
: FoodItem(id, nutrition, saturationMod, isMeat) {
|
||||
setStackedByData(true);
|
||||
}
|
||||
|
||||
bool GoldenAppleItem::isFoil(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return itemInstance->getAuxValue() > 0;
|
||||
bool GoldenAppleItem::isFoil(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return itemInstance->getAuxValue() > 0;
|
||||
}
|
||||
|
||||
const Rarity *GoldenAppleItem::getRarity(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
if (itemInstance->getAuxValue() == 0)
|
||||
{
|
||||
return Rarity::rare;
|
||||
}
|
||||
return Rarity::epic;
|
||||
const Rarity* GoldenAppleItem::getRarity(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
if (itemInstance->getAuxValue() == 0) {
|
||||
return Rarity::rare;
|
||||
}
|
||||
return Rarity::epic;
|
||||
}
|
||||
|
||||
void GoldenAppleItem::addEatEffect(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (instance->getAuxValue() > 0)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
player->addEffect(new MobEffectInstance(MobEffect::regeneration->id, 30 * SharedConstants::TICKS_PER_SECOND, 3));
|
||||
player->addEffect(new MobEffectInstance(MobEffect::damageResistance->id, 300 * SharedConstants::TICKS_PER_SECOND, 0));
|
||||
player->addEffect(new MobEffectInstance(MobEffect::fireResistance->id, 300 * SharedConstants::TICKS_PER_SECOND, 0));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FoodItem::addEatEffect(instance, level, player);
|
||||
}
|
||||
void GoldenAppleItem::addEatEffect(std::shared_ptr<ItemInstance> instance,
|
||||
Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (instance->getAuxValue() > 0) {
|
||||
if (!level->isClientSide) {
|
||||
player->addEffect(new MobEffectInstance(
|
||||
MobEffect::regeneration->id,
|
||||
30 * SharedConstants::TICKS_PER_SECOND, 3));
|
||||
player->addEffect(new MobEffectInstance(
|
||||
MobEffect::damageResistance->id,
|
||||
300 * SharedConstants::TICKS_PER_SECOND, 0));
|
||||
player->addEffect(new MobEffectInstance(
|
||||
MobEffect::fireResistance->id,
|
||||
300 * SharedConstants::TICKS_PER_SECOND, 0));
|
||||
}
|
||||
} else {
|
||||
FoodItem::addEatEffect(instance, level, player);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int GoldenAppleItem::getUseDescriptionId(int iData /*= -1*/)
|
||||
{
|
||||
if (iData == 0) return IDS_DESC_GOLDENAPPLE;
|
||||
else return IDS_DESC_ENCHANTED_GOLDENAPPLE;
|
||||
unsigned int GoldenAppleItem::getUseDescriptionId(int iData /*= -1*/) {
|
||||
if (iData == 0)
|
||||
return IDS_DESC_GOLDENAPPLE;
|
||||
else
|
||||
return IDS_DESC_ENCHANTED_GOLDENAPPLE;
|
||||
}
|
||||
|
||||
unsigned int GoldenAppleItem::getUseDescriptionId(std::shared_ptr<ItemInstance> instance)
|
||||
{
|
||||
return this->getUseDescriptionId(instance->getAuxValue());
|
||||
unsigned int GoldenAppleItem::getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance) {
|
||||
return this->getUseDescriptionId(instance->getAuxValue());
|
||||
}
|
||||
@@ -2,20 +2,22 @@
|
||||
|
||||
#include "FoodItem.h"
|
||||
|
||||
class GoldenAppleItem : public FoodItem
|
||||
{
|
||||
class GoldenAppleItem : public FoodItem {
|
||||
public:
|
||||
using Item::getUseDescriptionId;
|
||||
using Item::getUseDescriptionId;
|
||||
|
||||
GoldenAppleItem(int id, int nutrition, float saturationMod, bool isMeat);
|
||||
GoldenAppleItem(int id, int nutrition, float saturationMod, bool isMeat);
|
||||
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual const Rarity *getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual const Rarity* getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
|
||||
// 4J-JEV: Enchanted goldenapples and goldenapples each require their own tooltips.
|
||||
virtual unsigned int getUseDescriptionId(int iData /*= -1*/);
|
||||
virtual unsigned int getUseDescriptionId(std::shared_ptr<ItemInstance> instance);
|
||||
// 4J-JEV: Enchanted goldenapples and goldenapples each require their own
|
||||
// tooltips.
|
||||
virtual unsigned int getUseDescriptionId(int iData /*= -1*/);
|
||||
virtual unsigned int getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance);
|
||||
|
||||
protected:
|
||||
void addEatEffect(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
void addEatEffect(std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
|
||||
@@ -10,79 +10,77 @@
|
||||
#include "../Stats/GenericStats.h"
|
||||
#include "../Entities/Mobs/ItemFrame.h"
|
||||
|
||||
|
||||
HangingEntityItem::HangingEntityItem(int id, eINSTANCEOF eClassType) : Item(id)
|
||||
{
|
||||
//super(id);
|
||||
//this.clazz = clazz;
|
||||
this->eType=eClassType;
|
||||
// setItemCategory(CreativeModeTab.TAB_DECORATIONS);
|
||||
HangingEntityItem::HangingEntityItem(int id, eINSTANCEOF eClassType)
|
||||
: Item(id) {
|
||||
// super(id);
|
||||
// this.clazz = clazz;
|
||||
this->eType = eClassType;
|
||||
// setItemCategory(CreativeModeTab.TAB_DECORATIONS);
|
||||
}
|
||||
|
||||
bool HangingEntityItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int xt, int yt, int zt, int face, float clickX, float clickY, float clickZ, bool bTestOnly)
|
||||
{
|
||||
if (face == Facing::DOWN) return false;
|
||||
if (face == Facing::UP) return false;
|
||||
bool HangingEntityItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level,
|
||||
int xt, int yt, int zt, int face, float clickX,
|
||||
float clickY, float clickZ, bool bTestOnly) {
|
||||
if (face == Facing::DOWN) return false;
|
||||
if (face == Facing::UP) return false;
|
||||
|
||||
if(bTestOnly)
|
||||
{
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
if (bTestOnly) {
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int dir = Direction::FACING_DIRECTION[face];
|
||||
int dir = Direction::FACING_DIRECTION[face];
|
||||
|
||||
std::shared_ptr<HangingEntity> entity = createEntity(level, xt, yt, zt, dir);
|
||||
std::shared_ptr<HangingEntity> entity =
|
||||
createEntity(level, xt, yt, zt, dir);
|
||||
|
||||
//if (!player->mayUseItemAt(xt, yt, zt, face, instance)) return false;
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
// if (!player->mayUseItemAt(xt, yt, zt, face, instance)) return false;
|
||||
if (!player->mayBuild(xt, yt, zt)) return false;
|
||||
|
||||
if (entity != NULL && entity->survives())
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
if(level->addEntity(entity)==TRUE)
|
||||
{
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
if (eType==eTYPE_PAINTING) player->awardStat(GenericStats::blocksPlaced(Item::painting_Id), GenericStats::param_blocksPlaced(Item::painting_Id,instance->getAuxValue(),1));
|
||||
else if (eType==eTYPE_ITEM_FRAME) player->awardStat(GenericStats::blocksPlaced(Item::itemFrame_Id), GenericStats::param_blocksPlaced(Item::itemFrame_Id,instance->getAuxValue(),1));
|
||||
if (entity != NULL && entity->survives()) {
|
||||
if (!level->isClientSide) {
|
||||
if (level->addEntity(entity) == TRUE) {
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
if (eType == eTYPE_PAINTING)
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced(Item::painting_Id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
Item::painting_Id, instance->getAuxValue(), 1));
|
||||
else if (eType == eTYPE_ITEM_FRAME)
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced(Item::itemFrame_Id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
Item::itemFrame_Id, instance->getAuxValue(), 1));
|
||||
|
||||
instance->count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->displayClientMessage(IDS_MAX_HANGINGENTITIES );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
instance->count--;
|
||||
} else {
|
||||
player->displayClientMessage(IDS_MAX_HANGINGENTITIES);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
instance->count--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<HangingEntity> HangingEntityItem::createEntity(Level* level,
|
||||
int x, int y,
|
||||
int z, int dir) {
|
||||
if (eType == eTYPE_PAINTING) {
|
||||
std::shared_ptr<Painting> painting =
|
||||
std::shared_ptr<Painting>(new Painting(level, x, y, z, dir));
|
||||
painting->PaintingPostConstructor(dir);
|
||||
|
||||
std::shared_ptr<HangingEntity> HangingEntityItem::createEntity(Level *level, int x, int y, int z, int dir)
|
||||
{
|
||||
if (eType == eTYPE_PAINTING)
|
||||
{
|
||||
std::shared_ptr<Painting> painting = std::shared_ptr<Painting>(new Painting(level, x, y, z, dir));
|
||||
painting->PaintingPostConstructor(dir);
|
||||
|
||||
return std::dynamic_pointer_cast<HangingEntity> (painting);
|
||||
}
|
||||
else if (eType == eTYPE_ITEM_FRAME)
|
||||
{
|
||||
std::shared_ptr<ItemFrame> itemFrame = std::shared_ptr<ItemFrame>(new ItemFrame(level, x, y, z, dir));
|
||||
return std::dynamic_pointer_cast<HangingEntity>(painting);
|
||||
} else if (eType == eTYPE_ITEM_FRAME) {
|
||||
std::shared_ptr<ItemFrame> itemFrame =
|
||||
std::shared_ptr<ItemFrame>(new ItemFrame(level, x, y, z, dir));
|
||||
|
||||
return std::dynamic_pointer_cast<HangingEntity> (itemFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return std::dynamic_pointer_cast<HangingEntity>(itemFrame);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,18 +4,21 @@
|
||||
|
||||
class HangingEntity;
|
||||
|
||||
class HangingEntityItem : public Item
|
||||
{
|
||||
class HangingEntityItem : public Item {
|
||||
private:
|
||||
//final Class<? extends HangingEntity> clazz;
|
||||
eINSTANCEOF eType;
|
||||
// final Class<? extends HangingEntity> clazz;
|
||||
eINSTANCEOF eType;
|
||||
|
||||
public:
|
||||
HangingEntityItem(int id, eINSTANCEOF eClassType);
|
||||
HangingEntityItem(int id, eINSTANCEOF eClassType);
|
||||
|
||||
virtual bool useOn(
|
||||
std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player,
|
||||
Level* level, int xt, int yt, int zt, int face, float clickX,
|
||||
float clickY, float clickZ,
|
||||
bool bTestUseOnOnly); //, float clickX, float clickY, float clickZ);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int xt, int yt, int zt, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly);//, float clickX, float clickY, float clickZ);
|
||||
|
||||
private:
|
||||
std::shared_ptr<HangingEntity> createEntity(Level *level, int x, int y, int z, int dir) ;
|
||||
|
||||
std::shared_ptr<HangingEntity> createEntity(Level* level, int x, int y,
|
||||
int z, int dir);
|
||||
};
|
||||
|
||||
@@ -2,31 +2,28 @@
|
||||
#include "../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "HatchetItem.h"
|
||||
|
||||
TileArray *HatchetItem::diggables = NULL;
|
||||
TileArray* HatchetItem::diggables = NULL;
|
||||
|
||||
void HatchetItem::staticCtor()
|
||||
{
|
||||
HatchetItem::diggables = new TileArray( HATCHET_DIGGABLES);
|
||||
diggables->data[0] = Tile::wood;
|
||||
diggables->data[1] = Tile::bookshelf;
|
||||
diggables->data[2] = Tile::treeTrunk;
|
||||
diggables->data[3] = Tile::chest;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[4] = Tile::stoneSlab;
|
||||
diggables->data[5] = Tile::stoneSlabHalf;
|
||||
diggables->data[6] = Tile::pumpkin;
|
||||
diggables->data[7] = Tile::litPumpkin;
|
||||
void HatchetItem::staticCtor() {
|
||||
HatchetItem::diggables = new TileArray(HATCHET_DIGGABLES);
|
||||
diggables->data[0] = Tile::wood;
|
||||
diggables->data[1] = Tile::bookshelf;
|
||||
diggables->data[2] = Tile::treeTrunk;
|
||||
diggables->data[3] = Tile::chest;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[4] = Tile::stoneSlab;
|
||||
diggables->data[5] = Tile::stoneSlabHalf;
|
||||
diggables->data[6] = Tile::pumpkin;
|
||||
diggables->data[7] = Tile::litPumpkin;
|
||||
}
|
||||
|
||||
HatchetItem::HatchetItem(int id, const Tier *tier) : DiggerItem (id, 3, tier, diggables)
|
||||
{
|
||||
}
|
||||
HatchetItem::HatchetItem(int id, const Tier* tier)
|
||||
: DiggerItem(id, 3, tier, diggables) {}
|
||||
|
||||
// 4J - brought forward from 1.2.3
|
||||
float HatchetItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile)
|
||||
{
|
||||
if (tile != NULL && tile->material == Material::wood)
|
||||
{
|
||||
float HatchetItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile) {
|
||||
if (tile != NULL && tile->material == Material::wood) {
|
||||
return speed;
|
||||
}
|
||||
return DiggerItem::getDestroySpeed(itemInstance, tile);
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
#include "DiggerItem.h"
|
||||
|
||||
#define HATCHET_DIGGABLES 8
|
||||
class HatchetItem : public DiggerItem
|
||||
{
|
||||
class HatchetItem : public DiggerItem {
|
||||
private:
|
||||
static TileArray *diggables;
|
||||
static TileArray* diggables;
|
||||
|
||||
public:
|
||||
static void staticCtor();
|
||||
HatchetItem(int id, const Tier *tier);
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile); // 4J - brought forward from 1.2.3
|
||||
static void staticCtor();
|
||||
HatchetItem(int id, const Tier* tier);
|
||||
virtual float getDestroySpeed(
|
||||
std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile); // 4J - brought forward from 1.2.3
|
||||
};
|
||||
|
||||
@@ -5,47 +5,44 @@
|
||||
#include "ItemInstance.h"
|
||||
#include "HoeItem.h"
|
||||
|
||||
HoeItem::HoeItem(int id, const Tier *tier) : Item(id)
|
||||
{
|
||||
this->tier = tier;
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(tier->getUses());
|
||||
HoeItem::HoeItem(int id, const Tier* tier) : Item(id) {
|
||||
this->tier = tier;
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(tier->getUses());
|
||||
}
|
||||
|
||||
bool HoeItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
bool HoeItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly) {
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
|
||||
int targetType = level->getTile(x, y, z);
|
||||
// Material above = level.getMaterial(x, y + 1, z);
|
||||
int above = level->getTile(x, y + 1, z);
|
||||
int targetType = level->getTile(x, y, z);
|
||||
// Material above = level.getMaterial(x, y + 1, z);
|
||||
int above = level->getTile(x, y + 1, z);
|
||||
|
||||
// 4J-PB - missing parentheses
|
||||
if (face != 0 && above == 0 && (targetType == Tile::grass_Id || targetType == Tile::dirt_Id))
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
Tile *tile = Tile::farmland;
|
||||
level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, tile->soundType->getStepSound(), (tile->soundType->getVolume() + 1) / 2, tile->soundType->getPitch() * 0.8f);
|
||||
// 4J-PB - missing parentheses
|
||||
if (face != 0 && above == 0 &&
|
||||
(targetType == Tile::grass_Id || targetType == Tile::dirt_Id)) {
|
||||
if (!bTestUseOnOnly) {
|
||||
Tile* tile = Tile::farmland;
|
||||
level->playSound(x + 0.5f, y + 0.5f, z + 0.5f,
|
||||
tile->soundType->getStepSound(),
|
||||
(tile->soundType->getVolume() + 1) / 2,
|
||||
tile->soundType->getPitch() * 0.8f);
|
||||
|
||||
if (level->isClientSide) return true;
|
||||
level->setTile(x, y, z, tile->id);
|
||||
instance->hurt(1, player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (level->isClientSide) return true;
|
||||
level->setTile(x, y, z, tile->id);
|
||||
instance->hurt(1, player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HoeItem::isHandEquipped()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool HoeItem::isHandEquipped() { return true; }
|
||||
|
||||
const Item::Tier *HoeItem::getTier()
|
||||
{
|
||||
return tier;
|
||||
}
|
||||
const Item::Tier* HoeItem::getTier() { return tier; }
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class Player;
|
||||
|
||||
class HoeItem : public Item
|
||||
{
|
||||
class HoeItem : public Item {
|
||||
protected:
|
||||
const Tier *tier;
|
||||
const Tier* tier;
|
||||
|
||||
public:
|
||||
HoeItem(int id, const Tier *tier);
|
||||
HoeItem(int id, const Tier* tier);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool isHandEquipped();
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
virtual bool isHandEquipped();
|
||||
|
||||
const Tier *getTier();
|
||||
const Tier* getTier();
|
||||
};
|
||||
+1488
-896
File diff suppressed because it is too large
Load Diff
+657
-633
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "../Util/UseAnim.h"
|
||||
#include "../Headers/com.mojang.nbt.h"
|
||||
|
||||
@@ -16,20 +15,20 @@ class MapItem;
|
||||
class ItemFrame;
|
||||
class Icon;
|
||||
|
||||
// 4J Stu - While this is not really an abstract class, we don't want to make new instances of it,
|
||||
// mainly because there are too many ctors and that doesn't fit well into out macroisation setup
|
||||
class ItemInstance: public std::enable_shared_from_this<ItemInstance>
|
||||
{
|
||||
// 4J Stu - While this is not really an abstract class, we don't want to make
|
||||
// new instances of it, mainly because there are too many ctors and that doesn't
|
||||
// fit well into out macroisation setup
|
||||
class ItemInstance : public std::enable_shared_from_this<ItemInstance> {
|
||||
public:
|
||||
static const wchar_t *TAG_ENCH_ID;
|
||||
static const wchar_t *TAG_ENCH_LEVEL;
|
||||
static const wchar_t* TAG_ENCH_ID;
|
||||
static const wchar_t* TAG_ENCH_LEVEL;
|
||||
|
||||
int count;
|
||||
int count;
|
||||
int popTime;
|
||||
int id;
|
||||
|
||||
// 4J Stu - Brought forward for enchanting/game rules
|
||||
CompoundTag *tag;
|
||||
// 4J Stu - Brought forward for enchanting/game rules
|
||||
CompoundTag* tag;
|
||||
|
||||
/**
|
||||
* This was previously the damage value, but is now used for different stuff
|
||||
@@ -37,118 +36,142 @@ public:
|
||||
* is interpreted correctly.
|
||||
*/
|
||||
private:
|
||||
int auxValue;
|
||||
// 4J-PB - added for trading menu
|
||||
bool m_bForceNumberDisplay;
|
||||
int auxValue;
|
||||
// 4J-PB - added for trading menu
|
||||
bool m_bForceNumberDisplay;
|
||||
|
||||
void _init(int id, int count, int auxValue);
|
||||
void _init(int id, int count, int auxValue);
|
||||
|
||||
// TU9
|
||||
std::shared_ptr<ItemFrame> frame;
|
||||
// TU9
|
||||
std::shared_ptr<ItemFrame> frame;
|
||||
|
||||
public:
|
||||
ItemInstance(Tile *tile);
|
||||
ItemInstance(Tile *tile, int count);
|
||||
ItemInstance(Tile *tile, int count, int auxValue);
|
||||
ItemInstance(Item *item);
|
||||
// 4J-PB - added
|
||||
ItemInstance(MapItem *item, int count);
|
||||
ItemInstance(Tile* tile);
|
||||
ItemInstance(Tile* tile, int count);
|
||||
ItemInstance(Tile* tile, int count, int auxValue);
|
||||
ItemInstance(Item* item);
|
||||
// 4J-PB - added
|
||||
ItemInstance(MapItem* item, int count);
|
||||
|
||||
ItemInstance(Item *item, int count);
|
||||
ItemInstance(Item *item, int count, int auxValue);
|
||||
ItemInstance(int id, int count, int damage);
|
||||
ItemInstance(Item* item, int count);
|
||||
ItemInstance(Item* item, int count, int auxValue);
|
||||
ItemInstance(int id, int count, int damage);
|
||||
|
||||
static std::shared_ptr<ItemInstance> fromTag(CompoundTag *itemTag);
|
||||
private:
|
||||
ItemInstance() { _init(-1,0,0); }
|
||||
|
||||
public:
|
||||
virtual ~ItemInstance();
|
||||
std::shared_ptr<ItemInstance> remove(int count);
|
||||
|
||||
Item *getItem() const;
|
||||
Icon *getIcon();
|
||||
int getIconType();
|
||||
bool useOn(std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX = 0.0f, float clickY = 0.0f, float clickZ = 0.0f, bool bTestUseOnOnly=false);
|
||||
float getDestroySpeed(Tile *tile);
|
||||
bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<ItemInstance> use(Level *level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<ItemInstance> useTimeDepleted(Level *level, std::shared_ptr<Player> player);
|
||||
CompoundTag *save(CompoundTag *compoundTag);
|
||||
void load(CompoundTag *compoundTag);
|
||||
int getMaxStackSize();
|
||||
bool isStackable();
|
||||
bool isDamageableItem();
|
||||
bool isStackedByData();
|
||||
bool isDamaged();
|
||||
int getDamageValue();
|
||||
int getAuxValue() const;
|
||||
void setAuxValue(int value);
|
||||
int getMaxDamage();
|
||||
void hurt(int i, std::shared_ptr<Mob> owner);
|
||||
void hurtEnemy(std::shared_ptr<Mob> mob, std::shared_ptr<Player> attacker);
|
||||
void mineBlock(Level *level, int tile, int x, int y, int z, std::shared_ptr<Player> owner);
|
||||
int getAttackDamage(std::shared_ptr<Entity> entity);
|
||||
bool canDestroySpecial(Tile *tile);
|
||||
bool interactEnemy(std::shared_ptr<Mob> mob);
|
||||
std::shared_ptr<ItemInstance> copy() const;
|
||||
ItemInstance *copy_not_shared() const; // 4J Stu - Added for use in recipes
|
||||
static bool tagMatches(std::shared_ptr<ItemInstance> a, std::shared_ptr<ItemInstance> b); // 4J Brought forward from 1.2
|
||||
static bool matches(std::shared_ptr<ItemInstance> a, std::shared_ptr<ItemInstance> b);
|
||||
|
||||
// 4J-PB
|
||||
int GetCount() {return count;}
|
||||
void ForceNumberDisplay(bool bForce) {m_bForceNumberDisplay=bForce;} // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
|
||||
bool GetForceNumberDisplay() {return m_bForceNumberDisplay;} // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
|
||||
static std::shared_ptr<ItemInstance> fromTag(CompoundTag* itemTag);
|
||||
|
||||
private:
|
||||
bool matches(std::shared_ptr<ItemInstance> b);
|
||||
ItemInstance() { _init(-1, 0, 0); }
|
||||
|
||||
public:
|
||||
bool sameItem(std::shared_ptr<ItemInstance> b);
|
||||
bool sameItemWithTags(std::shared_ptr<ItemInstance> b); //4J Added
|
||||
bool sameItem_not_shared(ItemInstance *b); // 4J Stu - Added this for the one time I need it
|
||||
virtual unsigned int getUseDescriptionId(); // 4J Added
|
||||
virtual unsigned int getDescriptionId(int iData = -1);
|
||||
virtual ItemInstance *setDescriptionId(unsigned int id);
|
||||
static std::shared_ptr<ItemInstance> clone(std::shared_ptr<ItemInstance> item);
|
||||
std::wstring toString();
|
||||
void inventoryTick(Level *level, std::shared_ptr<Entity> owner, int slot, bool selected);
|
||||
void onCraftedBy(Level *level, std::shared_ptr<Player> player, int craftCount);
|
||||
bool equals(std::shared_ptr<ItemInstance> ii);
|
||||
virtual ~ItemInstance();
|
||||
std::shared_ptr<ItemInstance> remove(int count);
|
||||
|
||||
int getUseDuration();
|
||||
UseAnim getUseAnimation();
|
||||
void releaseUsing(Level *level, std::shared_ptr<Player> player, int durationLeft);
|
||||
Item* getItem() const;
|
||||
Icon* getIcon();
|
||||
int getIconType();
|
||||
bool useOn(std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX = 0.0f, float clickY = 0.0f,
|
||||
float clickZ = 0.0f, bool bTestUseOnOnly = false);
|
||||
float getDestroySpeed(Tile* tile);
|
||||
bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<ItemInstance> use(Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
Level* level, std::shared_ptr<Player> player);
|
||||
CompoundTag* save(CompoundTag* compoundTag);
|
||||
void load(CompoundTag* compoundTag);
|
||||
int getMaxStackSize();
|
||||
bool isStackable();
|
||||
bool isDamageableItem();
|
||||
bool isStackedByData();
|
||||
bool isDamaged();
|
||||
int getDamageValue();
|
||||
int getAuxValue() const;
|
||||
void setAuxValue(int value);
|
||||
int getMaxDamage();
|
||||
void hurt(int i, std::shared_ptr<Mob> owner);
|
||||
void hurtEnemy(std::shared_ptr<Mob> mob, std::shared_ptr<Player> attacker);
|
||||
void mineBlock(Level* level, int tile, int x, int y, int z,
|
||||
std::shared_ptr<Player> owner);
|
||||
int getAttackDamage(std::shared_ptr<Entity> entity);
|
||||
bool canDestroySpecial(Tile* tile);
|
||||
bool interactEnemy(std::shared_ptr<Mob> mob);
|
||||
std::shared_ptr<ItemInstance> copy() const;
|
||||
ItemInstance* copy_not_shared() const; // 4J Stu - Added for use in recipes
|
||||
static bool tagMatches(
|
||||
std::shared_ptr<ItemInstance> a,
|
||||
std::shared_ptr<ItemInstance> b); // 4J Brought forward from 1.2
|
||||
static bool matches(std::shared_ptr<ItemInstance> a,
|
||||
std::shared_ptr<ItemInstance> b);
|
||||
|
||||
// 4J Stu - Brought forward these functions for enchanting/game rules
|
||||
bool hasTag();
|
||||
CompoundTag *getTag();
|
||||
ListTag<CompoundTag> *getEnchantmentTags();
|
||||
void setTag(CompoundTag *tag);
|
||||
std::wstring getHoverName();
|
||||
void setHoverName(const std::wstring &name);
|
||||
bool hasCustomHoverName();
|
||||
std::vector<std::wstring> *getHoverText(std::shared_ptr<Player> player, bool advanced, std::vector<std::wstring> &unformattedStrings);
|
||||
std::vector<std::wstring> *getHoverTextOnly(std::shared_ptr<Player> player, bool advanced, std::vector<std::wstring> &unformattedStrings); // 4J Added
|
||||
bool isFoil();
|
||||
const Rarity *getRarity();
|
||||
bool isEnchantable();
|
||||
void enchant(const Enchantment *enchantment, int level);
|
||||
bool isEnchanted();
|
||||
void addTagElement(std::wstring name, Tag *tag);
|
||||
// 4J-PB
|
||||
int GetCount() { return count; }
|
||||
void ForceNumberDisplay(bool bForce) {
|
||||
m_bForceNumberDisplay = bForce;
|
||||
} // to force the display of 0 and 1 on the required trading items when you
|
||||
// have o or 1 of the item
|
||||
bool GetForceNumberDisplay() {
|
||||
return m_bForceNumberDisplay;
|
||||
} // to force the display of 0 and 1 on the required trading items when you
|
||||
// have o or 1 of the item
|
||||
|
||||
// 4J Added
|
||||
void set4JData(int data);
|
||||
int get4JData();
|
||||
bool hasPotionStrengthBar();
|
||||
int GetPotionStrength();
|
||||
private:
|
||||
bool matches(std::shared_ptr<ItemInstance> b);
|
||||
|
||||
// TU9
|
||||
bool isFramed();
|
||||
void setFramed(std::shared_ptr<ItemFrame> frame);
|
||||
std::shared_ptr<ItemFrame> getFrame();
|
||||
public:
|
||||
bool sameItem(std::shared_ptr<ItemInstance> b);
|
||||
bool sameItemWithTags(std::shared_ptr<ItemInstance> b); // 4J Added
|
||||
bool sameItem_not_shared(
|
||||
ItemInstance* b); // 4J Stu - Added this for the one time I need it
|
||||
virtual unsigned int getUseDescriptionId(); // 4J Added
|
||||
virtual unsigned int getDescriptionId(int iData = -1);
|
||||
virtual ItemInstance* setDescriptionId(unsigned int id);
|
||||
static std::shared_ptr<ItemInstance> clone(
|
||||
std::shared_ptr<ItemInstance> item);
|
||||
std::wstring toString();
|
||||
void inventoryTick(Level* level, std::shared_ptr<Entity> owner, int slot,
|
||||
bool selected);
|
||||
void onCraftedBy(Level* level, std::shared_ptr<Player> player,
|
||||
int craftCount);
|
||||
bool equals(std::shared_ptr<ItemInstance> ii);
|
||||
|
||||
int getBaseRepairCost();
|
||||
void setRepairCost(int cost);
|
||||
int getUseDuration();
|
||||
UseAnim getUseAnimation();
|
||||
void releaseUsing(Level* level, std::shared_ptr<Player> player,
|
||||
int durationLeft);
|
||||
|
||||
// 4J Stu - Brought forward these functions for enchanting/game rules
|
||||
bool hasTag();
|
||||
CompoundTag* getTag();
|
||||
ListTag<CompoundTag>* getEnchantmentTags();
|
||||
void setTag(CompoundTag* tag);
|
||||
std::wstring getHoverName();
|
||||
void setHoverName(const std::wstring& name);
|
||||
bool hasCustomHoverName();
|
||||
std::vector<std::wstring>* getHoverText(
|
||||
std::shared_ptr<Player> player, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings);
|
||||
std::vector<std::wstring>* getHoverTextOnly(
|
||||
std::shared_ptr<Player> player, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings); // 4J Added
|
||||
bool isFoil();
|
||||
const Rarity* getRarity();
|
||||
bool isEnchantable();
|
||||
void enchant(const Enchantment* enchantment, int level);
|
||||
bool isEnchanted();
|
||||
void addTagElement(std::wstring name, Tag* tag);
|
||||
|
||||
// 4J Added
|
||||
void set4JData(int data);
|
||||
int get4JData();
|
||||
bool hasPotionStrengthBar();
|
||||
int GetPotionStrength();
|
||||
|
||||
// TU9
|
||||
bool isFramed();
|
||||
void setFramed(std::shared_ptr<ItemFrame> frame);
|
||||
std::shared_ptr<ItemFrame> getFrame();
|
||||
|
||||
int getBaseRepairCost();
|
||||
void setRepairCost(int cost);
|
||||
};
|
||||
|
||||
+274
-272
@@ -14,334 +14,336 @@
|
||||
#include "../Headers/net.minecraft.world.inventory.h"
|
||||
#include "../Util/JavaMath.h"
|
||||
|
||||
MapItem::MapItem(int id) : ComplexItem(id)
|
||||
{
|
||||
this->setMaxStackSize(1);
|
||||
MapItem::MapItem(int id) : ComplexItem(id) { this->setMaxStackSize(1); }
|
||||
|
||||
std::shared_ptr<MapItemSavedData> MapItem::getSavedData(short idNum,
|
||||
Level* level) {
|
||||
std::wstring id = std::wstring(L"map_") + _toString(idNum);
|
||||
std::shared_ptr<MapItemSavedData> mapItemSavedData =
|
||||
std::dynamic_pointer_cast<MapItemSavedData>(
|
||||
level->getSavedData(typeid(MapItemSavedData), id));
|
||||
|
||||
if (mapItemSavedData == NULL) {
|
||||
// 4J Stu - This call comes from ClientConnection, but i don't see why
|
||||
// we should be trying to work out the id again when it's passed as a
|
||||
// param. In any case that won't work with the new map setup
|
||||
// int aux = level->getFreeAuxValueFor(L"map");
|
||||
int aux = idNum;
|
||||
|
||||
id = std::wstring(L"map_") + _toString(aux);
|
||||
mapItemSavedData =
|
||||
std::shared_ptr<MapItemSavedData>(new MapItemSavedData(id));
|
||||
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData>)mapItemSavedData);
|
||||
}
|
||||
|
||||
return mapItemSavedData;
|
||||
}
|
||||
|
||||
std::shared_ptr<MapItemSavedData> MapItem::getSavedData(short idNum, Level *level)
|
||||
{
|
||||
std::wstring id = std::wstring( L"map_" ) + _toString(idNum);
|
||||
std::shared_ptr<MapItemSavedData> mapItemSavedData = std::dynamic_pointer_cast<MapItemSavedData>(level->getSavedData(typeid(MapItemSavedData), id));
|
||||
std::shared_ptr<MapItemSavedData> MapItem::getSavedData(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level) {
|
||||
MemSect(31);
|
||||
std::wstring id =
|
||||
std::wstring(L"map_") + _toString(itemInstance->getAuxValue());
|
||||
MemSect(0);
|
||||
std::shared_ptr<MapItemSavedData> mapItemSavedData =
|
||||
std::dynamic_pointer_cast<MapItemSavedData>(
|
||||
level->getSavedData(typeid(MapItemSavedData), id));
|
||||
|
||||
if (mapItemSavedData == NULL)
|
||||
{
|
||||
// 4J Stu - This call comes from ClientConnection, but i don't see why we should be trying to work out
|
||||
// the id again when it's passed as a param. In any case that won't work with the new map setup
|
||||
//int aux = level->getFreeAuxValueFor(L"map");
|
||||
int aux = idNum;
|
||||
bool newData = false;
|
||||
if (mapItemSavedData == NULL) {
|
||||
// 4J Stu - I don't see why we should be trying to work out the id again
|
||||
// when it's passed as a param. In any case that won't work with the new
|
||||
// map setup
|
||||
// itemInstance->setAuxValue(level->getFreeAuxValueFor(L"map"));
|
||||
|
||||
id = std::wstring( L"map_" ) + _toString(aux);
|
||||
mapItemSavedData = std::shared_ptr<MapItemSavedData>( new MapItemSavedData(id) );
|
||||
id = std::wstring(L"map_") + _toString(itemInstance->getAuxValue());
|
||||
mapItemSavedData =
|
||||
std::shared_ptr<MapItemSavedData>(new MapItemSavedData(id));
|
||||
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData> ) mapItemSavedData);
|
||||
}
|
||||
newData = true;
|
||||
}
|
||||
|
||||
return mapItemSavedData;
|
||||
}
|
||||
|
||||
std::shared_ptr<MapItemSavedData> MapItem::getSavedData(std::shared_ptr<ItemInstance> itemInstance, Level *level)
|
||||
{
|
||||
MemSect(31);
|
||||
std::wstring id = std::wstring( L"map_" ) + _toString(itemInstance->getAuxValue() );
|
||||
MemSect(0);
|
||||
std::shared_ptr<MapItemSavedData> mapItemSavedData = std::dynamic_pointer_cast<MapItemSavedData>( level->getSavedData(typeid(MapItemSavedData), id ) );
|
||||
|
||||
bool newData = false;
|
||||
if (mapItemSavedData == NULL)
|
||||
{
|
||||
// 4J Stu - I don't see why we should be trying to work out the id again when it's passed as a param.
|
||||
// In any case that won't work with the new map setup
|
||||
//itemInstance->setAuxValue(level->getFreeAuxValueFor(L"map"));
|
||||
|
||||
id = std::wstring( L"map_" ) + _toString(itemInstance->getAuxValue() );
|
||||
mapItemSavedData = std::shared_ptr<MapItemSavedData>( new MapItemSavedData(id) );
|
||||
|
||||
newData = true;
|
||||
}
|
||||
|
||||
mapItemSavedData->scale = 3;
|
||||
mapItemSavedData->scale = 3;
|
||||
#ifndef _LARGE_WORLDS
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map
|
||||
mapItemSavedData->x = 0;
|
||||
mapItemSavedData->z = 0;
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world,
|
||||
// since we can fit the whole world in our map
|
||||
mapItemSavedData->x = 0;
|
||||
mapItemSavedData->z = 0;
|
||||
#endif
|
||||
|
||||
if( newData )
|
||||
{
|
||||
if (newData) {
|
||||
#ifdef _LARGE_WORLDS
|
||||
int scale = MapItemSavedData::MAP_SIZE * 2 * (1 << mapItemSavedData->scale);
|
||||
mapItemSavedData->x = Math::round((float) level->getLevelData()->getXSpawn() / scale) * scale;
|
||||
mapItemSavedData->z = Math::round(level->getLevelData()->getZSpawn() / scale) * scale;
|
||||
int scale =
|
||||
MapItemSavedData::MAP_SIZE * 2 * (1 << mapItemSavedData->scale);
|
||||
mapItemSavedData->x =
|
||||
Math::round((float)level->getLevelData()->getXSpawn() / scale) *
|
||||
scale;
|
||||
mapItemSavedData->z =
|
||||
Math::round(level->getLevelData()->getZSpawn() / scale) * scale;
|
||||
#endif
|
||||
mapItemSavedData->dimension = (uint8_t) level->dimension->id;
|
||||
|
||||
mapItemSavedData->setDirty();
|
||||
mapItemSavedData->dimension = (uint8_t)level->dimension->id;
|
||||
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData> ) mapItemSavedData);
|
||||
}
|
||||
mapItemSavedData->setDirty();
|
||||
|
||||
return mapItemSavedData;
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData>)mapItemSavedData);
|
||||
}
|
||||
|
||||
return mapItemSavedData;
|
||||
}
|
||||
|
||||
void MapItem::update(Level *level, std::shared_ptr<Entity> player, std::shared_ptr<MapItemSavedData> data)
|
||||
{
|
||||
if (level->dimension->id != data->dimension)
|
||||
{
|
||||
// Wrong dimension, abort
|
||||
return;
|
||||
}
|
||||
void MapItem::update(Level* level, std::shared_ptr<Entity> player,
|
||||
std::shared_ptr<MapItemSavedData> data) {
|
||||
if (level->dimension->id != data->dimension) {
|
||||
// Wrong dimension, abort
|
||||
return;
|
||||
}
|
||||
|
||||
int w = MapItem::IMAGE_WIDTH;
|
||||
int h = MapItem::IMAGE_HEIGHT;
|
||||
int w = MapItem::IMAGE_WIDTH;
|
||||
int h = MapItem::IMAGE_HEIGHT;
|
||||
|
||||
int scale = 1 << data->scale;
|
||||
int scale = 1 << data->scale;
|
||||
|
||||
int xo = data->x;
|
||||
int zo = data->z;
|
||||
int xo = data->x;
|
||||
int zo = data->z;
|
||||
|
||||
int xp = Mth::floor(player->x - xo) / scale + w / 2;
|
||||
int zp = Mth::floor(player->z - zo) / scale + h / 2;
|
||||
int xp = Mth::floor(player->x - xo) / scale + w / 2;
|
||||
int zp = Mth::floor(player->z - zo) / scale + h / 2;
|
||||
|
||||
int rad = 128 / scale;
|
||||
if (level->dimension->hasCeiling)
|
||||
{
|
||||
rad /= 2;
|
||||
}
|
||||
data->step++;
|
||||
int rad = 128 / scale;
|
||||
if (level->dimension->hasCeiling) {
|
||||
rad /= 2;
|
||||
}
|
||||
data->step++;
|
||||
|
||||
for (int x = xp - rad + 1; x < xp + rad; x++)
|
||||
{
|
||||
if ((x & 15) != (data->step & 15)) continue;
|
||||
for (int x = xp - rad + 1; x < xp + rad; x++) {
|
||||
if ((x & 15) != (data->step & 15)) continue;
|
||||
|
||||
int yd0 = 255;
|
||||
int yd1 = 0;
|
||||
int yd0 = 255;
|
||||
int yd1 = 0;
|
||||
|
||||
double ho = 0;
|
||||
for (int z = zp - rad - 1; z < zp + rad; z++)
|
||||
{
|
||||
if (x < 0 || z < -1 || x >= w || z >= h) continue;
|
||||
double ho = 0;
|
||||
for (int z = zp - rad - 1; z < zp + rad; z++) {
|
||||
if (x < 0 || z < -1 || x >= w || z >= h) continue;
|
||||
|
||||
int xd = x - xp;
|
||||
int zd = z - zp;
|
||||
int xd = x - xp;
|
||||
int zd = z - zp;
|
||||
|
||||
bool ditherBlack = xd * xd + zd * zd > (rad - 2) * (rad - 2);
|
||||
bool ditherBlack = xd * xd + zd * zd > (rad - 2) * (rad - 2);
|
||||
|
||||
int xx = (xo / scale + x - w / 2) * scale;
|
||||
int zz = (zo / scale + z - h / 2) * scale;
|
||||
int xx = (xo / scale + x - w / 2) * scale;
|
||||
int zz = (zo / scale + z - h / 2) * scale;
|
||||
|
||||
int r = 0;
|
||||
int g = 0;
|
||||
int b = 0;
|
||||
int r = 0;
|
||||
int g = 0;
|
||||
int b = 0;
|
||||
|
||||
int count[256];
|
||||
memset(count, 0, sizeof(int) * 256);
|
||||
|
||||
int count[256];
|
||||
memset( count,0,sizeof(int)*256);
|
||||
LevelChunk* lc = level->getChunkAt(xx, zz);
|
||||
if (lc->isEmpty()) continue;
|
||||
int xso = ((xx)) & 15;
|
||||
int zso = ((zz)) & 15;
|
||||
int liquidDepth = 0;
|
||||
|
||||
LevelChunk *lc = level->getChunkAt(xx, zz);
|
||||
if(lc->isEmpty()) continue;
|
||||
int xso = ((xx)) & 15;
|
||||
int zso = ((zz)) & 15;
|
||||
int liquidDepth = 0;
|
||||
double hh = 0;
|
||||
if (level->dimension->hasCeiling) {
|
||||
int ss = xx + zz * 231871;
|
||||
ss = ss * ss * 31287121 + ss * 11;
|
||||
if (((ss >> 20) & 1) == 0)
|
||||
count[Tile::dirt_Id] += 10;
|
||||
else
|
||||
count[Tile::rock_Id] += 10;
|
||||
hh = 100;
|
||||
} else {
|
||||
for (int xs = 0; xs < scale; xs++) {
|
||||
for (int zs = 0; zs < scale; zs++) {
|
||||
int yy = lc->getHeightmap(xs + xso, zs + zso) + 1;
|
||||
int t = 0;
|
||||
if (yy > 1) {
|
||||
bool ok = false;
|
||||
do {
|
||||
ok = true;
|
||||
t = lc->getTile(xs + xso, yy - 1, zs + zso);
|
||||
if (t == 0)
|
||||
ok = false;
|
||||
else if (yy > 0 && t > 0 &&
|
||||
Tile::tiles[t]->material->color ==
|
||||
MaterialColor::none) {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
double hh = 0;
|
||||
if (level->dimension->hasCeiling)
|
||||
{
|
||||
int ss = xx + zz * 231871;
|
||||
ss = ss * ss * 31287121 + ss * 11;
|
||||
if (((ss >> 20) & 1) == 0) count[Tile::dirt_Id] += 10;
|
||||
else count[Tile::rock_Id] += 10;
|
||||
hh = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int xs = 0; xs < scale; xs++)
|
||||
{
|
||||
for (int zs = 0; zs < scale; zs++)
|
||||
{
|
||||
int yy = lc->getHeightmap(xs + xso, zs + zso) + 1;
|
||||
int t = 0;
|
||||
if (yy > 1)
|
||||
{
|
||||
bool ok = false;
|
||||
do
|
||||
{
|
||||
ok = true;
|
||||
t = lc->getTile(xs + xso, yy - 1, zs + zso);
|
||||
if (t == 0) ok = false;
|
||||
else if (yy > 0 && t > 0 && Tile::tiles[t]->material->color == MaterialColor::none)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) {
|
||||
yy--;
|
||||
if (yy <= 0) break;
|
||||
t = lc->getTile(xs + xso, yy - 1, zs + zso);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
yy--;
|
||||
if (yy <= 0) break;
|
||||
t = lc->getTile(xs + xso, yy - 1, zs + zso);
|
||||
}
|
||||
} while (yy > 0 && !ok);
|
||||
|
||||
} while (yy > 0 && !ok);
|
||||
if (yy > 0 && t != 0 &&
|
||||
Tile::tiles[t]->material->isLiquid()) {
|
||||
int y = yy - 1;
|
||||
int below = 0;
|
||||
do {
|
||||
below =
|
||||
lc->getTile(xs + xso, y--, zs + zso);
|
||||
liquidDepth++;
|
||||
} while (
|
||||
y > 0 && below != 0 &&
|
||||
Tile::tiles[below]->material->isLiquid());
|
||||
}
|
||||
}
|
||||
hh += yy / (double)(scale * scale);
|
||||
|
||||
if (yy > 0 && t != 0 && Tile::tiles[t]->material->isLiquid())
|
||||
{
|
||||
int y = yy - 1;
|
||||
int below = 0;
|
||||
do
|
||||
{
|
||||
below = lc->getTile(xs + xso, y--, zs + zso);
|
||||
liquidDepth++;
|
||||
} while (y > 0 && below != 0 && Tile::tiles[below]->material->isLiquid());
|
||||
}
|
||||
}
|
||||
hh += yy / (double) (scale * scale);
|
||||
count[t]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
liquidDepth /= scale * scale;
|
||||
r /= scale * scale;
|
||||
g /= scale * scale;
|
||||
b /= scale * scale;
|
||||
|
||||
count[t]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
liquidDepth /= scale * scale;
|
||||
r /= scale * scale;
|
||||
g /= scale * scale;
|
||||
b /= scale * scale;
|
||||
int best = 0;
|
||||
int tBest = 0;
|
||||
for (int j = 0; j < 256; j++) {
|
||||
if (count[j] > best) {
|
||||
tBest = j;
|
||||
best = count[j];
|
||||
}
|
||||
}
|
||||
|
||||
int best = 0;
|
||||
int tBest = 0;
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
if (count[j] > best)
|
||||
{
|
||||
tBest = j;
|
||||
best = count[j];
|
||||
}
|
||||
}
|
||||
double diff =
|
||||
((hh - ho) * 4 / (scale + 4)) + (((x + z) & 1) - 0.5) * 0.4;
|
||||
int br = 1;
|
||||
if (diff > +0.6) br = 2;
|
||||
if (diff < -0.6) br = 0;
|
||||
|
||||
double diff = ((hh - ho) * 4 / (scale + 4)) + (((x + z) & 1) - 0.5) * 0.4;
|
||||
int br = 1;
|
||||
if (diff > +0.6) br = 2;
|
||||
if (diff < -0.6) br = 0;
|
||||
int col = 0;
|
||||
if (tBest > 0) {
|
||||
MaterialColor* mc = Tile::tiles[tBest]->material->color;
|
||||
if (mc == MaterialColor::water) {
|
||||
diff = (liquidDepth * 0.1) + ((x + z) & 1) * 0.2;
|
||||
br = 1;
|
||||
if (diff < 0.5) br = 2;
|
||||
if (diff > 0.9) br = 0;
|
||||
}
|
||||
col = mc->id;
|
||||
}
|
||||
|
||||
int col = 0;
|
||||
if (tBest > 0)
|
||||
{
|
||||
MaterialColor *mc = Tile::tiles[tBest]->material->color;
|
||||
if (mc == MaterialColor::water)
|
||||
{
|
||||
diff = (liquidDepth * 0.1) + ((x + z) & 1) * 0.2;
|
||||
br = 1;
|
||||
if (diff < 0.5) br = 2;
|
||||
if (diff > 0.9) br = 0;
|
||||
}
|
||||
col = mc->id;
|
||||
}
|
||||
ho = hh;
|
||||
|
||||
ho = hh;
|
||||
|
||||
if (z < 0) continue;
|
||||
if (xd * xd + zd * zd >= rad * rad) continue;
|
||||
if (ditherBlack && ((x + z) & 1) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
uint8_t oldColor = data->colors[x + z * w];
|
||||
uint8_t newColor = (uint8_t) (col * 4 + br);
|
||||
if (oldColor != newColor)
|
||||
{
|
||||
if (yd0 > z) yd0 = z;
|
||||
if (yd1 < z) yd1 = z;
|
||||
data->colors[x + z * w] = newColor;
|
||||
}
|
||||
}
|
||||
if (yd0 <= yd1)
|
||||
{
|
||||
data->setDirty(x, yd0, yd1);
|
||||
}
|
||||
}
|
||||
if (z < 0) continue;
|
||||
if (xd * xd + zd * zd >= rad * rad) continue;
|
||||
if (ditherBlack && ((x + z) & 1) == 0) {
|
||||
continue;
|
||||
}
|
||||
uint8_t oldColor = data->colors[x + z * w];
|
||||
uint8_t newColor = (uint8_t)(col * 4 + br);
|
||||
if (oldColor != newColor) {
|
||||
if (yd0 > z) yd0 = z;
|
||||
if (yd1 < z) yd1 = z;
|
||||
data->colors[x + z * w] = newColor;
|
||||
}
|
||||
}
|
||||
if (yd0 <= yd1) {
|
||||
data->setDirty(x, yd0, yd1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapItem::inventoryTick(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Entity> owner, int slot, bool selected)
|
||||
{
|
||||
if (level->isClientSide) return;
|
||||
void MapItem::inventoryTick(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Entity> owner,
|
||||
int slot, bool selected) {
|
||||
if (level->isClientSide) return;
|
||||
|
||||
std::shared_ptr<MapItemSavedData> data = getSavedData(itemInstance, level);
|
||||
if (std::dynamic_pointer_cast<Player>(owner) != NULL)
|
||||
{
|
||||
std::shared_ptr<Player> player = std::dynamic_pointer_cast<Player>(owner);
|
||||
std::shared_ptr<MapItemSavedData> data = getSavedData(itemInstance, level);
|
||||
if (std::dynamic_pointer_cast<Player>(owner) != NULL) {
|
||||
std::shared_ptr<Player> player =
|
||||
std::dynamic_pointer_cast<Player>(owner);
|
||||
|
||||
// 4J Stu - If the player has a map that belongs to another player, then merge the data over and change this map id to the owners id
|
||||
int ownersAuxValue = level->getAuxValueForMap(player->getXuid(), data->dimension, data->x, data->z, data->scale);
|
||||
if(ownersAuxValue != itemInstance->getAuxValue() )
|
||||
{
|
||||
std::shared_ptr<MapItemSavedData> ownersData = getSavedData(ownersAuxValue,level);
|
||||
// 4J Stu - If the player has a map that belongs to another player, then
|
||||
// merge the data over and change this map id to the owners id
|
||||
int ownersAuxValue = level->getAuxValueForMap(
|
||||
player->getXuid(), data->dimension, data->x, data->z, data->scale);
|
||||
if (ownersAuxValue != itemInstance->getAuxValue()) {
|
||||
std::shared_ptr<MapItemSavedData> ownersData =
|
||||
getSavedData(ownersAuxValue, level);
|
||||
|
||||
ownersData->x = data->x;
|
||||
ownersData->z = data->z;
|
||||
ownersData->scale = data->scale;
|
||||
ownersData->dimension = data->dimension;
|
||||
ownersData->x = data->x;
|
||||
ownersData->z = data->z;
|
||||
ownersData->scale = data->scale;
|
||||
ownersData->dimension = data->dimension;
|
||||
|
||||
itemInstance->setAuxValue( ownersAuxValue );
|
||||
ownersData->tickCarriedBy(player, itemInstance );
|
||||
ownersData->mergeInMapData(data);
|
||||
player->inventoryMenu->broadcastChanges();
|
||||
|
||||
data = ownersData;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->tickCarriedBy(player, itemInstance);
|
||||
}
|
||||
}
|
||||
itemInstance->setAuxValue(ownersAuxValue);
|
||||
ownersData->tickCarriedBy(player, itemInstance);
|
||||
ownersData->mergeInMapData(data);
|
||||
player->inventoryMenu->broadcastChanges();
|
||||
|
||||
if (selected)
|
||||
{
|
||||
update(level, owner, data);
|
||||
}
|
||||
data = ownersData;
|
||||
} else {
|
||||
data->tickCarriedBy(player, itemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
if (selected) {
|
||||
update(level, owner, data);
|
||||
}
|
||||
}
|
||||
|
||||
void MapItem::onCraftedBy(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
wchar_t buf[64];
|
||||
void MapItem::onCraftedBy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Player> player) {
|
||||
wchar_t buf[64];
|
||||
|
||||
int mapScale = 3;
|
||||
int mapScale = 3;
|
||||
#ifdef _LARGE_WORLDS
|
||||
int scale = MapItemSavedData::MAP_SIZE * 2 * (1 << mapScale);
|
||||
int centreXC = (int) (Math::round(player->x / scale) * scale);
|
||||
int centreZC = (int) (Math::round(player->z / scale) * scale);
|
||||
int scale = MapItemSavedData::MAP_SIZE * 2 * (1 << mapScale);
|
||||
int centreXC = (int)(Math::round(player->x / scale) * scale);
|
||||
int centreZC = (int)(Math::round(player->z / scale) * scale);
|
||||
#else
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map
|
||||
int centreXC = 0;
|
||||
int centreZC = 0;
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world,
|
||||
// since we can fit the whole world in our map
|
||||
int centreXC = 0;
|
||||
int centreZC = 0;
|
||||
#endif
|
||||
|
||||
itemInstance->setAuxValue(level->getAuxValueForMap(player->getXuid(), player->dimension, centreXC, centreZC, mapScale));
|
||||
|
||||
swprintf(buf,64,L"map_%d", itemInstance->getAuxValue());
|
||||
std::wstring id = std::wstring(buf);
|
||||
itemInstance->setAuxValue(level->getAuxValueForMap(
|
||||
player->getXuid(), player->dimension, centreXC, centreZC, mapScale));
|
||||
|
||||
std::shared_ptr<MapItemSavedData> data = getSavedData(itemInstance->getAuxValue(), level);
|
||||
// 4J Stu - We only have one map per player per dimension, so don't reset the one that they have
|
||||
// when a new one is created
|
||||
if( data == NULL )
|
||||
{
|
||||
data = std::shared_ptr<MapItemSavedData>( new MapItemSavedData(id) );
|
||||
}
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData> ) data);
|
||||
|
||||
data->scale = mapScale;
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map
|
||||
data->x = centreXC;
|
||||
data->z = centreZC;
|
||||
data->dimension = (uint8_t) level->dimension->id;
|
||||
data->setDirty();
|
||||
swprintf(buf, 64, L"map_%d", itemInstance->getAuxValue());
|
||||
std::wstring id = std::wstring(buf);
|
||||
|
||||
std::shared_ptr<MapItemSavedData> data =
|
||||
getSavedData(itemInstance->getAuxValue(), level);
|
||||
// 4J Stu - We only have one map per player per dimension, so don't reset
|
||||
// the one that they have when a new one is created
|
||||
if (data == NULL) {
|
||||
data = std::shared_ptr<MapItemSavedData>(new MapItemSavedData(id));
|
||||
}
|
||||
level->setSavedData(id, (std::shared_ptr<SavedData>)data);
|
||||
|
||||
data->scale = mapScale;
|
||||
// 4J-PB - for Xbox maps, we'll centre them on the origin of the world,
|
||||
// since we can fit the whole world in our map
|
||||
data->x = centreXC;
|
||||
data->z = centreZC;
|
||||
data->dimension = (uint8_t)level->dimension->id;
|
||||
data->setDirty();
|
||||
}
|
||||
|
||||
std::shared_ptr<Packet> MapItem::getUpdatePacket(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
charArray data = MapItem::getSavedData(itemInstance, level)->getUpdatePacket(itemInstance, level, player);
|
||||
std::shared_ptr<Packet> MapItem::getUpdatePacket(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
charArray data = MapItem::getSavedData(itemInstance, level)
|
||||
->getUpdatePacket(itemInstance, level, player);
|
||||
|
||||
if (data.data == NULL || data.length == 0) return nullptr;
|
||||
if (data.data == NULL || data.length == 0) return nullptr;
|
||||
|
||||
std::shared_ptr<Packet> retval = std::shared_ptr<Packet>(new ComplexItemDataPacket((short) Item::map->id, (short) itemInstance->getAuxValue(), data));
|
||||
delete[] data.data; //4jcraft, changed to []
|
||||
return retval;
|
||||
std::shared_ptr<Packet> retval =
|
||||
std::shared_ptr<Packet>(new ComplexItemDataPacket(
|
||||
(short)Item::map->id, (short)itemInstance->getAuxValue(), data));
|
||||
delete[] data.data; // 4jcraft, changed to []
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "ComplexItem.h"
|
||||
|
||||
class MapItemSavedData;
|
||||
|
||||
class MapItem : public ComplexItem
|
||||
{
|
||||
class MapItem : public ComplexItem {
|
||||
public:
|
||||
static const int IMAGE_WIDTH = 128;
|
||||
static const int IMAGE_HEIGHT = 128;
|
||||
static const int IMAGE_WIDTH = 128;
|
||||
static const int IMAGE_HEIGHT = 128;
|
||||
|
||||
public: // 4J Stu - Was protected in Java, but then we can't access it where we need it
|
||||
MapItem(int id);
|
||||
public: // 4J Stu - Was protected in Java, but then we can't access it where we
|
||||
// need it
|
||||
MapItem(int id);
|
||||
|
||||
static std::shared_ptr<MapItemSavedData> getSavedData(short idNum, Level *level);
|
||||
std::shared_ptr<MapItemSavedData> getSavedData(std::shared_ptr<ItemInstance> itemInstance, Level *level);
|
||||
void update(Level *level, std::shared_ptr<Entity> player, std::shared_ptr<MapItemSavedData> data);
|
||||
virtual void inventoryTick(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Entity> owner, int slot, bool selected);
|
||||
virtual void onCraftedBy(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<Packet> getUpdatePacket(std::shared_ptr<ItemInstance> itemInstance, Level *level, std::shared_ptr<Player> player);
|
||||
static std::shared_ptr<MapItemSavedData> getSavedData(short idNum,
|
||||
Level* level);
|
||||
std::shared_ptr<MapItemSavedData> getSavedData(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level);
|
||||
void update(Level* level, std::shared_ptr<Entity> player,
|
||||
std::shared_ptr<MapItemSavedData> data);
|
||||
virtual void inventoryTick(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Entity> owner,
|
||||
int slot, bool selected);
|
||||
virtual void onCraftedBy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, std::shared_ptr<Player> player);
|
||||
std::shared_ptr<Packet> getUpdatePacket(
|
||||
std::shared_ptr<ItemInstance> itemInstance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
|
||||
@@ -3,39 +3,36 @@
|
||||
#include "../Headers/net.minecraft.world.entity.player.h"
|
||||
#include "MilkBucketItem.h"
|
||||
|
||||
MilkBucketItem::MilkBucketItem(int id) : Item( id )
|
||||
{
|
||||
setMaxStackSize(1);
|
||||
MilkBucketItem::MilkBucketItem(int id) : Item(id) { setMaxStackSize(1); }
|
||||
|
||||
std::shared_ptr<ItemInstance> MilkBucketItem::useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
|
||||
if (!level->isClientSide) {
|
||||
player->removeAllEffects();
|
||||
}
|
||||
|
||||
if (instance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::bucket_empty));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> MilkBucketItem::useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
player->removeAllEffects();
|
||||
}
|
||||
|
||||
if (instance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_empty) );
|
||||
}
|
||||
return instance;
|
||||
int MilkBucketItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return DRINK_DURATION;
|
||||
}
|
||||
|
||||
int MilkBucketItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return DRINK_DURATION;
|
||||
UseAnim MilkBucketItem::getUseAnimation(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return UseAnim_drink;
|
||||
}
|
||||
|
||||
UseAnim MilkBucketItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return UseAnim_drink;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> MilkBucketItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
return instance;
|
||||
std::shared_ptr<ItemInstance> MilkBucketItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
return instance;
|
||||
}
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class MilkBucketItem : public Item
|
||||
{
|
||||
class MilkBucketItem : public Item {
|
||||
private:
|
||||
static const int DRINK_DURATION = (int) (20 * 1.6);
|
||||
static const int DRINK_DURATION = (int)(20 * 1.6);
|
||||
|
||||
public:
|
||||
MilkBucketItem(int id);
|
||||
MilkBucketItem(int id);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -6,28 +6,27 @@
|
||||
#include "ItemInstance.h"
|
||||
#include "MinecartItem.h"
|
||||
|
||||
MinecartItem::MinecartItem(int id, int type) : Item(id)
|
||||
{
|
||||
this->maxStackSize = 1;
|
||||
this->type = type;
|
||||
MinecartItem::MinecartItem(int id, int type) : Item(id) {
|
||||
this->maxStackSize = 1;
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
bool MinecartItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
int targetType = level->getTile(x, y, z);
|
||||
bool MinecartItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
int targetType = level->getTile(x, y, z);
|
||||
|
||||
if (RailTile::isRail(targetType))
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
level->addEntity(std::shared_ptr<Minecart>( new Minecart(level, x + 0.5f, y + 0.5f, z + 0.5f, type) ) );
|
||||
}
|
||||
instance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (RailTile::isRail(targetType)) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (!level->isClientSide) {
|
||||
level->addEntity(std::shared_ptr<Minecart>(
|
||||
new Minecart(level, x + 0.5f, y + 0.5f, z + 0.5f, type)));
|
||||
}
|
||||
instance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class MinecartItem : public Item
|
||||
{
|
||||
class MinecartItem : public Item {
|
||||
public:
|
||||
int type;
|
||||
int type;
|
||||
|
||||
MinecartItem(int id, int type);
|
||||
MinecartItem(int id, int type);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
@@ -10,282 +10,253 @@
|
||||
#include "MonsterPlacerItem.h"
|
||||
#include "../Util/Difficulty.h"
|
||||
|
||||
|
||||
MonsterPlacerItem::MonsterPlacerItem(int id) : Item(id)
|
||||
{
|
||||
setMaxStackSize(16); // 4J-PB brought forward. It is 64 on PC, but we'll never be able to place that many
|
||||
setStackedByData(true);
|
||||
overlay = NULL;
|
||||
MonsterPlacerItem::MonsterPlacerItem(int id) : Item(id) {
|
||||
setMaxStackSize(16); // 4J-PB brought forward. It is 64 on PC, but we'll
|
||||
// never be able to place that many
|
||||
setStackedByData(true);
|
||||
overlay = NULL;
|
||||
}
|
||||
|
||||
std::wstring MonsterPlacerItem::getHoverName(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
std::wstring elementName = getDescription();
|
||||
std::wstring MonsterPlacerItem::getHoverName(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
std::wstring elementName = getDescription();
|
||||
|
||||
int nameId = EntityIO::getNameId(itemInstance->getAuxValue());
|
||||
if (nameId >= 0)
|
||||
{
|
||||
elementName = replaceAll(elementName,L"{*CREATURE*}",app.GetString(nameId));
|
||||
//elementName += " " + I18n.get("entity." + encodeId + ".name");
|
||||
}
|
||||
else
|
||||
{
|
||||
elementName = replaceAll(elementName,L"{*CREATURE*}",L"");
|
||||
}
|
||||
int nameId = EntityIO::getNameId(itemInstance->getAuxValue());
|
||||
if (nameId >= 0) {
|
||||
elementName =
|
||||
replaceAll(elementName, L"{*CREATURE*}", app.GetString(nameId));
|
||||
// elementName += " " + I18n.get("entity." + encodeId + ".name");
|
||||
} else {
|
||||
elementName = replaceAll(elementName, L"{*CREATURE*}", L"");
|
||||
}
|
||||
|
||||
return elementName;
|
||||
return elementName;
|
||||
}
|
||||
|
||||
int MonsterPlacerItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer)
|
||||
{
|
||||
AUTO_VAR(it, EntityIO::idsSpawnableInCreative.find(item->getAuxValue()));
|
||||
if (it != EntityIO::idsSpawnableInCreative.end())
|
||||
{
|
||||
EntityIO::SpawnableMobInfo *spawnableMobInfo = it->second;
|
||||
if (spriteLayer == 0) {
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor( spawnableMobInfo->eggColor1 );
|
||||
}
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor( spawnableMobInfo->eggColor2 );
|
||||
}
|
||||
return 0xffffff;
|
||||
int MonsterPlacerItem::getColor(std::shared_ptr<ItemInstance> item,
|
||||
int spriteLayer) {
|
||||
AUTO_VAR(it, EntityIO::idsSpawnableInCreative.find(item->getAuxValue()));
|
||||
if (it != EntityIO::idsSpawnableInCreative.end()) {
|
||||
EntityIO::SpawnableMobInfo* spawnableMobInfo = it->second;
|
||||
if (spriteLayer == 0) {
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor(
|
||||
spawnableMobInfo->eggColor1);
|
||||
}
|
||||
return Minecraft::GetInstance()->getColourTable()->getColor(
|
||||
spawnableMobInfo->eggColor2);
|
||||
}
|
||||
return 0xffffff;
|
||||
}
|
||||
|
||||
bool MonsterPlacerItem::hasMultipleSpriteLayers()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool MonsterPlacerItem::hasMultipleSpriteLayers() { return true; }
|
||||
|
||||
Icon *MonsterPlacerItem::getLayerIcon(int auxValue, int spriteLayer)
|
||||
{
|
||||
if (spriteLayer > 0)
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
Icon* MonsterPlacerItem::getLayerIcon(int auxValue, int spriteLayer) {
|
||||
if (spriteLayer > 0) {
|
||||
return overlay;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
}
|
||||
|
||||
// 4J-PB - added for dispenser
|
||||
std::shared_ptr<Entity> MonsterPlacerItem::canSpawn(int iAuxVal, Level *level, int *piResult)
|
||||
{
|
||||
std::shared_ptr<Entity> newEntity = EntityIO::newById(iAuxVal, level);
|
||||
if (newEntity != NULL)
|
||||
{
|
||||
bool canSpawn = false;
|
||||
std::shared_ptr<Entity> MonsterPlacerItem::canSpawn(int iAuxVal, Level* level,
|
||||
int* piResult) {
|
||||
std::shared_ptr<Entity> newEntity = EntityIO::newById(iAuxVal, level);
|
||||
if (newEntity != NULL) {
|
||||
bool canSpawn = false;
|
||||
|
||||
switch(newEntity->GetType())
|
||||
{
|
||||
case eTYPE_CHICKEN:
|
||||
if(level->canCreateMore( eTYPE_CHICKEN, Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManyChickens;
|
||||
}
|
||||
break;
|
||||
case eTYPE_WOLF:
|
||||
if(level->canCreateMore( eTYPE_WOLF, Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManyWolves;
|
||||
}
|
||||
break;
|
||||
case eTYPE_VILLAGER:
|
||||
if(level->canCreateMore( eTYPE_VILLAGER, Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManyVillagers;
|
||||
}
|
||||
break;
|
||||
case eTYPE_MUSHROOMCOW:
|
||||
if(level->canCreateMore(eTYPE_MUSHROOMCOW, Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManyMooshrooms;
|
||||
}
|
||||
break;
|
||||
case eTYPE_SQUID:
|
||||
if(level->canCreateMore( eTYPE_SQUID, Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManySquid;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if( (newEntity->GetType() & eTYPE_ANIMALS_SPAWN_LIMIT_CHECK) == eTYPE_ANIMALS_SPAWN_LIMIT_CHECK)
|
||||
{
|
||||
if( level->canCreateMore( newEntity->GetType(), Level::eSpawnType_Egg ) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// different message for each animal
|
||||
switch (newEntity->GetType()) {
|
||||
case eTYPE_CHICKEN:
|
||||
if (level->canCreateMore(eTYPE_CHICKEN,
|
||||
Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManyChickens;
|
||||
}
|
||||
break;
|
||||
case eTYPE_WOLF:
|
||||
if (level->canCreateMore(eTYPE_WOLF, Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManyWolves;
|
||||
}
|
||||
break;
|
||||
case eTYPE_VILLAGER:
|
||||
if (level->canCreateMore(eTYPE_VILLAGER,
|
||||
Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManyVillagers;
|
||||
}
|
||||
break;
|
||||
case eTYPE_MUSHROOMCOW:
|
||||
if (level->canCreateMore(eTYPE_MUSHROOMCOW,
|
||||
Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManyMooshrooms;
|
||||
}
|
||||
break;
|
||||
case eTYPE_SQUID:
|
||||
if (level->canCreateMore(eTYPE_SQUID, Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManySquid;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((newEntity->GetType() & eTYPE_ANIMALS_SPAWN_LIMIT_CHECK) ==
|
||||
eTYPE_ANIMALS_SPAWN_LIMIT_CHECK) {
|
||||
if (level->canCreateMore(newEntity->GetType(),
|
||||
Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
// different message for each animal
|
||||
|
||||
*piResult=eSpawnResult_FailTooManyPigsCowsSheepCats;
|
||||
}
|
||||
}
|
||||
else if( (newEntity->GetType() & eTYPE_MONSTER) == eTYPE_MONSTER)
|
||||
{
|
||||
// 4J-PB - check if the player is trying to spawn an enemy in peaceful mode
|
||||
if(level->difficulty==Difficulty::PEACEFUL)
|
||||
{
|
||||
*piResult=eSpawnResult_FailCantSpawnInPeaceful;
|
||||
}
|
||||
else if(level->canCreateMore( newEntity->GetType(), Level::eSpawnType_Egg) )
|
||||
{
|
||||
canSpawn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*piResult=eSpawnResult_FailTooManyMonsters;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
*piResult = eSpawnResult_FailTooManyPigsCowsSheepCats;
|
||||
}
|
||||
} else if ((newEntity->GetType() & eTYPE_MONSTER) ==
|
||||
eTYPE_MONSTER) {
|
||||
// 4J-PB - check if the player is trying to spawn an enemy
|
||||
// in peaceful mode
|
||||
if (level->difficulty == Difficulty::PEACEFUL) {
|
||||
*piResult = eSpawnResult_FailCantSpawnInPeaceful;
|
||||
} else if (level->canCreateMore(newEntity->GetType(),
|
||||
Level::eSpawnType_Egg)) {
|
||||
canSpawn = true;
|
||||
} else {
|
||||
*piResult = eSpawnResult_FailTooManyMonsters;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(canSpawn)
|
||||
{
|
||||
return newEntity;
|
||||
}
|
||||
}
|
||||
if (canSpawn) {
|
||||
return newEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MonsterPlacerItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (level->isClientSide)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool MonsterPlacerItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level,
|
||||
int x, int y, int z, int face, float clickX,
|
||||
float clickY, float clickZ, bool bTestUseOnOnly) {
|
||||
if (level->isClientSide) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int tile = level->getTile(x, y, z);
|
||||
int tile = level->getTile(x, y, z);
|
||||
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
if(app.DebugSettingsOn() && tile == Tile::mobSpawner_Id)
|
||||
{
|
||||
// 4J Stu - Force adding this as a tile update
|
||||
level->setTile(x,y,z,0);
|
||||
level->setTile(x,y,z,Tile::mobSpawner_Id);
|
||||
std::shared_ptr<MobSpawnerTileEntity> mste = std::dynamic_pointer_cast<MobSpawnerTileEntity>( level->getTileEntity(x,y,z) );
|
||||
if(mste != NULL)
|
||||
{
|
||||
mste->setEntityId( EntityIO::getEncodeId(itemInstance->getAuxValue()) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (app.DebugSettingsOn() && tile == Tile::mobSpawner_Id) {
|
||||
// 4J Stu - Force adding this as a tile update
|
||||
level->setTile(x, y, z, 0);
|
||||
level->setTile(x, y, z, Tile::mobSpawner_Id);
|
||||
std::shared_ptr<MobSpawnerTileEntity> mste =
|
||||
std::dynamic_pointer_cast<MobSpawnerTileEntity>(
|
||||
level->getTileEntity(x, y, z));
|
||||
if (mste != NULL) {
|
||||
mste->setEntityId(
|
||||
EntityIO::getEncodeId(itemInstance->getAuxValue()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
x += Facing::STEP_X[face];
|
||||
y += Facing::STEP_Y[face];
|
||||
z += Facing::STEP_Z[face];
|
||||
|
||||
double yOff = 0;
|
||||
// 4J-PB - missing parentheses added
|
||||
if (face == Facing::UP && (tile == Tile::fence_Id || tile == Tile::netherFence_Id))
|
||||
{
|
||||
// special case
|
||||
yOff = .5;
|
||||
}
|
||||
x += Facing::STEP_X[face];
|
||||
y += Facing::STEP_Y[face];
|
||||
z += Facing::STEP_Z[face];
|
||||
|
||||
int iResult=0;
|
||||
bool spawned = spawnMobAt(level, itemInstance->getAuxValue(), x + .5, y + yOff, z + .5, &iResult) != NULL;
|
||||
double yOff = 0;
|
||||
// 4J-PB - missing parentheses added
|
||||
if (face == Facing::UP &&
|
||||
(tile == Tile::fence_Id || tile == Tile::netherFence_Id)) {
|
||||
// special case
|
||||
yOff = .5;
|
||||
}
|
||||
|
||||
if(bTestUseOnOnly)
|
||||
{
|
||||
return spawned;
|
||||
}
|
||||
int iResult = 0;
|
||||
bool spawned = spawnMobAt(level, itemInstance->getAuxValue(), x + .5,
|
||||
y + yOff, z + .5, &iResult) != NULL;
|
||||
|
||||
if (spawned)
|
||||
{
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
itemInstance->count--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// some negative sound effect?
|
||||
//level->levelEvent(LevelEvent::SOUND_CLICK_FAIL, x, y, z, 0);
|
||||
switch(iResult)
|
||||
{
|
||||
case eSpawnResult_FailTooManyPigsCowsSheepCats:
|
||||
player->displayClientMessage(IDS_MAX_PIGS_SHEEP_COWS_CATS_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManyChickens:
|
||||
player->displayClientMessage(IDS_MAX_CHICKENS_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManySquid:
|
||||
player->displayClientMessage(IDS_MAX_SQUID_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManyWolves:
|
||||
player->displayClientMessage(IDS_MAX_WOLVES_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManyMooshrooms:
|
||||
player->displayClientMessage(IDS_MAX_MOOSHROOMS_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManyMonsters:
|
||||
player->displayClientMessage(IDS_MAX_ENEMIES_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailTooManyVillagers:
|
||||
player->displayClientMessage(IDS_MAX_VILLAGERS_SPAWNED );
|
||||
break;
|
||||
case eSpawnResult_FailCantSpawnInPeaceful:
|
||||
player->displayClientMessage(IDS_CANT_SPAWN_IN_PEACEFUL );
|
||||
break;
|
||||
if (bTestUseOnOnly) {
|
||||
return spawned;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (spawned) {
|
||||
if (!player->abilities.instabuild) {
|
||||
itemInstance->count--;
|
||||
}
|
||||
} else {
|
||||
// some negative sound effect?
|
||||
// level->levelEvent(LevelEvent::SOUND_CLICK_FAIL, x, y, z, 0);
|
||||
switch (iResult) {
|
||||
case eSpawnResult_FailTooManyPigsCowsSheepCats:
|
||||
player->displayClientMessage(
|
||||
IDS_MAX_PIGS_SHEEP_COWS_CATS_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManyChickens:
|
||||
player->displayClientMessage(IDS_MAX_CHICKENS_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManySquid:
|
||||
player->displayClientMessage(IDS_MAX_SQUID_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManyWolves:
|
||||
player->displayClientMessage(IDS_MAX_WOLVES_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManyMooshrooms:
|
||||
player->displayClientMessage(IDS_MAX_MOOSHROOMS_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManyMonsters:
|
||||
player->displayClientMessage(IDS_MAX_ENEMIES_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailTooManyVillagers:
|
||||
player->displayClientMessage(IDS_MAX_VILLAGERS_SPAWNED);
|
||||
break;
|
||||
case eSpawnResult_FailCantSpawnInPeaceful:
|
||||
player->displayClientMessage(IDS_CANT_SPAWN_IN_PEACEFUL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Entity> MonsterPlacerItem::spawnMobAt(Level *level, int mobId, double x, double y, double z, int *piResult)
|
||||
{
|
||||
if (EntityIO::idsSpawnableInCreative.find(mobId) == EntityIO::idsSpawnableInCreative.end())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<Entity> MonsterPlacerItem::spawnMobAt(Level* level, int mobId,
|
||||
double x, double y,
|
||||
double z, int* piResult) {
|
||||
if (EntityIO::idsSpawnableInCreative.find(mobId) ==
|
||||
EntityIO::idsSpawnableInCreative.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Entity> newEntity = nullptr;
|
||||
std::shared_ptr<Entity> newEntity = nullptr;
|
||||
|
||||
for (int i = 0; i < SPAWN_COUNT; i++)
|
||||
{
|
||||
newEntity = canSpawn(mobId, level, piResult);
|
||||
for (int i = 0; i < SPAWN_COUNT; i++) {
|
||||
newEntity = canSpawn(mobId, level, piResult);
|
||||
|
||||
std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(newEntity);
|
||||
if (mob)
|
||||
{
|
||||
newEntity->moveTo(x, y, z, Mth::wrapDegrees(level->random->nextFloat() * 360), 0);
|
||||
newEntity->setDespawnProtected(); // 4J added, default to being protected against despawning (has to be done after initial position is set)
|
||||
mob->yHeadRot = mob->yRot;
|
||||
mob->yBodyRot = mob->yRot;
|
||||
std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(newEntity);
|
||||
if (mob) {
|
||||
newEntity->moveTo(
|
||||
x, y, z, Mth::wrapDegrees(level->random->nextFloat() * 360), 0);
|
||||
newEntity->setDespawnProtected(); // 4J added, default to being
|
||||
// protected against despawning
|
||||
// (has to be done after initial
|
||||
// position is set)
|
||||
mob->yHeadRot = mob->yRot;
|
||||
mob->yBodyRot = mob->yRot;
|
||||
|
||||
mob->finalizeMobSpawn();
|
||||
level->addEntity(newEntity);
|
||||
mob->playAmbientSound();
|
||||
}
|
||||
}
|
||||
mob->finalizeMobSpawn();
|
||||
level->addEntity(newEntity);
|
||||
mob->playAmbientSound();
|
||||
}
|
||||
}
|
||||
|
||||
return newEntity;
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
void MonsterPlacerItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
Item::registerIcons(iconRegister);
|
||||
overlay = iconRegister->registerIcon(L"monsterPlacer_overlay");
|
||||
void MonsterPlacerItem::registerIcons(IconRegister* iconRegister) {
|
||||
Item::registerIcons(iconRegister);
|
||||
overlay = iconRegister->registerIcon(L"monsterPlacer_overlay");
|
||||
}
|
||||
|
||||
@@ -2,41 +2,45 @@
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class MonsterPlacerItem : public Item
|
||||
{
|
||||
class MonsterPlacerItem : public Item {
|
||||
private:
|
||||
static const int SPAWN_COUNT = 1;
|
||||
static const int SPAWN_COUNT = 1;
|
||||
|
||||
Icon *overlay;
|
||||
Icon* overlay;
|
||||
|
||||
public:
|
||||
enum _eSpawnResult {
|
||||
eSpawnResult_OK = 0,
|
||||
eSpawnResult_FailTooManyPigsCowsSheepCats,
|
||||
eSpawnResult_FailTooManyChickens,
|
||||
eSpawnResult_FailTooManySquid,
|
||||
eSpawnResult_FailTooManyWolves,
|
||||
eSpawnResult_FailTooManyMooshrooms,
|
||||
eSpawnResult_FailTooManyAnimals,
|
||||
eSpawnResult_FailTooManyMonsters,
|
||||
eSpawnResult_FailTooManyVillagers,
|
||||
eSpawnResult_FailCantSpawnInPeaceful,
|
||||
};
|
||||
|
||||
enum _eSpawnResult
|
||||
{
|
||||
eSpawnResult_OK=0,
|
||||
eSpawnResult_FailTooManyPigsCowsSheepCats,
|
||||
eSpawnResult_FailTooManyChickens,
|
||||
eSpawnResult_FailTooManySquid,
|
||||
eSpawnResult_FailTooManyWolves,
|
||||
eSpawnResult_FailTooManyMooshrooms,
|
||||
eSpawnResult_FailTooManyAnimals,
|
||||
eSpawnResult_FailTooManyMonsters,
|
||||
eSpawnResult_FailTooManyVillagers,
|
||||
eSpawnResult_FailCantSpawnInPeaceful,
|
||||
};
|
||||
MonsterPlacerItem(int id);
|
||||
|
||||
MonsterPlacerItem(int id);
|
||||
virtual std::wstring getHoverName(
|
||||
std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual bool hasMultipleSpriteLayers();
|
||||
virtual Icon* getLayerIcon(int auxValue, int spriteLayer);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
static std::shared_ptr<Entity> spawnMobAt(
|
||||
Level* level, int mobId, double x, double y, double z,
|
||||
int* piResult); // 4J Added piResult param
|
||||
|
||||
virtual std::wstring getHoverName(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual bool hasMultipleSpriteLayers();
|
||||
virtual Icon *getLayerIcon(int auxValue, int spriteLayer);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
static std::shared_ptr<Entity> spawnMobAt(Level *level, int mobId, double x, double y, double z, int *piResult); // 4J Added piResult param
|
||||
// 4J-PB added for dispenser
|
||||
static std::shared_ptr<Entity> canSpawn(int iAuxVal, Level* level,
|
||||
int* piResult);
|
||||
|
||||
// 4J-PB added for dispenser
|
||||
static std::shared_ptr<Entity> canSpawn(int iAuxVal, Level *level, int *piResult);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -2,60 +2,64 @@
|
||||
#include "../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "PickaxeItem.h"
|
||||
|
||||
TileArray *PickaxeItem::diggables = NULL;
|
||||
TileArray* PickaxeItem::diggables = NULL;
|
||||
|
||||
void PickaxeItem::staticCtor()
|
||||
{
|
||||
PickaxeItem::diggables = new TileArray( PICKAXE_DIGGABLES);
|
||||
diggables->data[0] = Tile::stoneBrick;
|
||||
diggables->data[1] = Tile::stoneSlab;
|
||||
diggables->data[2] = Tile::stoneSlabHalf;
|
||||
diggables->data[3] = Tile::rock;
|
||||
diggables->data[4] = Tile::sandStone;
|
||||
diggables->data[5] = Tile::mossStone;
|
||||
diggables->data[6] = Tile::ironOre;
|
||||
diggables->data[7] = Tile::ironBlock;
|
||||
diggables->data[8] = Tile::coalOre;
|
||||
diggables->data[9] = Tile::goldBlock;
|
||||
diggables->data[10] = Tile::goldOre;
|
||||
diggables->data[11] = Tile::diamondOre;
|
||||
diggables->data[12] = Tile::diamondBlock;
|
||||
diggables->data[13] = Tile::ice;
|
||||
diggables->data[14] = Tile::hellRock;
|
||||
diggables->data[15] = Tile::lapisOre;
|
||||
diggables->data[16] = Tile::lapisBlock;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[17] = Tile::redStoneOre;
|
||||
diggables->data[18] = Tile::redStoneOre_lit;
|
||||
diggables->data[19] = Tile::rail;
|
||||
diggables->data[20] = Tile::detectorRail;
|
||||
diggables->data[21] = Tile::goldenRail;
|
||||
void PickaxeItem::staticCtor() {
|
||||
PickaxeItem::diggables = new TileArray(PICKAXE_DIGGABLES);
|
||||
diggables->data[0] = Tile::stoneBrick;
|
||||
diggables->data[1] = Tile::stoneSlab;
|
||||
diggables->data[2] = Tile::stoneSlabHalf;
|
||||
diggables->data[3] = Tile::rock;
|
||||
diggables->data[4] = Tile::sandStone;
|
||||
diggables->data[5] = Tile::mossStone;
|
||||
diggables->data[6] = Tile::ironOre;
|
||||
diggables->data[7] = Tile::ironBlock;
|
||||
diggables->data[8] = Tile::coalOre;
|
||||
diggables->data[9] = Tile::goldBlock;
|
||||
diggables->data[10] = Tile::goldOre;
|
||||
diggables->data[11] = Tile::diamondOre;
|
||||
diggables->data[12] = Tile::diamondBlock;
|
||||
diggables->data[13] = Tile::ice;
|
||||
diggables->data[14] = Tile::hellRock;
|
||||
diggables->data[15] = Tile::lapisOre;
|
||||
diggables->data[16] = Tile::lapisBlock;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[17] = Tile::redStoneOre;
|
||||
diggables->data[18] = Tile::redStoneOre_lit;
|
||||
diggables->data[19] = Tile::rail;
|
||||
diggables->data[20] = Tile::detectorRail;
|
||||
diggables->data[21] = Tile::goldenRail;
|
||||
}
|
||||
|
||||
PickaxeItem::PickaxeItem(int id, const Tier *tier) : DiggerItem(id, 2, tier, diggables)
|
||||
{
|
||||
}
|
||||
PickaxeItem::PickaxeItem(int id, const Tier* tier)
|
||||
: DiggerItem(id, 2, tier, diggables) {}
|
||||
|
||||
bool PickaxeItem::canDestroySpecial(Tile *tile)
|
||||
{
|
||||
if (tile == Tile::obsidian) return tier->getLevel() == 3;
|
||||
if (tile == Tile::diamondBlock || tile == Tile::diamondOre) return tier->getLevel() >= 2;
|
||||
if (tile == Tile::emeraldBlock || tile == Tile::emeraldOre) return tier->getLevel() >= 2;
|
||||
if (tile == Tile::goldBlock || tile == Tile::goldOre) return tier->getLevel() >= 2;
|
||||
if (tile == Tile::ironBlock || tile == Tile::ironOre) return tier->getLevel() >= 1;
|
||||
if (tile == Tile::lapisBlock || tile == Tile::lapisOre) return tier->getLevel() >= 1;
|
||||
if (tile == Tile::redStoneOre || tile == Tile::redStoneOre_lit) return tier->getLevel() >= 2;
|
||||
if (tile->material == Material::stone) return true;
|
||||
if (tile->material == Material::metal) return true;
|
||||
if (tile->material == Material::heavyMetal) return true;
|
||||
return false;
|
||||
bool PickaxeItem::canDestroySpecial(Tile* tile) {
|
||||
if (tile == Tile::obsidian) return tier->getLevel() == 3;
|
||||
if (tile == Tile::diamondBlock || tile == Tile::diamondOre)
|
||||
return tier->getLevel() >= 2;
|
||||
if (tile == Tile::emeraldBlock || tile == Tile::emeraldOre)
|
||||
return tier->getLevel() >= 2;
|
||||
if (tile == Tile::goldBlock || tile == Tile::goldOre)
|
||||
return tier->getLevel() >= 2;
|
||||
if (tile == Tile::ironBlock || tile == Tile::ironOre)
|
||||
return tier->getLevel() >= 1;
|
||||
if (tile == Tile::lapisBlock || tile == Tile::lapisOre)
|
||||
return tier->getLevel() >= 1;
|
||||
if (tile == Tile::redStoneOre || tile == Tile::redStoneOre_lit)
|
||||
return tier->getLevel() >= 2;
|
||||
if (tile->material == Material::stone) return true;
|
||||
if (tile->material == Material::metal) return true;
|
||||
if (tile->material == Material::heavyMetal) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4J - brought forward from 1.2.3
|
||||
float PickaxeItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile)
|
||||
{
|
||||
if (tile != NULL && (tile->material == Material::metal || tile->material == Material::heavyMetal || tile->material == Material::stone))
|
||||
{
|
||||
float PickaxeItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile) {
|
||||
if (tile != NULL && (tile->material == Material::metal ||
|
||||
tile->material == Material::heavyMetal ||
|
||||
tile->material == Material::stone)) {
|
||||
return speed;
|
||||
}
|
||||
return DiggerItem::getDestroySpeed(itemInstance, tile);
|
||||
|
||||
@@ -4,17 +4,18 @@
|
||||
|
||||
#define PICKAXE_DIGGABLES 22
|
||||
|
||||
class PickaxeItem : public DiggerItem
|
||||
{
|
||||
class PickaxeItem : public DiggerItem {
|
||||
private:
|
||||
static TileArray *diggables;
|
||||
static TileArray* diggables;
|
||||
|
||||
public: //
|
||||
static void staticCtor();
|
||||
public: //
|
||||
static void staticCtor();
|
||||
|
||||
PickaxeItem(int id, const Tier *tier);
|
||||
PickaxeItem(int id, const Tier* tier);
|
||||
|
||||
public:
|
||||
virtual bool canDestroySpecial(Tile *tile);
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile); // 4J - brought forward from 1.2.3
|
||||
virtual bool canDestroySpecial(Tile* tile);
|
||||
virtual float getDestroySpeed(
|
||||
std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile); // 4J - brought forward from 1.2.3
|
||||
};
|
||||
|
||||
@@ -17,356 +17,350 @@ const std::wstring PotionItem::THROWABLE_ICON = L"potion_splash";
|
||||
const std::wstring PotionItem::CONTENTS_ICON = L"potion_contents";
|
||||
|
||||
// 4J Added
|
||||
std::vector<std::pair<int, int> > PotionItem::s_uniquePotionValues;
|
||||
std::vector<std::pair<int, int> > PotionItem::s_uniquePotionValues;
|
||||
|
||||
PotionItem::PotionItem(int id) : Item(id)
|
||||
{
|
||||
setMaxStackSize(1);
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
PotionItem::PotionItem(int id) : Item(id) {
|
||||
setMaxStackSize(1);
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
|
||||
iconThrowable = NULL;
|
||||
iconDrinkable = NULL;
|
||||
iconOverlay = NULL;
|
||||
iconThrowable = NULL;
|
||||
iconDrinkable = NULL;
|
||||
iconOverlay = NULL;
|
||||
}
|
||||
|
||||
std::vector<MobEffectInstance *> *PotionItem::getMobEffects(std::shared_ptr<ItemInstance> potion)
|
||||
{
|
||||
return getMobEffects(potion->getAuxValue());
|
||||
std::vector<MobEffectInstance*>* PotionItem::getMobEffects(
|
||||
std::shared_ptr<ItemInstance> potion) {
|
||||
return getMobEffects(potion->getAuxValue());
|
||||
}
|
||||
|
||||
std::vector<MobEffectInstance *> *PotionItem::getMobEffects(int auxValue)
|
||||
{
|
||||
std::vector<MobEffectInstance *> *effects = NULL;
|
||||
AUTO_VAR(it, cachedMobEffects.find(auxValue));
|
||||
if(it != cachedMobEffects.end()) effects = it->second;
|
||||
if (effects == NULL)
|
||||
{
|
||||
effects = PotionBrewing::getEffects(auxValue, false);
|
||||
if(effects != NULL) cachedMobEffects.insert( std::pair<int, std::vector<MobEffectInstance *> *>(auxValue, effects) );
|
||||
}
|
||||
return effects;
|
||||
std::vector<MobEffectInstance*>* PotionItem::getMobEffects(int auxValue) {
|
||||
std::vector<MobEffectInstance*>* effects = NULL;
|
||||
AUTO_VAR(it, cachedMobEffects.find(auxValue));
|
||||
if (it != cachedMobEffects.end()) effects = it->second;
|
||||
if (effects == NULL) {
|
||||
effects = PotionBrewing::getEffects(auxValue, false);
|
||||
if (effects != NULL)
|
||||
cachedMobEffects.insert(
|
||||
std::pair<int, std::vector<MobEffectInstance*>*>(auxValue,
|
||||
effects));
|
||||
}
|
||||
return effects;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> PotionItem::useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
std::shared_ptr<ItemInstance> PotionItem::useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
std::vector<MobEffectInstance *> *effects = getMobEffects(instance);
|
||||
if (effects != NULL)
|
||||
{
|
||||
//for (MobEffectInstance effect : effects)
|
||||
for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it)
|
||||
{
|
||||
player->addEffect(new MobEffectInstance(*it));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
if (instance->count <= 0)
|
||||
{
|
||||
return std::shared_ptr<ItemInstance>( new ItemInstance(Item::glassBottle) );
|
||||
}
|
||||
else
|
||||
{
|
||||
player->inventory->add( std::shared_ptr<ItemInstance>( new ItemInstance(Item::glassBottle) ) );
|
||||
}
|
||||
}
|
||||
if (!level->isClientSide) {
|
||||
std::vector<MobEffectInstance*>* effects = getMobEffects(instance);
|
||||
if (effects != NULL) {
|
||||
// for (MobEffectInstance effect : effects)
|
||||
for (AUTO_VAR(it, effects->begin()); it != effects->end(); ++it) {
|
||||
player->addEffect(new MobEffectInstance(*it));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!player->abilities.instabuild) {
|
||||
if (instance->count <= 0) {
|
||||
return std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::glassBottle));
|
||||
} else {
|
||||
player->inventory->add(std::shared_ptr<ItemInstance>(
|
||||
new ItemInstance(Item::glassBottle)));
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int PotionItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return DRINK_DURATION;
|
||||
int PotionItem::getUseDuration(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return DRINK_DURATION;
|
||||
}
|
||||
|
||||
UseAnim PotionItem::getUseAnimation(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return UseAnim_drink;
|
||||
UseAnim PotionItem::getUseAnimation(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return UseAnim_drink;
|
||||
}
|
||||
|
||||
bool PotionItem::TestUse(Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
return true;
|
||||
bool PotionItem::TestUse(Level* level, std::shared_ptr<Player> player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> PotionItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (isThrowable(instance->getAuxValue()))
|
||||
{
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) level->addEntity(std::shared_ptr<ThrownPotion>( new ThrownPotion(level, player, instance->getAuxValue()) ));
|
||||
return instance;
|
||||
}
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
return instance;
|
||||
std::shared_ptr<ItemInstance> PotionItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (isThrowable(instance->getAuxValue())) {
|
||||
if (!player->abilities.instabuild) instance->count--;
|
||||
level->playSound(player, eSoundType_RANDOM_BOW, 0.5f,
|
||||
0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
level->addEntity(std::shared_ptr<ThrownPotion>(
|
||||
new ThrownPotion(level, player, instance->getAuxValue())));
|
||||
return instance;
|
||||
}
|
||||
player->startUsingItem(instance, getUseDuration(instance));
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool PotionItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
return false;
|
||||
bool PotionItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Icon *PotionItem::getIcon(int auxValue)
|
||||
{
|
||||
if (isThrowable(auxValue))
|
||||
{
|
||||
return iconThrowable;
|
||||
}
|
||||
return iconDrinkable;
|
||||
Icon* PotionItem::getIcon(int auxValue) {
|
||||
if (isThrowable(auxValue)) {
|
||||
return iconThrowable;
|
||||
}
|
||||
return iconDrinkable;
|
||||
}
|
||||
|
||||
Icon *PotionItem::getLayerIcon(int auxValue, int spriteLayer)
|
||||
{
|
||||
if (spriteLayer == 0)
|
||||
{
|
||||
return iconOverlay;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
Icon* PotionItem::getLayerIcon(int auxValue, int spriteLayer) {
|
||||
if (spriteLayer == 0) {
|
||||
return iconOverlay;
|
||||
}
|
||||
return Item::getLayerIcon(auxValue, spriteLayer);
|
||||
}
|
||||
|
||||
bool PotionItem::isThrowable(int auxValue)
|
||||
{
|
||||
return ((auxValue & PotionBrewing::THROWABLE_MASK) != 0);
|
||||
bool PotionItem::isThrowable(int auxValue) {
|
||||
return ((auxValue & PotionBrewing::THROWABLE_MASK) != 0);
|
||||
}
|
||||
|
||||
int PotionItem::getColor(int data)
|
||||
{
|
||||
return PotionBrewing::getColorValue(data, false);
|
||||
int PotionItem::getColor(int data) {
|
||||
return PotionBrewing::getColorValue(data, false);
|
||||
}
|
||||
|
||||
int PotionItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer)
|
||||
{
|
||||
if (spriteLayer > 0)
|
||||
{
|
||||
return 0xffffff;
|
||||
}
|
||||
return PotionBrewing::getColorValue(item->getAuxValue(), false);
|
||||
int PotionItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer) {
|
||||
if (spriteLayer > 0) {
|
||||
return 0xffffff;
|
||||
}
|
||||
return PotionBrewing::getColorValue(item->getAuxValue(), false);
|
||||
}
|
||||
|
||||
bool PotionItem::hasMultipleSpriteLayers()
|
||||
{
|
||||
return true;
|
||||
bool PotionItem::hasMultipleSpriteLayers() { return true; }
|
||||
|
||||
bool PotionItem::hasInstantenousEffects(int itemAuxValue) {
|
||||
std::vector<MobEffectInstance*>* mobEffects = getMobEffects(itemAuxValue);
|
||||
if (mobEffects == NULL || mobEffects->empty()) {
|
||||
return false;
|
||||
}
|
||||
// for (MobEffectInstance effect : mobEffects) {
|
||||
for (AUTO_VAR(it, mobEffects->begin()); it != mobEffects->end(); ++it) {
|
||||
MobEffectInstance* effect = *it;
|
||||
if (MobEffect::effects[effect->getId()]->isInstantenous()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PotionItem::hasInstantenousEffects(int itemAuxValue)
|
||||
{
|
||||
std::vector<MobEffectInstance *> *mobEffects = getMobEffects(itemAuxValue);
|
||||
if (mobEffects == NULL || mobEffects->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//for (MobEffectInstance effect : mobEffects) {
|
||||
for(AUTO_VAR(it, mobEffects->begin()); it != mobEffects->end(); ++it)
|
||||
{
|
||||
MobEffectInstance *effect = *it;
|
||||
if (MobEffect::effects[effect->getId()]->isInstantenous())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
std::wstring PotionItem::getHoverName(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
if (itemInstance->getAuxValue() == 0) {
|
||||
return app.GetString(
|
||||
IDS_ITEM_WATER_BOTTLE); // I18n.get("item.emptyPotion.name").trim();
|
||||
}
|
||||
|
||||
std::wstring elementName = Item::getHoverName(itemInstance);
|
||||
if (isThrowable(itemInstance->getAuxValue())) {
|
||||
// elementName = I18n.get("potion.prefix.grenade").trim() + " " +
|
||||
// elementName;
|
||||
elementName = replaceAll(elementName, L"{*splash*}",
|
||||
app.GetString(IDS_POTION_PREFIX_GRENADE));
|
||||
} else {
|
||||
elementName = replaceAll(elementName, L"{*splash*}", L"");
|
||||
}
|
||||
|
||||
std::vector<MobEffectInstance*>* effects =
|
||||
((PotionItem*)Item::potion)->getMobEffects(itemInstance);
|
||||
if (effects != NULL && !effects->empty()) {
|
||||
// String postfixString = effects.get(0).getDescriptionId();
|
||||
// postfixString += ".postfix";
|
||||
// return elementName + " " + I18n.get(postfixString).trim();
|
||||
|
||||
elementName = replaceAll(elementName, L"{*prefix*}", L"");
|
||||
elementName = replaceAll(
|
||||
elementName, L"{*postfix*}",
|
||||
app.GetString(effects->at(0)->getPostfixDescriptionId()));
|
||||
} else {
|
||||
// String appearanceName =
|
||||
// PotionBrewing.getAppearanceName(itemInstance.getAuxValue()); return
|
||||
// I18n.get(appearanceName).trim() + " " + elementName;
|
||||
|
||||
elementName = replaceAll(elementName, L"{*prefix*}",
|
||||
app.GetString(PotionBrewing::getAppearanceName(
|
||||
itemInstance->getAuxValue())));
|
||||
elementName = replaceAll(elementName, L"{*postfix*}", L"");
|
||||
}
|
||||
return elementName;
|
||||
}
|
||||
|
||||
std::wstring PotionItem::getHoverName(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
if (itemInstance->getAuxValue() == 0)
|
||||
{
|
||||
return app.GetString(IDS_ITEM_WATER_BOTTLE); // I18n.get("item.emptyPotion.name").trim();
|
||||
}
|
||||
|
||||
std::wstring elementName = Item::getHoverName(itemInstance);
|
||||
if (isThrowable(itemInstance->getAuxValue()))
|
||||
{
|
||||
//elementName = I18n.get("potion.prefix.grenade").trim() + " " + elementName;
|
||||
elementName = replaceAll(elementName,L"{*splash*}",app.GetString(IDS_POTION_PREFIX_GRENADE));
|
||||
}
|
||||
else
|
||||
{
|
||||
elementName = replaceAll(elementName,L"{*splash*}",L"");
|
||||
}
|
||||
|
||||
std::vector<MobEffectInstance *> *effects = ((PotionItem *) Item::potion)->getMobEffects(itemInstance);
|
||||
if (effects != NULL && !effects->empty())
|
||||
{
|
||||
//String postfixString = effects.get(0).getDescriptionId();
|
||||
//postfixString += ".postfix";
|
||||
//return elementName + " " + I18n.get(postfixString).trim();
|
||||
|
||||
elementName = replaceAll(elementName,L"{*prefix*}",L"");
|
||||
elementName = replaceAll(elementName,L"{*postfix*}",app.GetString(effects->at(0)->getPostfixDescriptionId()));
|
||||
}
|
||||
else
|
||||
{
|
||||
//String appearanceName = PotionBrewing.getAppearanceName(itemInstance.getAuxValue());
|
||||
//return I18n.get(appearanceName).trim() + " " + elementName;
|
||||
|
||||
elementName = replaceAll(elementName,L"{*prefix*}",app.GetString( PotionBrewing::getAppearanceName(itemInstance->getAuxValue())));
|
||||
elementName = replaceAll(elementName,L"{*postfix*}",L"");
|
||||
}
|
||||
return elementName;
|
||||
void PotionItem::appendHoverText(
|
||||
std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings) {
|
||||
if (itemInstance->getAuxValue() == 0) {
|
||||
return;
|
||||
}
|
||||
std::vector<MobEffectInstance*>* effects =
|
||||
((PotionItem*)Item::potion)->getMobEffects(itemInstance);
|
||||
if (effects != NULL && !effects->empty()) {
|
||||
// for (MobEffectInstance effect : effects)
|
||||
for (AUTO_VAR(it, effects->begin()); it != effects->end(); ++it) {
|
||||
MobEffectInstance* effect = *it;
|
||||
std::wstring effectString = app.GetString(
|
||||
effect
|
||||
->getDescriptionId()); // I18n.get(effect.getDescriptionId()).trim();
|
||||
if (effect->getAmplifier() > 0) {
|
||||
std::wstring potencyString = L"";
|
||||
switch (effect->getAmplifier()) {
|
||||
case 1:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString(IDS_POTION_POTENCY_1);
|
||||
break;
|
||||
case 2:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString(IDS_POTION_POTENCY_2);
|
||||
break;
|
||||
case 3:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString(IDS_POTION_POTENCY_3);
|
||||
break;
|
||||
default:
|
||||
potencyString = app.GetString(IDS_POTION_POTENCY_0);
|
||||
break;
|
||||
}
|
||||
effectString +=
|
||||
potencyString; // + I18n.get("potion.potency." +
|
||||
// effect.getAmplifier()).trim();
|
||||
}
|
||||
if (effect->getDuration() > SharedConstants::TICKS_PER_SECOND) {
|
||||
effectString +=
|
||||
L" (" + MobEffect::formatDuration(effect) + L")";
|
||||
}
|
||||
unformattedStrings.push_back(effectString);
|
||||
wchar_t formatted[256];
|
||||
ZeroMemory(formatted, 256 * sizeof(wchar_t));
|
||||
eMinecraftColour colour = eMinecraftColour_NOT_SET;
|
||||
if (MobEffect::effects[effect->getId()]->isHarmful()) {
|
||||
colour = eHTMLColor_c;
|
||||
// lines->push_back(L"�c + effectString); //"�c"
|
||||
} else {
|
||||
colour = eHTMLColor_7;
|
||||
// lines->push_back(L"�7" + effectString); //"�7"
|
||||
}
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>",
|
||||
app.GetHTMLColour(colour), effectString.c_str());
|
||||
lines->push_back(formatted);
|
||||
}
|
||||
} else {
|
||||
std::wstring effectString = app.GetString(
|
||||
IDS_POTION_EMPTY); // I18n.get("potion.empty").trim();
|
||||
// eHTMLColor_7
|
||||
wchar_t formatted[256];
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>",
|
||||
app.GetHTMLColour(eHTMLColor_7), effectString.c_str());
|
||||
lines->push_back(formatted); //"�7"
|
||||
}
|
||||
}
|
||||
|
||||
void PotionItem::appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings)
|
||||
{
|
||||
if (itemInstance->getAuxValue() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::vector<MobEffectInstance *> *effects = ((PotionItem *) Item::potion)->getMobEffects(itemInstance);
|
||||
if (effects != NULL && !effects->empty())
|
||||
{
|
||||
//for (MobEffectInstance effect : effects)
|
||||
for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it)
|
||||
{
|
||||
MobEffectInstance *effect = *it;
|
||||
std::wstring effectString = app.GetString( effect->getDescriptionId() );//I18n.get(effect.getDescriptionId()).trim();
|
||||
if (effect->getAmplifier() > 0)
|
||||
{
|
||||
std::wstring potencyString = L"";
|
||||
switch(effect->getAmplifier())
|
||||
{
|
||||
case 1:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString( IDS_POTION_POTENCY_1 );
|
||||
break;
|
||||
case 2:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString( IDS_POTION_POTENCY_2 );
|
||||
break;
|
||||
case 3:
|
||||
potencyString = L" ";
|
||||
potencyString += app.GetString( IDS_POTION_POTENCY_3 );
|
||||
break;
|
||||
default:
|
||||
potencyString = app.GetString( IDS_POTION_POTENCY_0 );
|
||||
break;
|
||||
}
|
||||
effectString += potencyString;// + I18n.get("potion.potency." + effect.getAmplifier()).trim();
|
||||
}
|
||||
if (effect->getDuration() > SharedConstants::TICKS_PER_SECOND)
|
||||
{
|
||||
effectString += L" (" + MobEffect::formatDuration(effect) + L")";
|
||||
}
|
||||
unformattedStrings.push_back(effectString);
|
||||
wchar_t formatted[256];
|
||||
ZeroMemory(formatted, 256 * sizeof(wchar_t));
|
||||
eMinecraftColour colour = eMinecraftColour_NOT_SET;
|
||||
if (MobEffect::effects[effect->getId()]->isHarmful())
|
||||
{
|
||||
colour = eHTMLColor_c;
|
||||
//lines->push_back(L"�c + effectString); //"�c"
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = eHTMLColor_7;
|
||||
//lines->push_back(L"�7" + effectString); //"�7"
|
||||
}
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>",app.GetHTMLColour(colour),effectString.c_str());
|
||||
lines->push_back(formatted);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring effectString = app.GetString(IDS_POTION_EMPTY); //I18n.get("potion.empty").trim();
|
||||
//eHTMLColor_7
|
||||
wchar_t formatted[256];
|
||||
swprintf(formatted,256,L"<font color=\"#%08x\">%ls</font>",app.GetHTMLColour(eHTMLColor_7),effectString.c_str());
|
||||
lines->push_back(formatted); //"�7"
|
||||
}
|
||||
bool PotionItem::isFoil(std::shared_ptr<ItemInstance> itemInstance) {
|
||||
std::vector<MobEffectInstance*>* mobEffects = getMobEffects(itemInstance);
|
||||
return mobEffects != NULL && !mobEffects->empty();
|
||||
}
|
||||
|
||||
bool PotionItem::isFoil(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
std::vector<MobEffectInstance *> *mobEffects = getMobEffects(itemInstance);
|
||||
return mobEffects != NULL && !mobEffects->empty();
|
||||
unsigned int PotionItem::getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance) {
|
||||
int brew = instance->getAuxValue();
|
||||
|
||||
#define MACRO_POTION_IS_NIGHTVISION(aux) ((aux & 0x200F) == MASK_NIGHTVISION)
|
||||
#define MACRO_POTION_IS_INVISIBILITY(aux) ((aux & 0x200F) == MASK_INVISIBILITY)
|
||||
|
||||
if (brew == 0)
|
||||
return IDS_POTION_DESC_WATER_BOTTLE;
|
||||
else if (MACRO_POTION_IS_REGENERATION(brew))
|
||||
return IDS_POTION_DESC_REGENERATION;
|
||||
else if (MACRO_POTION_IS_SPEED(brew))
|
||||
return IDS_POTION_DESC_MOVESPEED;
|
||||
else if (MACRO_POTION_IS_FIRE_RESISTANCE(brew))
|
||||
return IDS_POTION_DESC_FIRERESISTANCE;
|
||||
else if (MACRO_POTION_IS_INSTANTHEALTH(brew))
|
||||
return IDS_POTION_DESC_HEAL;
|
||||
else if (MACRO_POTION_IS_NIGHTVISION(brew))
|
||||
return IDS_POTION_DESC_NIGHTVISION;
|
||||
else if (MACRO_POTION_IS_INVISIBILITY(brew))
|
||||
return IDS_POTION_DESC_INVISIBILITY;
|
||||
else if (MACRO_POTION_IS_WEAKNESS(brew))
|
||||
return IDS_POTION_DESC_WEAKNESS;
|
||||
else if (MACRO_POTION_IS_STRENGTH(brew))
|
||||
return IDS_POTION_DESC_DAMAGEBOOST;
|
||||
else if (MACRO_POTION_IS_SLOWNESS(brew))
|
||||
return IDS_POTION_DESC_MOVESLOWDOWN;
|
||||
else if (MACRO_POTION_IS_POISON(brew))
|
||||
return IDS_POTION_DESC_POISON;
|
||||
else if (MACRO_POTION_IS_INSTANTDAMAGE(brew))
|
||||
return IDS_POTION_DESC_HARM;
|
||||
return IDS_POTION_DESC_EMPTY;
|
||||
}
|
||||
|
||||
unsigned int PotionItem::getUseDescriptionId(std::shared_ptr<ItemInstance> instance)
|
||||
{
|
||||
int brew = instance->getAuxValue();
|
||||
|
||||
|
||||
#define MACRO_POTION_IS_NIGHTVISION(aux) ((aux & 0x200F) == MASK_NIGHTVISION)
|
||||
#define MACRO_POTION_IS_INVISIBILITY(aux) ((aux & 0x200F) == MASK_INVISIBILITY)
|
||||
|
||||
if(brew == 0) return IDS_POTION_DESC_WATER_BOTTLE;
|
||||
else if( MACRO_POTION_IS_REGENERATION(brew)) return IDS_POTION_DESC_REGENERATION;
|
||||
else if( MACRO_POTION_IS_SPEED(brew) ) return IDS_POTION_DESC_MOVESPEED;
|
||||
else if( MACRO_POTION_IS_FIRE_RESISTANCE(brew)) return IDS_POTION_DESC_FIRERESISTANCE;
|
||||
else if( MACRO_POTION_IS_INSTANTHEALTH(brew)) return IDS_POTION_DESC_HEAL;
|
||||
else if( MACRO_POTION_IS_NIGHTVISION(brew)) return IDS_POTION_DESC_NIGHTVISION;
|
||||
else if( MACRO_POTION_IS_INVISIBILITY(brew)) return IDS_POTION_DESC_INVISIBILITY;
|
||||
else if( MACRO_POTION_IS_WEAKNESS(brew)) return IDS_POTION_DESC_WEAKNESS;
|
||||
else if( MACRO_POTION_IS_STRENGTH(brew)) return IDS_POTION_DESC_DAMAGEBOOST;
|
||||
else if( MACRO_POTION_IS_SLOWNESS(brew)) return IDS_POTION_DESC_MOVESLOWDOWN;
|
||||
else if( MACRO_POTION_IS_POISON(brew)) return IDS_POTION_DESC_POISON;
|
||||
else if( MACRO_POTION_IS_INSTANTDAMAGE(brew)) return IDS_POTION_DESC_HARM;
|
||||
return IDS_POTION_DESC_EMPTY;
|
||||
void PotionItem::registerIcons(IconRegister* iconRegister) {
|
||||
iconDrinkable = iconRegister->registerIcon(DEFAULT_ICON);
|
||||
iconThrowable = iconRegister->registerIcon(THROWABLE_ICON);
|
||||
iconOverlay = iconRegister->registerIcon(CONTENTS_ICON);
|
||||
}
|
||||
|
||||
void PotionItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
iconDrinkable = iconRegister->registerIcon(DEFAULT_ICON);
|
||||
iconThrowable = iconRegister->registerIcon(THROWABLE_ICON);
|
||||
iconOverlay = iconRegister->registerIcon(CONTENTS_ICON);
|
||||
Icon* PotionItem::getTexture(const std::wstring& name) {
|
||||
if (name.compare(DEFAULT_ICON) == 0) return Item::potion->iconDrinkable;
|
||||
if (name.compare(THROWABLE_ICON) == 0) return Item::potion->iconThrowable;
|
||||
if (name.compare(CONTENTS_ICON) == 0) return Item::potion->iconOverlay;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Icon *PotionItem::getTexture(const std::wstring &name)
|
||||
{
|
||||
if (name.compare(DEFAULT_ICON) == 0) return Item::potion->iconDrinkable;
|
||||
if (name.compare(THROWABLE_ICON) == 0) return Item::potion->iconThrowable;
|
||||
if (name.compare(CONTENTS_ICON) == 0) return Item::potion->iconOverlay;
|
||||
return NULL;
|
||||
}
|
||||
// 4J Stu - Based loosely on a function that gets added in java much later on
|
||||
// (1.3)
|
||||
std::vector<std::pair<int, int> >* PotionItem::getUniquePotionValues() {
|
||||
if (s_uniquePotionValues.empty()) {
|
||||
for (int brew = 0; brew <= PotionBrewing::BREW_MASK; ++brew) {
|
||||
std::vector<MobEffectInstance*>* effects =
|
||||
PotionBrewing::getEffects(brew, false);
|
||||
|
||||
if (effects != NULL) {
|
||||
if (!effects->empty()) {
|
||||
// 4J Stu - Based on implementation of Java List.hashCode()
|
||||
// at
|
||||
// http://docs.oracle.com/javase/6/docs/api/java/util/List.html#hashCode()
|
||||
// and adding deleting to clear up as we go
|
||||
int effectsHashCode = 1;
|
||||
for (AUTO_VAR(it, effects->begin()); it != effects->end();
|
||||
++it) {
|
||||
MobEffectInstance* mei = *it;
|
||||
effectsHashCode = 31 * effectsHashCode +
|
||||
(mei == NULL ? 0 : mei->hashCode());
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
// 4J Stu - Based loosely on a function that gets added in java much later on (1.3)
|
||||
std::vector<std::pair<int, int> > *PotionItem::getUniquePotionValues()
|
||||
{
|
||||
if (s_uniquePotionValues.empty())
|
||||
{
|
||||
for (int brew = 0; brew <= PotionBrewing::BREW_MASK; ++brew)
|
||||
{
|
||||
std::vector<MobEffectInstance *> *effects = PotionBrewing::getEffects(brew, false);
|
||||
|
||||
if (effects != NULL)
|
||||
{
|
||||
if(!effects->empty())
|
||||
{
|
||||
// 4J Stu - Based on implementation of Java List.hashCode() at http://docs.oracle.com/javase/6/docs/api/java/util/List.html#hashCode()
|
||||
// and adding deleting to clear up as we go
|
||||
int effectsHashCode = 1;
|
||||
for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it)
|
||||
{
|
||||
MobEffectInstance *mei = *it;
|
||||
effectsHashCode = 31*effectsHashCode + (mei==NULL ? 0 : mei->hashCode());
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
bool toAdd = true;
|
||||
for(AUTO_VAR(it, s_uniquePotionValues.begin()); it != s_uniquePotionValues.end(); ++it)
|
||||
{
|
||||
// Some potions hash the same (identical effects) but are throwable so account for that
|
||||
if(it->first == effectsHashCode && !(!isThrowable(it->second) && isThrowable(brew)) )
|
||||
{
|
||||
toAdd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( toAdd )
|
||||
{
|
||||
s_uniquePotionValues.push_back(std::pair<int,int>(effectsHashCode, brew) );
|
||||
}
|
||||
}
|
||||
delete effects;
|
||||
}
|
||||
}
|
||||
}
|
||||
return &s_uniquePotionValues;
|
||||
bool toAdd = true;
|
||||
for (AUTO_VAR(it, s_uniquePotionValues.begin());
|
||||
it != s_uniquePotionValues.end(); ++it) {
|
||||
// Some potions hash the same (identical effects) but
|
||||
// are throwable so account for that
|
||||
if (it->first == effectsHashCode &&
|
||||
!(!isThrowable(it->second) && isThrowable(brew))) {
|
||||
toAdd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toAdd) {
|
||||
s_uniquePotionValues.push_back(
|
||||
std::pair<int, int>(effectsHashCode, brew));
|
||||
}
|
||||
}
|
||||
delete effects;
|
||||
}
|
||||
}
|
||||
}
|
||||
return &s_uniquePotionValues;
|
||||
}
|
||||
@@ -4,54 +4,70 @@
|
||||
|
||||
class MobEffectInstance;
|
||||
|
||||
class PotionItem : public Item
|
||||
{
|
||||
class PotionItem : public Item {
|
||||
private:
|
||||
static const int DRINK_DURATION = (int) (20 * 1.6);
|
||||
static const int DRINK_DURATION = (int)(20 * 1.6);
|
||||
|
||||
public:
|
||||
static const std::wstring DEFAULT_ICON;
|
||||
static const std::wstring THROWABLE_ICON;
|
||||
static const std::wstring CONTENTS_ICON;
|
||||
static const std::wstring DEFAULT_ICON;
|
||||
static const std::wstring THROWABLE_ICON;
|
||||
static const std::wstring CONTENTS_ICON;
|
||||
|
||||
private:
|
||||
std::unordered_map<int, std::vector<MobEffectInstance *> *> cachedMobEffects;
|
||||
std::unordered_map<int, std::vector<MobEffectInstance*>*> cachedMobEffects;
|
||||
|
||||
Icon *iconThrowable;
|
||||
Icon *iconDrinkable;
|
||||
Icon *iconOverlay;
|
||||
Icon* iconThrowable;
|
||||
Icon* iconDrinkable;
|
||||
Icon* iconOverlay;
|
||||
|
||||
public:
|
||||
PotionItem(int id);
|
||||
PotionItem(int id);
|
||||
|
||||
virtual std::vector<MobEffectInstance *> *getMobEffects(std::shared_ptr<ItemInstance> potion);
|
||||
virtual std::vector<MobEffectInstance *> *getMobEffects(int auxValue);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level *level, std::shared_ptr<Player> player);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual Icon *getIcon(int auxValue);
|
||||
virtual Icon *getLayerIcon(int auxValue, int spriteLayer);
|
||||
static bool isThrowable(int auxValue);
|
||||
int getColor(int data);
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual bool hasMultipleSpriteLayers();
|
||||
virtual bool hasInstantenousEffects(int itemAuxValue);
|
||||
virtual std::wstring getHoverName(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual void appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings);
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::vector<MobEffectInstance*>* getMobEffects(
|
||||
std::shared_ptr<ItemInstance> potion);
|
||||
virtual std::vector<MobEffectInstance*>* getMobEffects(int auxValue);
|
||||
virtual std::shared_ptr<ItemInstance> useTimeDepleted(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual int getUseDuration(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual UseAnim getUseAnimation(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
virtual bool TestUse(Level* level, std::shared_ptr<Player> player);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
virtual Icon* getIcon(int auxValue);
|
||||
virtual Icon* getLayerIcon(int auxValue, int spriteLayer);
|
||||
static bool isThrowable(int auxValue);
|
||||
int getColor(int data);
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual bool hasMultipleSpriteLayers();
|
||||
virtual bool hasInstantenousEffects(int itemAuxValue);
|
||||
virtual std::wstring getHoverName(
|
||||
std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual void appendHoverText(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines,
|
||||
bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings);
|
||||
virtual bool isFoil(std::shared_ptr<ItemInstance> itemInstance);
|
||||
|
||||
virtual unsigned int getUseDescriptionId(std::shared_ptr<ItemInstance> instance);
|
||||
virtual unsigned int getUseDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
static Icon *getTexture(const std::wstring &name);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
static Icon* getTexture(const std::wstring& name);
|
||||
|
||||
// 4J Stu - Based loosely on a function that gets added in java much later
|
||||
// on (1.3)
|
||||
static std::vector<std::pair<int, int> >* getUniquePotionValues();
|
||||
|
||||
// 4J Stu - Based loosely on a function that gets added in java much later on (1.3)
|
||||
static std::vector<std::pair<int, int> > *getUniquePotionValues();
|
||||
private:
|
||||
// 4J Stu - Added to support function above, different from Java implementation
|
||||
static std::vector<std::pair<int, int> > s_uniquePotionValues;
|
||||
// 4J Stu - Added to support function above, different from Java
|
||||
// implementation
|
||||
static std::vector<std::pair<int, int> > s_uniquePotionValues;
|
||||
};
|
||||
@@ -7,58 +7,59 @@
|
||||
#include "RecordingItem.h"
|
||||
#include "../Stats/GenericStats.h"
|
||||
|
||||
RecordingItem::RecordingItem(int id, const std::wstring& recording) : Item(id), recording( recording )
|
||||
{
|
||||
this->maxStackSize = 1;
|
||||
RecordingItem::RecordingItem(int id, const std::wstring& recording)
|
||||
: Item(id), recording(recording) {
|
||||
this->maxStackSize = 1;
|
||||
}
|
||||
|
||||
Icon *RecordingItem::getIcon(int auxValue)
|
||||
{
|
||||
return icon;
|
||||
Icon* RecordingItem::getIcon(int auxValue) { return icon; }
|
||||
|
||||
bool RecordingItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (level->getTile(x, y, z) == Tile::recordPlayer_Id &&
|
||||
level->getData(x, y, z) == 0) {
|
||||
if (!bTestUseOnOnly) {
|
||||
if (level->isClientSide) return true;
|
||||
|
||||
((RecordPlayerTile*)Tile::recordPlayer)
|
||||
->setRecord(level, x, y, z, id);
|
||||
level->levelEvent(nullptr, LevelEvent::SOUND_PLAY_RECORDING, x, y,
|
||||
z, id);
|
||||
itemInstance->count--;
|
||||
|
||||
player->awardStat(GenericStats::musicToMyEars(),
|
||||
GenericStats::param_musicToMyEars(id));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RecordingItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (level->getTile(x, y, z) == Tile::recordPlayer_Id && level->getData(x, y, z) == 0)
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (level->isClientSide) return true;
|
||||
void RecordingItem::appendHoverText(
|
||||
std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines, bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings) {
|
||||
eMinecraftColour rarityColour =
|
||||
getRarity(std::shared_ptr<ItemInstance>())->color;
|
||||
int colour = app.GetHTMLColour(rarityColour);
|
||||
wchar_t formatted[256];
|
||||
|
||||
((RecordPlayerTile *) Tile::recordPlayer)->setRecord(level, x, y, z, id);
|
||||
level->levelEvent(nullptr, LevelEvent::SOUND_PLAY_RECORDING, x, y, z, id);
|
||||
itemInstance->count--;
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>", colour,
|
||||
L"C418 - ", recording.c_str());
|
||||
|
||||
player->awardStat(
|
||||
GenericStats::musicToMyEars(),
|
||||
GenericStats::param_musicToMyEars(id)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
lines->push_back(formatted);
|
||||
|
||||
unformattedStrings.push_back(recording);
|
||||
}
|
||||
|
||||
void RecordingItem::appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings)
|
||||
{
|
||||
eMinecraftColour rarityColour = getRarity(std::shared_ptr<ItemInstance>())->color;
|
||||
int colour = app.GetHTMLColour(rarityColour);
|
||||
wchar_t formatted[256];
|
||||
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>",colour,L"C418 - ", recording.c_str());
|
||||
|
||||
lines->push_back(formatted);
|
||||
|
||||
unformattedStrings.push_back(recording);
|
||||
const Rarity* RecordingItem::getRarity(
|
||||
std::shared_ptr<ItemInstance> itemInstance) {
|
||||
return (Rarity*)Rarity::rare;
|
||||
}
|
||||
|
||||
const Rarity *RecordingItem::getRarity(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
return (Rarity *)Rarity::rare;
|
||||
}
|
||||
|
||||
void RecordingItem::registerIcons(IconRegister *iconRegister)
|
||||
{
|
||||
icon = iconRegister->registerIcon(L"record_" + recording);
|
||||
void RecordingItem::registerIcons(IconRegister* iconRegister) {
|
||||
icon = iconRegister->registerIcon(L"record_" + recording);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class RecordingItem : public Item
|
||||
{
|
||||
class RecordingItem : public Item {
|
||||
public:
|
||||
const std::wstring recording;
|
||||
const std::wstring recording;
|
||||
|
||||
public: // 4J Stu - Was protected in Java, but the can't access it where we need
|
||||
RecordingItem(int id, const std::wstring& recording);
|
||||
public
|
||||
: // 4J Stu - Was protected in Java, but the can't access it where we need
|
||||
RecordingItem(int id, const std::wstring& recording);
|
||||
|
||||
//@Override
|
||||
Icon *getIcon(int auxValue);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
//@Override
|
||||
Icon* getIcon(int auxValue);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
|
||||
virtual void appendHoverText(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, std::vector<std::wstring> *lines, bool advanced, std::vector<std::wstring> &unformattedStrings);
|
||||
virtual const Rarity *getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
virtual void appendHoverText(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player,
|
||||
std::vector<std::wstring>* lines,
|
||||
bool advanced,
|
||||
std::vector<std::wstring>& unformattedStrings);
|
||||
virtual const Rarity* getRarity(std::shared_ptr<ItemInstance> itemInstance);
|
||||
|
||||
//@Override
|
||||
void registerIcons(IconRegister *iconRegister);
|
||||
//@Override
|
||||
void registerIcons(IconRegister* iconRegister);
|
||||
};
|
||||
@@ -6,35 +6,35 @@
|
||||
#include "../Stats/GenericStats.h"
|
||||
#include "RedstoneItem.h"
|
||||
|
||||
RedStoneItem::RedStoneItem(int id) : Item(id)
|
||||
{
|
||||
}
|
||||
|
||||
bool RedStoneItem::useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (level->getTile(x, y, z) != Tile::topSnow_Id)
|
||||
{
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
if (!level->isEmptyTile(x, y, z)) return false;
|
||||
}
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
if (Tile::redStoneDust->mayPlace(level, x, y, z))
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(GenericStats::blocksPlaced(Tile::redStoneDust_Id), GenericStats::param_blocksPlaced(Tile::redStoneDust_Id,itemInstance->getAuxValue(),1));
|
||||
|
||||
itemInstance->count--;
|
||||
level->setTile(x, y, z, Tile::redStoneDust_Id);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
RedStoneItem::RedStoneItem(int id) : Item(id) {}
|
||||
|
||||
bool RedStoneItem::useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (level->getTile(x, y, z) != Tile::topSnow_Id) {
|
||||
if (face == 0) y--;
|
||||
if (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
if (!level->isEmptyTile(x, y, z)) return false;
|
||||
}
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
if (Tile::redStoneDust->mayPlace(level, x, y, z)) {
|
||||
if (!bTestUseOnOnly) {
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced(Tile::redStoneDust_Id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
Tile::redStoneDust_Id, itemInstance->getAuxValue(), 1));
|
||||
|
||||
itemInstance->count--;
|
||||
level->setTile(x, y, z, Tile::redStoneDust_Id);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class RedStoneItem : public Item
|
||||
{
|
||||
public:
|
||||
RedStoneItem(int id);
|
||||
class RedStoneItem : public Item {
|
||||
public:
|
||||
RedStoneItem(int id);
|
||||
|
||||
public:
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
public:
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
@@ -4,28 +4,24 @@
|
||||
#include "../Headers/net.minecraft.world.entity.h"
|
||||
#include "SaddleItem.h"
|
||||
|
||||
SaddleItem::SaddleItem(int id) : Item(id)
|
||||
{
|
||||
maxStackSize = 1;
|
||||
}
|
||||
SaddleItem::SaddleItem(int id) : Item(id) { maxStackSize = 1; }
|
||||
|
||||
bool SaddleItem::interactEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob)
|
||||
{
|
||||
if ( std::dynamic_pointer_cast<Pig>(mob) )
|
||||
{
|
||||
bool SaddleItem::interactEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob) {
|
||||
if (std::dynamic_pointer_cast<Pig>(mob)) {
|
||||
std::shared_ptr<Pig> pig = std::dynamic_pointer_cast<Pig>(mob);
|
||||
if (!pig->hasSaddle() && !pig->isBaby())
|
||||
{
|
||||
if (!pig->hasSaddle() && !pig->isBaby()) {
|
||||
pig->setSaddle(true);
|
||||
itemInstance->count--;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SaddleItem::hurtEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob, std::shared_ptr<Mob> attacker)
|
||||
{
|
||||
bool SaddleItem::hurtEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob,
|
||||
std::shared_ptr<Mob> attacker) {
|
||||
interactEnemy(itemInstance, mob);
|
||||
return true;
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class SaddleItem : public Item
|
||||
{
|
||||
class SaddleItem : public Item {
|
||||
public:
|
||||
SaddleItem(int id);
|
||||
SaddleItem(int id);
|
||||
|
||||
virtual bool interactEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob);
|
||||
virtual bool hurtEnemy(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Mob> mob, std::shared_ptr<Mob> attacker);
|
||||
virtual bool interactEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob);
|
||||
virtual bool hurtEnemy(std::shared_ptr<ItemInstance> itemInstance,
|
||||
std::shared_ptr<Mob> mob,
|
||||
std::shared_ptr<Mob> attacker);
|
||||
};
|
||||
@@ -4,28 +4,29 @@
|
||||
#include "../Headers/net.minecraft.world.level.h"
|
||||
#include "SeedFoodItem.h"
|
||||
|
||||
SeedFoodItem::SeedFoodItem(int id, int nutrition, float saturationMod, int resultId, int targetLand) : FoodItem(id, nutrition, saturationMod, false)
|
||||
{
|
||||
this->resultId = resultId;
|
||||
this->targetLand = targetLand;
|
||||
|
||||
SeedFoodItem::SeedFoodItem(int id, int nutrition, float saturationMod,
|
||||
int resultId, int targetLand)
|
||||
: FoodItem(id, nutrition, saturationMod, false) {
|
||||
this->resultId = resultId;
|
||||
this->targetLand = targetLand;
|
||||
}
|
||||
|
||||
bool SeedFoodItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
if (face != Facing::UP) return false;
|
||||
bool SeedFoodItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly) {
|
||||
if (face != Facing::UP) return false;
|
||||
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z)) return false;
|
||||
int targetType = level->getTile(x, y, z);
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z))
|
||||
return false;
|
||||
int targetType = level->getTile(x, y, z);
|
||||
|
||||
if (targetType == targetLand && level->isEmptyTile(x, y + 1, z))
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
level->setTile(x, y + 1, z, resultId);
|
||||
instance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (targetType == targetLand && level->isEmptyTile(x, y + 1, z)) {
|
||||
if (!bTestUseOnOnly) {
|
||||
level->setTile(x, y + 1, z, resultId);
|
||||
instance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
#include "FoodItem.h"
|
||||
|
||||
class SeedFoodItem : public FoodItem
|
||||
{
|
||||
class SeedFoodItem : public FoodItem {
|
||||
private:
|
||||
int resultId;
|
||||
int targetLand;
|
||||
int resultId;
|
||||
int targetLand;
|
||||
|
||||
public:
|
||||
SeedFoodItem(int id, int nutrition, float saturationMod, int resultId, int targetLand);
|
||||
SeedFoodItem(int id, int nutrition, float saturationMod, int resultId,
|
||||
int targetLand);
|
||||
|
||||
bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly);
|
||||
bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly);
|
||||
};
|
||||
@@ -8,28 +8,28 @@
|
||||
#include "ItemInstance.h"
|
||||
#include "SeedItem.h"
|
||||
|
||||
SeedItem::SeedItem(int id, int resultId, int targetLand) : Item(id)
|
||||
{
|
||||
SeedItem::SeedItem(int id, int resultId, int targetLand) : Item(id) {
|
||||
this->resultId = resultId;
|
||||
this->targetLand = targetLand;
|
||||
this->targetLand = targetLand;
|
||||
}
|
||||
|
||||
bool SeedItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
bool SeedItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (face != 1) return false;
|
||||
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z)) return false;
|
||||
if (!player->mayBuild(x, y, z) || !player->mayBuild(x, y + 1, z))
|
||||
return false;
|
||||
|
||||
int targetType = level->getTile(x, y, z);
|
||||
|
||||
if (targetType == targetLand && level->isEmptyTile(x, y + 1, z))
|
||||
{
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
level->setTile(x, y + 1, z, resultId);
|
||||
instance->count--;
|
||||
}
|
||||
if (targetType == targetLand && level->isEmptyTile(x, y + 1, z)) {
|
||||
if (!bTestUseOnOnly) {
|
||||
level->setTile(x, y + 1, z, resultId);
|
||||
instance->count--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class SeedItem : public Item
|
||||
{
|
||||
class SeedItem : public Item {
|
||||
private:
|
||||
int resultId;
|
||||
int targetLand;
|
||||
int resultId;
|
||||
int targetLand;
|
||||
|
||||
public:
|
||||
SeedItem(int id, int resultId, int targetLand);
|
||||
SeedItem(int id, int resultId, int targetLand);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
@@ -3,35 +3,34 @@
|
||||
#include "../Blocks/Tile.h"
|
||||
#include "../Headers/net.minecraft.world.entity.h"
|
||||
|
||||
ShearsItem::ShearsItem(int itemId) : Item(itemId)
|
||||
{
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(238);
|
||||
ShearsItem::ShearsItem(int itemId) : Item(itemId) {
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(238);
|
||||
}
|
||||
|
||||
bool ShearsItem::mineBlock(std::shared_ptr<ItemInstance> itemInstance, Level *level, int tile, int x, int y, int z, std::shared_ptr<Mob> owner)
|
||||
{
|
||||
if (tile == Tile::leaves_Id || tile == Tile::web_Id || tile == Tile::tallgrass_Id || tile == Tile::vine_Id || tile == Tile::tripWire_Id)
|
||||
{
|
||||
bool ShearsItem::mineBlock(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, int tile, int x, int y, int z,
|
||||
std::shared_ptr<Mob> owner) {
|
||||
if (tile == Tile::leaves_Id || tile == Tile::web_Id ||
|
||||
tile == Tile::tallgrass_Id || tile == Tile::vine_Id ||
|
||||
tile == Tile::tripWire_Id) {
|
||||
itemInstance->hurt(1, owner);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return Item::mineBlock(itemInstance, level, tile, x, y, z, owner);
|
||||
}
|
||||
|
||||
bool ShearsItem::canDestroySpecial(Tile *tile)
|
||||
{
|
||||
return tile->id == Tile::web_Id || tile->id == Tile::redStoneDust_Id || tile->id == Tile::tripWire_Id;
|
||||
bool ShearsItem::canDestroySpecial(Tile* tile) {
|
||||
return tile->id == Tile::web_Id || tile->id == Tile::redStoneDust_Id ||
|
||||
tile->id == Tile::tripWire_Id;
|
||||
}
|
||||
|
||||
float ShearsItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile)
|
||||
{
|
||||
if (tile->id == Tile::web_Id || tile->id == Tile::leaves_Id)
|
||||
{
|
||||
float ShearsItem::getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile) {
|
||||
if (tile->id == Tile::web_Id || tile->id == Tile::leaves_Id) {
|
||||
return 15;
|
||||
}
|
||||
if (tile->id == Tile::cloth_Id)
|
||||
{
|
||||
if (tile->id == Tile::cloth_Id) {
|
||||
return 5;
|
||||
}
|
||||
return Item::getDestroySpeed(itemInstance, tile);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class ShearsItem : public Item
|
||||
{
|
||||
class ShearsItem : public Item {
|
||||
public:
|
||||
ShearsItem(int itemId);
|
||||
virtual bool mineBlock(std::shared_ptr<ItemInstance> itemInstance, Level *level, int tile, int x, int y, int z, std::shared_ptr<Mob> owner);
|
||||
virtual bool canDestroySpecial(Tile *tile);
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance, Tile *tile);
|
||||
ShearsItem(int itemId);
|
||||
virtual bool mineBlock(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Level* level, int tile, int x, int y, int z,
|
||||
std::shared_ptr<Mob> owner);
|
||||
virtual bool canDestroySpecial(Tile* tile);
|
||||
virtual float getDestroySpeed(std::shared_ptr<ItemInstance> itemInstance,
|
||||
Tile* tile);
|
||||
};
|
||||
@@ -3,31 +3,28 @@
|
||||
#include "../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "ShovelItem.h"
|
||||
|
||||
TileArray *ShovelItem::diggables = NULL;
|
||||
TileArray* ShovelItem::diggables = NULL;
|
||||
|
||||
void ShovelItem::staticCtor()
|
||||
{
|
||||
ShovelItem::diggables = new TileArray( SHOVEL_DIGGABLES);
|
||||
diggables->data[0] = Tile::grass;
|
||||
diggables->data[1] = Tile::dirt;
|
||||
diggables->data[2] = Tile::sand;
|
||||
diggables->data[3] = Tile::gravel;
|
||||
diggables->data[4] = Tile::topSnow;
|
||||
diggables->data[5] = Tile::snow;
|
||||
diggables->data[6] = Tile::clay;
|
||||
diggables->data[7] = Tile::farmland;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[8] = Tile::hellSand;
|
||||
diggables->data[9] = Tile::mycel;
|
||||
void ShovelItem::staticCtor() {
|
||||
ShovelItem::diggables = new TileArray(SHOVEL_DIGGABLES);
|
||||
diggables->data[0] = Tile::grass;
|
||||
diggables->data[1] = Tile::dirt;
|
||||
diggables->data[2] = Tile::sand;
|
||||
diggables->data[3] = Tile::gravel;
|
||||
diggables->data[4] = Tile::topSnow;
|
||||
diggables->data[5] = Tile::snow;
|
||||
diggables->data[6] = Tile::clay;
|
||||
diggables->data[7] = Tile::farmland;
|
||||
// 4J - brought forward from 1.2.3
|
||||
diggables->data[8] = Tile::hellSand;
|
||||
diggables->data[9] = Tile::mycel;
|
||||
}
|
||||
|
||||
ShovelItem::ShovelItem(int id, const Tier *tier) : DiggerItem(id, 1, tier, diggables)
|
||||
{
|
||||
}
|
||||
ShovelItem::ShovelItem(int id, const Tier* tier)
|
||||
: DiggerItem(id, 1, tier, diggables) {}
|
||||
|
||||
bool ShovelItem::canDestroySpecial(Tile *tile)
|
||||
{
|
||||
if (tile == Tile::topSnow) return true;
|
||||
if (tile == Tile::snow) return true;
|
||||
return false;
|
||||
bool ShovelItem::canDestroySpecial(Tile* tile) {
|
||||
if (tile == Tile::topSnow) return true;
|
||||
if (tile == Tile::snow) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -2,14 +2,13 @@
|
||||
#include "DiggerItem.h"
|
||||
|
||||
#define SHOVEL_DIGGABLES 10
|
||||
class ShovelItem : public DiggerItem
|
||||
{
|
||||
class ShovelItem : public DiggerItem {
|
||||
private:
|
||||
static TileArray *diggables;
|
||||
static TileArray* diggables;
|
||||
|
||||
public:
|
||||
static void staticCtor();
|
||||
ShovelItem(int id, const Tier *tier);
|
||||
static void staticCtor();
|
||||
ShovelItem(int id, const Tier* tier);
|
||||
|
||||
bool canDestroySpecial(Tile *tile);
|
||||
bool canDestroySpecial(Tile* tile);
|
||||
};
|
||||
@@ -7,53 +7,49 @@
|
||||
#include "SignItem.h"
|
||||
#include "../Stats/GenericStats.h"
|
||||
|
||||
SignItem::SignItem(int id) : Item(id)
|
||||
{
|
||||
// 4J-PB - Changed for TU9
|
||||
maxStackSize = 16;
|
||||
SignItem::SignItem(int id) : Item(id) {
|
||||
// 4J-PB - Changed for TU9
|
||||
maxStackSize = 16;
|
||||
}
|
||||
|
||||
bool SignItem::useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
|
||||
{
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
if (face == 0) return false;
|
||||
if (!level->getMaterial(x, y, z)->isSolid()) return false;
|
||||
bool SignItem::useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x, int y,
|
||||
int z, int face, float clickX, float clickY, float clickZ,
|
||||
bool bTestUseOnOnly) {
|
||||
// 4J-PB - Adding a test only version to allow tooltips to be displayed
|
||||
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 (face == 1) y++;
|
||||
if (face == 2) z--;
|
||||
if (face == 3) z++;
|
||||
if (face == 4) x--;
|
||||
if (face == 5) x++;
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
|
||||
if (!player->mayBuild(x, y, z)) return false;
|
||||
if (!Tile::sign->mayPlace(level, x, y, z)) return false;
|
||||
|
||||
if (!Tile::sign->mayPlace(level, x, y, z)) return false;
|
||||
if (!bTestUseOnOnly) {
|
||||
if (face == 1) {
|
||||
int rot = Mth::floor(((player->yRot + 180) * 16) / 360 + 0.5) & 15;
|
||||
level->setTileAndData(x, y, z, Tile::sign_Id, rot);
|
||||
} else {
|
||||
level->setTileAndData(x, y, z, Tile::wallSign_Id, face);
|
||||
}
|
||||
|
||||
if(!bTestUseOnOnly)
|
||||
{
|
||||
if (face == 1)
|
||||
{
|
||||
int rot = Mth::floor(((player->yRot + 180) * 16) / 360 + 0.5) & 15;
|
||||
level->setTileAndData(x, y, z, Tile::sign_Id, rot);
|
||||
}
|
||||
else
|
||||
{
|
||||
level->setTileAndData(x, y, z, Tile::wallSign_Id, face);
|
||||
}
|
||||
instance->count--;
|
||||
std::shared_ptr<SignTileEntity> ste =
|
||||
std::dynamic_pointer_cast<SignTileEntity>(
|
||||
level->getTileEntity(x, y, z));
|
||||
if (ste != NULL) player->openTextEdit(ste);
|
||||
|
||||
instance->count--;
|
||||
std::shared_ptr<SignTileEntity> ste = std::dynamic_pointer_cast<SignTileEntity>( level->getTileEntity(x, y, z) );
|
||||
if (ste != NULL) player->openTextEdit(ste);
|
||||
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(
|
||||
GenericStats::blocksPlaced((face==1) ? Tile::sign_Id : Tile::wallSign_Id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
(face==1) ? Tile::sign_Id : Tile::wallSign_Id,
|
||||
instance->getAuxValue(),
|
||||
1)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
||||
player->awardStat(GenericStats::blocksPlaced(
|
||||
(face == 1) ? Tile::sign_Id : Tile::wallSign_Id),
|
||||
GenericStats::param_blocksPlaced(
|
||||
(face == 1) ? Tile::sign_Id : Tile::wallSign_Id,
|
||||
instance->getAuxValue(), 1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class SignItem : public Item
|
||||
{
|
||||
class SignItem : public Item {
|
||||
public:
|
||||
SignItem(int id);
|
||||
SignItem(int id);
|
||||
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
||||
virtual bool useOn(std::shared_ptr<ItemInstance> instance,
|
||||
std::shared_ptr<Player> player, Level* level, int x,
|
||||
int y, int z, int face, float clickX, float clickY,
|
||||
float clickZ, bool bTestUseOnOnly = false);
|
||||
};
|
||||
@@ -6,18 +6,18 @@
|
||||
#include "SnowballItem.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
|
||||
SnowballItem::SnowballItem(int id) : Item(id)
|
||||
{
|
||||
this->maxStackSize = 16;
|
||||
}
|
||||
SnowballItem::SnowballItem(int id) : Item(id) { this->maxStackSize = 16; }
|
||||
|
||||
std::shared_ptr<ItemInstance> SnowballItem::use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player)
|
||||
{
|
||||
if (!player->abilities.instabuild)
|
||||
{
|
||||
instance->count--;
|
||||
}
|
||||
level->playSound((std::shared_ptr<Entity> ) player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide) level->addEntity( std::shared_ptr<Snowball>( new Snowball(level, player) ) );
|
||||
std::shared_ptr<ItemInstance> SnowballItem::use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player) {
|
||||
if (!player->abilities.instabuild) {
|
||||
instance->count--;
|
||||
}
|
||||
level->playSound((std::shared_ptr<Entity>)player, eSoundType_RANDOM_BOW,
|
||||
0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
||||
if (!level->isClientSide)
|
||||
level->addEntity(
|
||||
std::shared_ptr<Snowball>(new Snowball(level, player)));
|
||||
return instance;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
class SnowballItem : public Item
|
||||
{
|
||||
class SnowballItem : public Item {
|
||||
public:
|
||||
SnowballItem(int id);
|
||||
SnowballItem(int id);
|
||||
|
||||
virtual std::shared_ptr<ItemInstance> use(std::shared_ptr<ItemInstance> instance, Level *level, std::shared_ptr<Player> player);
|
||||
virtual std::shared_ptr<ItemInstance> use(
|
||||
std::shared_ptr<ItemInstance> instance, Level* level,
|
||||
std::shared_ptr<Player> player);
|
||||
};
|
||||
@@ -2,17 +2,15 @@
|
||||
#include "../../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "AnvilTileItem.h"
|
||||
|
||||
AnvilTileItem::AnvilTileItem(Tile *tile) : MultiTextureTileItem(tile->id - 256, tile, (int *)AnvilTile::ANVIL_NAMES, 3)
|
||||
{
|
||||
AnvilTileItem::AnvilTileItem(Tile* tile)
|
||||
: MultiTextureTileItem(tile->id - 256, tile, (int*)AnvilTile::ANVIL_NAMES,
|
||||
3) {}
|
||||
|
||||
int AnvilTileItem::getLevelDataForAuxValue(int auxValue) {
|
||||
return auxValue << 2;
|
||||
}
|
||||
|
||||
int AnvilTileItem::getLevelDataForAuxValue(int auxValue)
|
||||
{
|
||||
return auxValue << 2;
|
||||
}
|
||||
|
||||
unsigned int AnvilTileItem::getDescriptionId(int iData)
|
||||
{
|
||||
int damage = iData >> 2;
|
||||
return MultiTextureTileItem::getDescriptionId(damage);
|
||||
unsigned int AnvilTileItem::getDescriptionId(int iData) {
|
||||
int damage = iData >> 2;
|
||||
return MultiTextureTileItem::getDescriptionId(damage);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
#include "MultiTextureTileItem.h"
|
||||
|
||||
class AnvilTileItem : public MultiTextureTileItem
|
||||
{
|
||||
class AnvilTileItem : public MultiTextureTileItem {
|
||||
public:
|
||||
AnvilTileItem(Tile *tile);
|
||||
AnvilTileItem(Tile* tile);
|
||||
|
||||
int getLevelDataForAuxValue(int auxValue);
|
||||
virtual unsigned int getDescriptionId(int iData);
|
||||
|
||||
int getLevelDataForAuxValue(int auxValue);
|
||||
virtual unsigned int getDescriptionId(int iData);
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -2,20 +2,15 @@
|
||||
#include "../../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "AuxDataTileItem.h"
|
||||
|
||||
AuxDataTileItem::AuxDataTileItem(int id, Tile *parentTile) : TileItem(id)
|
||||
{
|
||||
this->parentTile = parentTile;
|
||||
AuxDataTileItem::AuxDataTileItem(int id, Tile* parentTile) : TileItem(id) {
|
||||
this->parentTile = parentTile;
|
||||
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
}
|
||||
|
||||
Icon *AuxDataTileItem::getIcon(int itemAuxValue)
|
||||
{
|
||||
return parentTile->getTexture(2, itemAuxValue);
|
||||
Icon* AuxDataTileItem::getIcon(int itemAuxValue) {
|
||||
return parentTile->getTexture(2, itemAuxValue);
|
||||
}
|
||||
|
||||
int AuxDataTileItem::getLevelDataForAuxValue(int auxValue)
|
||||
{
|
||||
return auxValue;
|
||||
}
|
||||
int AuxDataTileItem::getLevelDataForAuxValue(int auxValue) { return auxValue; }
|
||||
@@ -4,14 +4,13 @@
|
||||
|
||||
class Tile;
|
||||
|
||||
class AuxDataTileItem : public TileItem
|
||||
{
|
||||
class AuxDataTileItem : public TileItem {
|
||||
private:
|
||||
Tile *parentTile;
|
||||
Tile* parentTile;
|
||||
|
||||
public:
|
||||
AuxDataTileItem(int id, Tile *parentTile);
|
||||
AuxDataTileItem(int id, Tile* parentTile);
|
||||
|
||||
Icon *getIcon(int itemAuxValue);
|
||||
int getLevelDataForAuxValue(int auxValue);
|
||||
Icon* getIcon(int itemAuxValue);
|
||||
int getLevelDataForAuxValue(int auxValue);
|
||||
};
|
||||
@@ -4,65 +4,40 @@
|
||||
#include "../DyePowderItem.h"
|
||||
#include "ClothTileItem.h"
|
||||
|
||||
const unsigned int ClothTileItem::COLOR_DESCS[] =
|
||||
{
|
||||
IDS_TILE_CLOTH_BLACK,
|
||||
IDS_TILE_CLOTH_RED,
|
||||
IDS_TILE_CLOTH_GREEN,
|
||||
IDS_TILE_CLOTH_BROWN,
|
||||
IDS_TILE_CLOTH_BLUE,
|
||||
IDS_TILE_CLOTH_PURPLE,
|
||||
IDS_TILE_CLOTH_CYAN,
|
||||
IDS_TILE_CLOTH_SILVER,
|
||||
IDS_TILE_CLOTH_GRAY,
|
||||
IDS_TILE_CLOTH_PINK,
|
||||
IDS_TILE_CLOTH_LIME,
|
||||
IDS_TILE_CLOTH_YELLOW,
|
||||
IDS_TILE_CLOTH_LIGHT_BLUE,
|
||||
IDS_TILE_CLOTH_MAGENTA,
|
||||
IDS_TILE_CLOTH_ORANGE,
|
||||
IDS_TILE_CLOTH_WHITE
|
||||
};
|
||||
const unsigned int ClothTileItem::COLOR_DESCS[] = {
|
||||
IDS_TILE_CLOTH_BLACK, IDS_TILE_CLOTH_RED, IDS_TILE_CLOTH_GREEN,
|
||||
IDS_TILE_CLOTH_BROWN, IDS_TILE_CLOTH_BLUE, IDS_TILE_CLOTH_PURPLE,
|
||||
IDS_TILE_CLOTH_CYAN, IDS_TILE_CLOTH_SILVER, IDS_TILE_CLOTH_GRAY,
|
||||
IDS_TILE_CLOTH_PINK, IDS_TILE_CLOTH_LIME, IDS_TILE_CLOTH_YELLOW,
|
||||
IDS_TILE_CLOTH_LIGHT_BLUE, IDS_TILE_CLOTH_MAGENTA, IDS_TILE_CLOTH_ORANGE,
|
||||
IDS_TILE_CLOTH_WHITE};
|
||||
|
||||
const unsigned int ClothTileItem::CARPET_COLOR_DESCS[] =
|
||||
{
|
||||
IDS_TILE_CARPET_BLACK,
|
||||
IDS_TILE_CARPET_RED,
|
||||
IDS_TILE_CARPET_GREEN,
|
||||
IDS_TILE_CARPET_BROWN,
|
||||
IDS_TILE_CARPET_BLUE,
|
||||
IDS_TILE_CARPET_PURPLE,
|
||||
IDS_TILE_CARPET_CYAN,
|
||||
IDS_TILE_CARPET_SILVER,
|
||||
IDS_TILE_CARPET_GRAY,
|
||||
IDS_TILE_CARPET_PINK,
|
||||
IDS_TILE_CARPET_LIME,
|
||||
IDS_TILE_CARPET_YELLOW,
|
||||
IDS_TILE_CARPET_LIGHT_BLUE,
|
||||
IDS_TILE_CARPET_MAGENTA,
|
||||
IDS_TILE_CARPET_ORANGE,
|
||||
IDS_TILE_CARPET_WHITE
|
||||
};
|
||||
const unsigned int ClothTileItem::CARPET_COLOR_DESCS[] = {
|
||||
IDS_TILE_CARPET_BLACK, IDS_TILE_CARPET_RED, IDS_TILE_CARPET_GREEN,
|
||||
IDS_TILE_CARPET_BROWN, IDS_TILE_CARPET_BLUE, IDS_TILE_CARPET_PURPLE,
|
||||
IDS_TILE_CARPET_CYAN, IDS_TILE_CARPET_SILVER, IDS_TILE_CARPET_GRAY,
|
||||
IDS_TILE_CARPET_PINK, IDS_TILE_CARPET_LIME, IDS_TILE_CARPET_YELLOW,
|
||||
IDS_TILE_CARPET_LIGHT_BLUE, IDS_TILE_CARPET_MAGENTA, IDS_TILE_CARPET_ORANGE,
|
||||
IDS_TILE_CARPET_WHITE};
|
||||
|
||||
ClothTileItem::ClothTileItem(int id) : TileItem(id)
|
||||
{
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
ClothTileItem::ClothTileItem(int id) : TileItem(id) {
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
}
|
||||
|
||||
Icon *ClothTileItem::getIcon(int itemAuxValue)
|
||||
{
|
||||
return Tile::cloth->getTexture(2, ClothTile::getTileDataForItemAuxValue(itemAuxValue));
|
||||
|
||||
Icon* ClothTileItem::getIcon(int itemAuxValue) {
|
||||
return Tile::cloth->getTexture(
|
||||
2, ClothTile::getTileDataForItemAuxValue(itemAuxValue));
|
||||
}
|
||||
|
||||
int ClothTileItem::getLevelDataForAuxValue(int auxValue)
|
||||
{
|
||||
return auxValue;
|
||||
}
|
||||
int ClothTileItem::getLevelDataForAuxValue(int auxValue) { return auxValue; }
|
||||
|
||||
unsigned int ClothTileItem::getDescriptionId(std::shared_ptr<ItemInstance> instance)
|
||||
{
|
||||
if(getTileId() == Tile::woolCarpet_Id) return CARPET_COLOR_DESCS[ClothTile::getTileDataForItemAuxValue(instance->getAuxValue())];
|
||||
else return COLOR_DESCS[ClothTile::getTileDataForItemAuxValue(instance->getAuxValue())];
|
||||
unsigned int ClothTileItem::getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance) {
|
||||
if (getTileId() == Tile::woolCarpet_Id)
|
||||
return CARPET_COLOR_DESCS[ClothTile::getTileDataForItemAuxValue(
|
||||
instance->getAuxValue())];
|
||||
else
|
||||
return COLOR_DESCS[ClothTile::getTileDataForItemAuxValue(
|
||||
instance->getAuxValue())];
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "TileItem.h"
|
||||
|
||||
class ClothTileItem : public TileItem
|
||||
{
|
||||
public:
|
||||
static const unsigned int COLOR_DESCS[];
|
||||
static const unsigned int CARPET_COLOR_DESCS[];
|
||||
class ClothTileItem : public TileItem {
|
||||
public:
|
||||
static const unsigned int COLOR_DESCS[];
|
||||
static const unsigned int CARPET_COLOR_DESCS[];
|
||||
|
||||
ClothTileItem(int id);
|
||||
|
||||
virtual Icon *getIcon(int itemAuxValue);
|
||||
virtual int getLevelDataForAuxValue(int auxValue);
|
||||
virtual unsigned int getDescriptionId(std::shared_ptr<ItemInstance> instance);
|
||||
ClothTileItem(int id);
|
||||
|
||||
virtual Icon* getIcon(int itemAuxValue);
|
||||
virtual int getLevelDataForAuxValue(int auxValue);
|
||||
virtual unsigned int getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance);
|
||||
};
|
||||
@@ -2,59 +2,51 @@
|
||||
#include "../../Headers/net.minecraft.world.level.tile.h"
|
||||
#include "ColoredTileItem.h"
|
||||
|
||||
ColoredTileItem::ColoredTileItem(int id, bool stackedByData) : TileItem(id)
|
||||
{
|
||||
this->colorTile = Tile::tiles[getTileId()];
|
||||
ColoredTileItem::ColoredTileItem(int id, bool stackedByData) : TileItem(id) {
|
||||
this->colorTile = Tile::tiles[getTileId()];
|
||||
|
||||
if (stackedByData)
|
||||
{
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
}
|
||||
if (stackedByData) {
|
||||
setMaxDamage(0);
|
||||
setStackedByData(true);
|
||||
}
|
||||
}
|
||||
|
||||
ColoredTileItem::~ColoredTileItem()
|
||||
{
|
||||
if(descriptionPostfixes.data != NULL) delete [] descriptionPostfixes.data;
|
||||
ColoredTileItem::~ColoredTileItem() {
|
||||
if (descriptionPostfixes.data != NULL) delete[] descriptionPostfixes.data;
|
||||
}
|
||||
|
||||
int ColoredTileItem::getColor(std::shared_ptr<ItemInstance> item, int spriteLayer)
|
||||
{
|
||||
return colorTile->getColor(item->getAuxValue());
|
||||
int ColoredTileItem::getColor(std::shared_ptr<ItemInstance> item,
|
||||
int spriteLayer) {
|
||||
return colorTile->getColor(item->getAuxValue());
|
||||
}
|
||||
|
||||
Icon *ColoredTileItem::getIcon(int auxValue)
|
||||
{
|
||||
return colorTile->getTexture(0, auxValue);
|
||||
Icon* ColoredTileItem::getIcon(int auxValue) {
|
||||
return colorTile->getTexture(0, auxValue);
|
||||
}
|
||||
|
||||
int ColoredTileItem::getLevelDataForAuxValue(int auxValue)
|
||||
{
|
||||
return auxValue;
|
||||
int ColoredTileItem::getLevelDataForAuxValue(int auxValue) { return auxValue; }
|
||||
|
||||
ColoredTileItem* ColoredTileItem::setDescriptionPostfixes(
|
||||
intArray descriptionPostfixes) {
|
||||
if (this->descriptionPostfixes.data != NULL)
|
||||
delete this->descriptionPostfixes.data;
|
||||
this->descriptionPostfixes = intArray(descriptionPostfixes.length);
|
||||
for (unsigned int i = 0; i < descriptionPostfixes.length; ++i) {
|
||||
this->descriptionPostfixes[i] = descriptionPostfixes[i];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
ColoredTileItem *ColoredTileItem::setDescriptionPostfixes(intArray descriptionPostfixes)
|
||||
{
|
||||
if(this->descriptionPostfixes.data != NULL) delete this->descriptionPostfixes.data;
|
||||
this->descriptionPostfixes = intArray(descriptionPostfixes.length);
|
||||
for(unsigned int i = 0; i < descriptionPostfixes.length; ++i )
|
||||
{
|
||||
this->descriptionPostfixes[i] = descriptionPostfixes[i];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned int ColoredTileItem::getDescriptionId(std::shared_ptr<ItemInstance> instance)
|
||||
{
|
||||
if (descriptionPostfixes.data == NULL)
|
||||
{
|
||||
return TileItem::getDescriptionId(instance);
|
||||
}
|
||||
int id = instance->getAuxValue();
|
||||
if (id >= 0 && id < descriptionPostfixes.length)
|
||||
{
|
||||
return descriptionPostfixes[id]; //TileItem::getDescriptionId(instance) + "." + descriptionPostfixes[id];
|
||||
}
|
||||
return TileItem::getDescriptionId(instance);
|
||||
unsigned int ColoredTileItem::getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance) {
|
||||
if (descriptionPostfixes.data == NULL) {
|
||||
return TileItem::getDescriptionId(instance);
|
||||
}
|
||||
int id = instance->getAuxValue();
|
||||
if (id >= 0 && id < descriptionPostfixes.length) {
|
||||
return descriptionPostfixes[id]; // TileItem::getDescriptionId(instance)
|
||||
// + "." + descriptionPostfixes[id];
|
||||
}
|
||||
return TileItem::getDescriptionId(instance);
|
||||
}
|
||||
@@ -4,22 +4,23 @@
|
||||
|
||||
class ItemInstance;
|
||||
|
||||
class ColoredTileItem : public TileItem
|
||||
{
|
||||
class ColoredTileItem : public TileItem {
|
||||
private:
|
||||
// Was const, but removing that so we don't have to make all the functions const as well!
|
||||
Tile *colorTile;
|
||||
intArray descriptionPostfixes;
|
||||
// Was const, but removing that so we don't have to make all the functions
|
||||
// const as well!
|
||||
Tile* colorTile;
|
||||
intArray descriptionPostfixes;
|
||||
|
||||
public:
|
||||
using TileItem::getColor;
|
||||
ColoredTileItem(int id, bool stackedByData);
|
||||
~ColoredTileItem();
|
||||
using TileItem::getColor;
|
||||
ColoredTileItem(int id, bool stackedByData);
|
||||
~ColoredTileItem();
|
||||
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual Icon *getIcon(int auxValue);
|
||||
virtual int getLevelDataForAuxValue(int auxValue);
|
||||
virtual int getColor(std::shared_ptr<ItemInstance> item, int spriteLayer);
|
||||
virtual Icon* getIcon(int auxValue);
|
||||
virtual int getLevelDataForAuxValue(int auxValue);
|
||||
|
||||
ColoredTileItem *setDescriptionPostfixes(intArray descriptionPostfixes);
|
||||
virtual unsigned int getDescriptionId(std::shared_ptr<ItemInstance> instance);
|
||||
ColoredTileItem* setDescriptionPostfixes(intArray descriptionPostfixes);
|
||||
virtual unsigned int getDescriptionId(
|
||||
std::shared_ptr<ItemInstance> instance);
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user