mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-08 23:13:00 +00:00
Some checks are pending
Sync branches with main / sync (push) Waiting to run
* CustomPayloadPacket Changes commented all code for old equip packets cleaned up custom payload key creation added 2 new payload packet definitions for upcoming changes * server sided recipe list * code cleanup for recipes * add dtor for recipe classes to fix memory leak * forgot this part to the dtor commit * dtor changes tested and fixed * server side creative menu list
247 lines
6.3 KiB
C++
247 lines
6.3 KiB
C++
// package net.minecraft.world.item.crafting;
|
|
//
|
|
// import java.util.*;
|
|
//
|
|
// import net.minecraft.world.inventory.CraftingContainer;
|
|
// import net.minecraft.world.item.ItemInstance;
|
|
#include "stdafx.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.inventory.h"
|
|
#include "Tile.h"
|
|
#include "Recipy.h"
|
|
#include "Recipes.h"
|
|
#include "ShapelessRecipy.h"
|
|
|
|
ShapelessRecipy::ShapelessRecipy(ItemInstance *result, vector<ItemInstance *> *ingredients, _eGroupType egroup) :
|
|
result(result),
|
|
ingredients(ingredients),
|
|
group(egroup)
|
|
{
|
|
}
|
|
|
|
ShapelessRecipy::~ShapelessRecipy() {
|
|
for (int i = 0; i < ingredients->size(); i++) {
|
|
delete (*ingredients)[i];
|
|
}
|
|
|
|
delete ingredients;
|
|
delete result;
|
|
|
|
ingredients = nullptr;
|
|
result = nullptr;
|
|
}
|
|
|
|
|
|
const int ShapelessRecipy::getGroup()
|
|
{
|
|
return group;
|
|
}
|
|
|
|
const ItemInstance *ShapelessRecipy::getResultItem()
|
|
{
|
|
return result;
|
|
}
|
|
|
|
bool ShapelessRecipy::matches(shared_ptr<CraftingContainer> craftSlots, Level *level)
|
|
{
|
|
vector <ItemInstance *> tempList = *ingredients;
|
|
|
|
for (int y = 0; y < 3; y++)
|
|
{
|
|
for (int x = 0; x < 3; x++)
|
|
{
|
|
shared_ptr<ItemInstance> item = craftSlots->getItem(x, y);
|
|
|
|
if (item)
|
|
{
|
|
bool found = false;
|
|
|
|
auto citEnd = ingredients->end();
|
|
for ( ItemInstance *ingredient : *ingredients )
|
|
{
|
|
if (item->id == ingredient->id && (ingredient->getAuxValue() == Recipes::ANY_AUX_VALUE || item->getAuxValue() == ingredient->getAuxValue()))
|
|
{
|
|
found = true;
|
|
auto it = find(tempList.begin(), tempList.end(), ingredient);
|
|
if(it != tempList.end() ) tempList.erase(it);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return tempList.empty();
|
|
}
|
|
|
|
shared_ptr<ItemInstance> ShapelessRecipy::assemble(shared_ptr<CraftingContainer> craftSlots)
|
|
{
|
|
return result->copy();
|
|
}
|
|
|
|
int ShapelessRecipy::size()
|
|
{
|
|
return static_cast<int>(ingredients->size());
|
|
}
|
|
|
|
// 4J-PB
|
|
bool ShapelessRecipy::reqs(int iRecipe)
|
|
{
|
|
vector <ItemInstance *> *tempList = new vector<ItemInstance *>;
|
|
|
|
*tempList=*ingredients;
|
|
|
|
//printf("ShapelessRecipy %d\n",iRecipe);
|
|
|
|
int iCount=0;
|
|
for ( auto ingredient = ingredients->begin(); ingredient != ingredients->end(); ingredient++)
|
|
{
|
|
//printf("\tIngredient %d is %d\n",iCount++,(*ingredient)->id);
|
|
//if (item->id == (*ingredient)->id && ((*ingredient)->getAuxValue() == Recipes::ANY_AUX_VALUE || item->getAuxValue() == (*ingredient)->getAuxValue()))
|
|
tempList->erase(ingredient);
|
|
}
|
|
|
|
delete tempList;
|
|
return false;
|
|
}
|
|
|
|
void ShapelessRecipy::reqs(INGREDIENTS_REQUIRED *pIngReq)
|
|
{
|
|
int iCount=0;
|
|
bool bFound;
|
|
int j;
|
|
INGREDIENTS_REQUIRED TempIngReq;
|
|
|
|
// shapeless doesn't have the 3x3 shape, but we'll just use this to store the ingredients anyway
|
|
TempIngReq.iIngC=0;
|
|
TempIngReq.iType = RECIPE_TYPE_2x2; // all the dyes can be made in a 2x2
|
|
TempIngReq.uiGridA = new unsigned int [9];
|
|
TempIngReq.iIngIDA= new int [3*3];
|
|
TempIngReq.iIngValA = new int [3*3];
|
|
TempIngReq.iIngAuxValA = new int [3*3];
|
|
|
|
ZeroMemory(TempIngReq.iIngIDA,sizeof(int)*9);
|
|
ZeroMemory(TempIngReq.iIngValA,sizeof(int)*9);
|
|
memset(TempIngReq.iIngAuxValA,Recipes::ANY_AUX_VALUE,sizeof(int)*9);
|
|
ZeroMemory(TempIngReq.uiGridA,sizeof(unsigned int)*9);
|
|
|
|
for ( ItemInstance *expected : *ingredients )
|
|
{
|
|
if ( expected )
|
|
{
|
|
int iAuxVal = expected->getAuxValue();
|
|
TempIngReq.uiGridA[iCount++]=expected->id | iAuxVal<<24;
|
|
// 4J-PB - put the ingredients in boxes 1,2,4,5 so we can see them in a 2x2 crafting screen
|
|
if(iCount==2) iCount=3;
|
|
bFound=false;
|
|
for(j=0;j<TempIngReq.iIngC;j++)
|
|
{
|
|
if((TempIngReq.iIngIDA[j]==expected->id) && (iAuxVal == Recipes::ANY_AUX_VALUE || TempIngReq.iIngAuxValA[j] == iAuxVal))
|
|
{
|
|
bFound= true;
|
|
break;
|
|
}
|
|
}
|
|
if(bFound)
|
|
{
|
|
TempIngReq.iIngValA[j]++;
|
|
}
|
|
else
|
|
{
|
|
TempIngReq.iIngIDA[TempIngReq.iIngC]=expected->id;
|
|
TempIngReq.iIngAuxValA[TempIngReq.iIngC]=iAuxVal;
|
|
TempIngReq.iIngValA[TempIngReq.iIngC++]++;
|
|
}
|
|
}
|
|
}
|
|
pIngReq->iIngIDA = new int [TempIngReq.iIngC];
|
|
pIngReq->iIngValA = new int [TempIngReq.iIngC];
|
|
pIngReq->iIngAuxValA = new int [TempIngReq.iIngC];
|
|
pIngReq->uiGridA = new unsigned int [9];
|
|
|
|
pIngReq->pRecipy=this;
|
|
|
|
for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i)
|
|
{
|
|
pIngReq->bCanMake[i]=false;
|
|
}
|
|
|
|
pIngReq->iIngC=TempIngReq.iIngC;
|
|
pIngReq->iType=TempIngReq.iType;
|
|
|
|
if(pIngReq->iIngC!=0)
|
|
{
|
|
memcpy(pIngReq->iIngIDA,TempIngReq.iIngIDA,sizeof(int)*TempIngReq.iIngC);
|
|
memcpy(pIngReq->iIngValA,TempIngReq.iIngValA,sizeof(int)*TempIngReq.iIngC);
|
|
memcpy(pIngReq->iIngAuxValA,TempIngReq.iIngAuxValA,sizeof(int)*TempIngReq.iIngC);
|
|
}
|
|
memcpy(pIngReq->uiGridA,TempIngReq.uiGridA,sizeof(unsigned int) *9);
|
|
|
|
delete [] TempIngReq.iIngIDA;
|
|
delete [] TempIngReq.iIngValA;
|
|
delete [] TempIngReq.iIngAuxValA;
|
|
delete [] TempIngReq.uiGridA;
|
|
}
|
|
|
|
void ShapelessRecipy::writeToStream(DataOutputStream* dos) {
|
|
dos->writeByte(1);
|
|
dos->writeByte(this->group);
|
|
|
|
//write result item, it should always be valid
|
|
{
|
|
dos->writeShort(this->result->id);
|
|
dos->writeByte(this->result->count);
|
|
dos->writeShort(this->result->getAuxValue());
|
|
|
|
Packet::writeNbt(this->result->tag, dos);
|
|
}
|
|
|
|
byte iCount = ingredients->size();
|
|
dos->writeByte(iCount);
|
|
|
|
for (int i = 0; i < iCount; i++) {
|
|
ItemInstance* item = (*ingredients)[i];
|
|
dos->writeBoolean(item == nullptr);
|
|
if (item == nullptr) continue;
|
|
|
|
dos->writeShort(item->id);
|
|
dos->writeShort(item->getAuxValue());
|
|
Packet::writeNbt(item->tag, dos);
|
|
}
|
|
|
|
}
|
|
|
|
ShapelessRecipy* ShapelessRecipy::readFromStream(DataInputStream* dis) {
|
|
unsigned char groupType = dis->readByte();
|
|
|
|
int resultItemID = dis->readShort();
|
|
int resultItemCount = dis->readByte();
|
|
int resultItemAux = dis->readShort();
|
|
|
|
ItemInstance* resultItem = new ItemInstance(resultItemID, resultItemCount, 0);
|
|
resultItem->setRawAuxValue(resultItemAux);
|
|
resultItem->tag = Packet::readNbt(dis);
|
|
|
|
vector<ItemInstance*>* ingredients = new vector<ItemInstance*>();
|
|
int iCount = dis->readByte();
|
|
for (int i = 0; i < iCount; i++) {
|
|
if (dis->readBoolean() == true) continue; //item is null or something weird
|
|
|
|
int itemID = dis->readShort();
|
|
int itemAux = dis->readShort();
|
|
|
|
ItemInstance* ingredients_item = new ItemInstance(itemID, 1, 0);
|
|
ingredients_item->setRawAuxValue(itemAux);
|
|
ingredients_item->tag = Packet::readNbt(dis);
|
|
|
|
ingredients->push_back(ingredients_item);
|
|
}
|
|
|
|
return new ShapelessRecipy(resultItem, ingredients, (Recipy::_eGroupType)groupType);
|
|
}
|