Files
neoLegacy/Minecraft.World/FireworksRecipe.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

421 lines
9.5 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.item.h"
#include "FireworksRecipe.h"
DWORD FireworksRecipe::tlsIdx = 0;
FireworksRecipe::ThreadStorage *FireworksRecipe::tlsDefault = nullptr;
FireworksRecipe::ThreadStorage::ThreadStorage()
{
resultItem = nullptr;
}
void FireworksRecipe::CreateNewThreadStorage()
{
ThreadStorage *tls = new ThreadStorage();
if(tlsDefault == nullptr )
{
tlsIdx = TlsAlloc();
tlsDefault = tls;
}
TlsSetValue(tlsIdx, tls);
}
void FireworksRecipe::UseDefaultThreadStorage()
{
TlsSetValue(tlsIdx, tlsDefault);
}
void FireworksRecipe::ReleaseThreadStorage()
{
ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
if( tls == tlsDefault ) return;
delete tls;
}
void FireworksRecipe::setResultItem(shared_ptr<ItemInstance> item)
{
ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
if (tls == nullptr) tls = tlsDefault;
tls->resultItem = item;
}
FireworksRecipe::FireworksRecipe()
{
//resultItem = nullptr;
}
bool FireworksRecipe::matches(shared_ptr<CraftingContainer> craftSlots, Level *level)
{
shared_ptr<ItemInstance> resultItem = nullptr;
int paperCount = 0;
int sulphurCount = 0;
int colorCount = 0;
int chargeCount = 0;
int chargeComponents = 0;
int typeComponents = 0;
for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
if (item == nullptr) continue;
if (item->id == Item::gunpowder_Id)
{
sulphurCount++;
}
else if (item->id == Item::firework_charge_Id)
{
chargeCount++;
}
else if (item->id == Item::dye_Id)
{
colorCount++;
}
else if (item->id == Item::paper_Id)
{
paperCount++;
}
else if (item->id == Item::glowstone_dust_Id)
{
// glowstone dust gives flickering
chargeComponents++;
}
else if (item->id == Item::diamond_Id)
{
// diamonds give trails
chargeComponents++;
}
else if (item->id == Item::fire_charge_Id)
{
// fireball gives larger explosion
typeComponents++;
}
else if (item->id == Item::feather_Id)
{
// burst
typeComponents++;
}
else if (item->id == Item::gold_nugget_Id)
{
// star
typeComponents++;
}
else if (item->id == Item::skull_Id)
{
// creeper
typeComponents++;
}
else
{
setResultItem(resultItem);
return false;
}
}
chargeComponents += colorCount + typeComponents;
if (sulphurCount > 3 || paperCount > 1)
{
setResultItem(resultItem);
return false;
}
// create fireworks
if (sulphurCount >= 1 && paperCount == 1 && chargeComponents == 0)
{
resultItem = std::make_shared<ItemInstance>(Item::fireworks, 3);
{
CompoundTag *itemTag = new CompoundTag();
CompoundTag *fireTag = new CompoundTag(FireworksItem::TAG_FIREWORKS);
ListTag<CompoundTag> *expTags = new ListTag<CompoundTag>(FireworksItem::TAG_EXPLOSIONS);
for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
if (item == nullptr || item->id != Item::firework_charge_Id) continue;
if (item->hasTag() && item->getTag()->contains(FireworksItem::TAG_EXPLOSION))
{
expTags->add(static_cast<CompoundTag *>(item->getTag()->getCompound(FireworksItem::TAG_EXPLOSION)->copy()));
}
}
if (expTags->size() > 0) fireTag->put(FireworksItem::TAG_EXPLOSIONS, expTags);
else delete expTags;
fireTag->putByte(FireworksItem::TAG_FLIGHT, static_cast<byte>(sulphurCount));
itemTag->put(FireworksItem::TAG_FIREWORKS, fireTag);
resultItem->setTag(itemTag);
}
setResultItem(resultItem);
return true;
}
// create firecharge
if (sulphurCount == 1 && paperCount == 0 && chargeCount == 0 && colorCount > 0 && typeComponents <= 1)
{
resultItem = std::make_shared<ItemInstance>(Item::firework_charge);
CompoundTag *itemTag = new CompoundTag();
CompoundTag *expTag = new CompoundTag(FireworksItem::TAG_EXPLOSION);
byte type = 0;
vector<int> colors;
for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
if (item == nullptr) continue;
if (item->id == Item::dye_Id)
{
colors.push_back(DyePowderItem::COLOR_RGB[item->getAuxValue()]);
}
else if (item->id == Item::glowstone_dust_Id)
{
// glowstone dust gives flickering
expTag->putBoolean(FireworksItem::TAG_E_FLICKER, true);
}
else if (item->id == Item::diamond_Id)
{
// diamonds give trails
expTag->putBoolean(FireworksItem::TAG_E_TRAIL, true);
}
else if (item->id == Item::fire_charge_Id)
{
type = FireworksItem::TYPE_BIG;
}
else if (item->id == Item::feather_Id)
{
type = FireworksItem::TYPE_BURST;
}
else if (item->id == Item::gold_nugget_Id)
{
type = FireworksItem::TYPE_STAR;
}
else if (item->id == Item::skull_Id)
{
type = FireworksItem::TYPE_CREEPER;
}
}
intArray colorArray(static_cast<unsigned int>(colors.size()));
for (int i = 0; i < colorArray.length; i++)
{
colorArray[i] = colors.at(i);
}
expTag->putIntArray(FireworksItem::TAG_E_COLORS, colorArray);
expTag->putByte(FireworksItem::TAG_E_TYPE, type);
itemTag->put(FireworksItem::TAG_EXPLOSION, expTag);
resultItem->setTag(itemTag);
setResultItem(resultItem);
return true;
}
// apply fade colors to firecharge
if (sulphurCount == 0 && paperCount == 0 && chargeCount == 1 && colorCount > 0 && colorCount == chargeComponents)
{
vector<int> colors;
for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
if (item == nullptr) continue;
if (item->id == Item::dye_Id)
{
colors.push_back(DyePowderItem::COLOR_RGB[item->getAuxValue()]);
}
else if (item->id == Item::firework_charge_Id)
{
resultItem = item->copy();
resultItem->count = 1;
}
}
intArray colorArray(static_cast<unsigned int>(colors.size()));
for (int i = 0; i < colorArray.length; i++)
{
colorArray[i] = colors.at(i);
}
if (resultItem != nullptr && resultItem->hasTag())
{
CompoundTag *compound = resultItem->getTag()->getCompound(FireworksItem::TAG_EXPLOSION);
if (compound == nullptr)
{
delete colorArray.data;
setResultItem(resultItem);
return false;
}
compound->putIntArray(FireworksItem::TAG_E_FADECOLORS, colorArray);
}
else
{
delete colorArray.data;
setResultItem(resultItem);
return false;
}
setResultItem(resultItem);
return true;
}
setResultItem(resultItem);
return false;
}
shared_ptr<ItemInstance> FireworksRecipe::assemble(shared_ptr<CraftingContainer> craftSlots)
{
ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
if (tls == nullptr) tls = tlsDefault;
return tls->resultItem->copy();
//return resultItem->copy();
}
int FireworksRecipe::size()
{
return 10;
}
const ItemInstance *FireworksRecipe::getResultItem()
{
ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
if (tls == nullptr) tls = tlsDefault;
return tls->resultItem.get();
//return resultItem.get();
}
void FireworksRecipe::updatePossibleRecipes(shared_ptr<CraftingContainer> craftSlots, bool *firework, bool *charge, bool *fade)
{
*firework = false;
*charge = false;
*fade = false;
int paperCount = 0;
int sulphurCount = 0;
int colorCount = 0;
int chargeCount = 0;
int chargeComponents = 0;
int typeComponents = 0;
for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
if (item == nullptr) continue;
if (item->id == Item::gunpowder_Id)
{
sulphurCount++;
}
else if (item->id == Item::firework_charge_Id)
{
chargeCount++;
}
else if (item->id == Item::dye_Id)
{
colorCount++;
}
else if (item->id == Item::paper_Id)
{
paperCount++;
}
else if (item->id == Item::glowstone_dust_Id)
{
// glowstone dust gives flickering
chargeComponents++;
}
else if (item->id == Item::diamond_Id)
{
// diamonds give trails
chargeComponents++;
}
else if (item->id == Item::fire_charge_Id)
{
// fireball gives larger explosion
typeComponents++;
}
else if (item->id == Item::feather_Id)
{
// burst
typeComponents++;
}
else if (item->id == Item::gold_nugget_Id)
{
// star
typeComponents++;
}
else if (item->id == Item::skull_Id)
{
// creeper
typeComponents++;
}
else
{
return;
}
}
chargeComponents += colorCount + typeComponents;
if (sulphurCount > 3 || paperCount > 1)
{
return;
}
// create fireworks
if ( paperCount <= 1 && chargeComponents == 0 )
{
*firework = true;
}
// create firecharge
if ( sulphurCount <= 1 && colorCount >= 0 && paperCount == 0 && chargeCount == 0 && typeComponents <= 1 )
{
*charge = true;
}
// apply fade colors to firecharge
if ( sulphurCount == 0 && paperCount == 0 && chargeCount <= 1 && colorCount >= 0 )
{
*fade = true;
}
}
bool FireworksRecipe::isValidIngredient(shared_ptr<ItemInstance> item, bool firework, bool charge, bool fade)
{
bool valid = false;
switch(item->id)
{
case Item::gunpowder_Id:
valid = firework || charge;
break;
case Item::firework_charge_Id:
valid = firework || fade;
break;
case Item::dye_Id:
valid = charge || fade;
break;
case Item::paper_Id:
valid = firework;
break;
case Item::glowstone_dust_Id:
valid = charge;
break;
case Item::diamond_Id:
valid = charge;
break;
case Item::fire_charge_Id:
valid = charge;
break;
case Item::feather_Id:
valid = charge;
break;
case Item::gold_nugget_Id:
valid = charge;
break;
case Item::skull_Id:
valid = charge;
break;
}
return valid;
}