mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 21:19:44 +00:00
some random stuff
This commit is contained in:
parent
62b846e673
commit
a38c1c109c
5 changed files with 88 additions and 57 deletions
116
src/Player.php
116
src/Player.php
|
|
@ -2461,55 +2461,30 @@ class Player{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->lastCraft <= (microtime(true) - 1)){
|
if($packet->windowid === 0){ //crafting
|
||||||
if(isset($this->toCraft[-1])){
|
|
||||||
$this->toCraft = [-1 => $this->toCraft[-1]];
|
|
||||||
}else{
|
|
||||||
$this->toCraft = [];
|
|
||||||
}
|
|
||||||
$this->craftingItems = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($packet->windowid === 0){
|
|
||||||
$craft = false;
|
|
||||||
$slot = $this->getSlot($packet->slot);
|
$slot = $this->getSlot($packet->slot);
|
||||||
|
$citem = $packet->item;
|
||||||
if($slot->count >= $packet->item->count && (($slot->getID() === $packet->item->getID() && $slot->getMetadata() === $packet->item->getMetadata()) || ($packet->item->getID() === AIR && $packet->item->count === 0)) && !isset($this->craftingItems[$packet->slot])){ //Crafting recipe
|
if($slot->getID() == $citem->getID() && $slot->getMetadata() == $citem->getMetadata()){
|
||||||
if(!isset($this->toCraft[-1])) $this->toCraft[-1] = 0;
|
if($citem->count > $slot->count){ //item added, result
|
||||||
$use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $packet->item->count);
|
$this->addCraftingResult($slot->getID(), $slot->getMetadata(), $citem->count - $slot->count);
|
||||||
$this->craftingItems[$packet->slot] = $use;
|
}else if($citem->count < $slot->count){ //item removed, ingridient
|
||||||
$craft = true;
|
$this->addCraftingIngridient($slot->getID(), $slot->getMetadata(), $slot->count - $citem->count);
|
||||||
}elseif($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final
|
}else{
|
||||||
$craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count - $slot->count);
|
//item synchronized
|
||||||
if(count($this->toCraft) === 0){
|
|
||||||
$this->toCraft[-1] = 0;
|
|
||||||
}
|
}
|
||||||
$this->toCraft[$packet->slot] = $craftItem;
|
}else if($citem->getID() == 0 && $slot->getID() > 0){ //client sent air, server has not air, ingridient
|
||||||
$craft = true;
|
$this->addCraftingIngridient($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||||
}elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final
|
}else if($slot->getID() == 0 && $citem->getID() > 0){ //client sent non-air, server has air, result
|
||||||
$craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count);
|
$this->addCraftingResult($citem->getID(), $citem->getMetadata(), $citem->count);
|
||||||
if(count($this->toCraft) === 0){
|
}else{
|
||||||
$this->toCraft[-1] = 0;
|
|
||||||
}
|
|
||||||
$use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count);
|
|
||||||
$this->craftingItems[$packet->slot] = $use;
|
|
||||||
$this->toCraft[$packet->slot] = $craftItem;
|
|
||||||
$craft = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($craft === true){
|
|
||||||
$this->lastCraft = microtime(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($craft === true and count($this->craftingItems) > 0 and count($this->toCraft) > 0 and ($recipe = $this->craftItems($this->toCraft, $this->craftingItems, $this->toCraft[-1])) !== true){
|
|
||||||
if($recipe === false){
|
|
||||||
$this->sendInventory();
|
$this->sendInventory();
|
||||||
$this->toCraft = [];
|
$this->toCraft = [];
|
||||||
}else{
|
|
||||||
$this->toCraft = [-1 => $this->toCraft[-1]];
|
|
||||||
}
|
|
||||||
$this->craftingItems = [];
|
$this->craftingItems = [];
|
||||||
|
ConsoleAPI::warn("{$this->username} tried modifying inventory<?>! Server item: $slot({$slot->count}), Client item: $citem({$citem->count})");
|
||||||
|
$this->sendChat("[NC] Haxxor(or bug?).");
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
$this->toCraft = [];
|
$this->toCraft = [];
|
||||||
$this->craftingItems = [];
|
$this->craftingItems = [];
|
||||||
|
|
@ -2697,6 +2672,63 @@ class Player{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public $craftingType = 0;
|
||||||
|
public function tryCraft(){
|
||||||
|
if(count($this->toCraft) <= 0 || count($this->craftingItems) <= 0) return;
|
||||||
|
|
||||||
|
if(count($this->toCraft) > 1){
|
||||||
|
ConsoleAPI::warn("Trying to craft more than 1 item, not supported for now.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach($this->toCraft as $i => $e){
|
||||||
|
$toCraft = [$i >> 8, $i & 0xff, $e];
|
||||||
|
}
|
||||||
|
$ingridients = [];
|
||||||
|
foreach($this->craftingItems as $i => $e){
|
||||||
|
$ingridients[$i >> 8] = [$i >> 8, $i & 0xff, $e];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$cc = CraftingRecipes::canCraft($toCraft, $ingridients, $this->craftingType);
|
||||||
|
if(!is_array($cc) && $this->craftingType == CraftingRecipes::TYPE_CRAFTIGTABLE){
|
||||||
|
$cc = CraftingRecipes::canCraft($toCraft, $ingridients, CraftingRecipes::TYPE_INVENTORY);
|
||||||
|
if(!is_array($cc)){
|
||||||
|
return; //recipe not found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var_dump($cc);
|
||||||
|
$this->addItem($toCraft[0], $toCraft[1], $toCraft[2], false);
|
||||||
|
foreach($ingridients as [$id, $meta, $count]){
|
||||||
|
$this->removeItem($id, $meta, $count, false);
|
||||||
|
}
|
||||||
|
$this->sendInventory();
|
||||||
|
$this->toCraft = [];
|
||||||
|
$this->craftingItems = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCraftingResult($id, $meta, $count){
|
||||||
|
$index = ($id << 8) | $meta;
|
||||||
|
|
||||||
|
if(!isset($this->toCraft[$index])) $this->toCraft[$index] = 0;
|
||||||
|
$this->toCraft[$index] += $count;
|
||||||
|
console("Result: $id, $meta, $count");
|
||||||
|
if($this->tryCraft() === false){
|
||||||
|
$this->sendInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCraftingIngridient($id, $meta, $count){
|
||||||
|
$index = ($id << 8) | $meta;
|
||||||
|
|
||||||
|
if(!isset($this->craftingItems[$index])) $this->craftingItems[$index] = 0;
|
||||||
|
$this->craftingItems[$index] += $count;
|
||||||
|
console("Ingridient: $id, $meta, $count");
|
||||||
|
if($this->tryCraft() === false){
|
||||||
|
$this->sendInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function hasItem($type, $damage = false){
|
public function hasItem($type, $damage = false){
|
||||||
foreach($this->inventory as $s => $item){
|
foreach($this->inventory as $s => $item){
|
||||||
if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0){
|
if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0){
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class PocketMinecraftServer{
|
||||||
|
|
||||||
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
||||||
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
|
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
|
||||||
|
public static $EXPERIMENTAL_INVENTORY = true;
|
||||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||||
$this->port = (int) $port;
|
$this->port = (int) $port;
|
||||||
$this->doTick = true;
|
$this->doTick = true;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class StonecutterBlock extends SolidBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
$player->toCraft[-1] = 2;
|
$player->craftingType = CraftingRecipes::TYPE_STONECUTTER;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class WorkbenchBlock extends SolidBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
$player->toCraft[-1] = 1;
|
$player->craftingType = CraftingRecipes::TYPE_CRAFTIGTABLE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class CraftingRecipes{
|
class CraftingRecipes{
|
||||||
|
const TYPE_INVENTORY = 0;
|
||||||
|
const TYPE_CRAFTIGTABLE = 1;
|
||||||
|
const TYPE_STONECUTTER = 2;
|
||||||
|
|
||||||
private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better!
|
private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better!
|
||||||
// Building
|
// Building
|
||||||
|
|
@ -204,19 +207,19 @@ class CraftingRecipes{
|
||||||
$id = 1;
|
$id = 1;
|
||||||
foreach(CraftingRecipes::$small as $recipe){
|
foreach(CraftingRecipes::$small as $recipe){
|
||||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||||
$recipe[3] = 0; //Type
|
$recipe[3] = self::TYPE_INVENTORY; //Type
|
||||||
CraftingRecipes::$recipes[$id] = $recipe;
|
CraftingRecipes::$recipes[$id] = $recipe;
|
||||||
++$id;
|
++$id;
|
||||||
}
|
}
|
||||||
foreach(CraftingRecipes::$big as $recipe){
|
foreach(CraftingRecipes::$big as $recipe){
|
||||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||||
$recipe[3] = 1;
|
$recipe[3] = self::TYPE_CRAFTIGTABLE;
|
||||||
CraftingRecipes::$recipes[$id] = $recipe;
|
CraftingRecipes::$recipes[$id] = $recipe;
|
||||||
++$id;
|
++$id;
|
||||||
}
|
}
|
||||||
foreach(CraftingRecipes::$stone as $recipe){
|
foreach(CraftingRecipes::$stone as $recipe){
|
||||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||||
$recipe[3] = 2;
|
$recipe[3] = self::TYPE_STONECUTTER;
|
||||||
CraftingRecipes::$recipes[$id] = $recipe;
|
CraftingRecipes::$recipes[$id] = $recipe;
|
||||||
++$id;
|
++$id;
|
||||||
}
|
}
|
||||||
|
|
@ -268,9 +271,6 @@ class CraftingRecipes{
|
||||||
ksort($recipeItems);
|
ksort($recipeItems);
|
||||||
$recipeString = "";
|
$recipeString = "";
|
||||||
foreach($recipeItems as $item){
|
foreach($recipeItems as $item){
|
||||||
if($craftItem[0] === CAKE && $item[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal
|
|
||||||
$item[2] = 3;
|
|
||||||
}
|
|
||||||
$recipeString .= $item[0] . "x" . $item[2] . ",";
|
$recipeString .= $item[0] . "x" . $item[2] . ",";
|
||||||
}
|
}
|
||||||
$recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2];
|
$recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2];
|
||||||
|
|
@ -287,9 +287,7 @@ class CraftingRecipes{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$oitem = $recipeItems[$item[0]];
|
$oitem = $recipeItems[$item[0]];
|
||||||
if($craftItem[0] === CAKE && $oitem[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal x2
|
|
||||||
$oitem[2] = 3;
|
|
||||||
}
|
|
||||||
if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]){
|
if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]){
|
||||||
$continue = false;
|
$continue = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue