<commit_before>
// ItemMinecart.h

// Declares the various minecart ItemHandlers





#pragma once

// Not needed, we're being included only from ItemHandler.cpp which already has this file: #include "ItemHandler.h"
#include "../Minecart.h"





class cItemMinecartHandler :
	public cItemHandler
{
	typedef cItemHandler super;
	
public:
	cItemMinecartHandler(int a_ItemType) :
		super(a_ItemType)
	{
	}
	
	
	
	virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
	{
		if (a_Dir < 0)
		{
			return false;
		}
		
		// Check that there's rail in there:
		BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
		switch (Block)
		{
			case E_BLOCK_MINECART_TRACKS:
			case E_BLOCK_POWERED_RAIL:
			case E_BLOCK_DETECTOR_RAIL:
			{
				// These are allowed
				break;
			}
			default:
			{
				LOGD("Used minecart on an unsuitable block %d (%s)", Block, ItemTypeToString(Block).c_str());
				return false;
			}
		}
		
		double x = (double)a_BlockX + 0.5;
		double y = (double)a_BlockY + 0.5;
		double z = (double)a_BlockZ + 0.5;
		cMinecart * Minecart = NULL;
		switch (m_ItemType)
		{
			case E_ITEM_MINECART:         Minecart = new cEmptyMinecart      (x, y, z); break;
			case E_ITEM_CHEST_MINECART:   Minecart = new cMinecartWithChest  (x, y, z); break;
			case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace(x, y, z); break;
			default:
			{
				ASSERT(!"Unhandled minecart item");
				return false;
			}
		}  // switch (m_ItemType)
		a_World->AddEntity(Minecart);
		Minecart->Initialize(a_World);
		return true;
	}
	
} ;<commit_msg>Fixed crash with Minecart. It was getting added twice to the world and it was causing and ASSERT to fail.<commit_after>
// ItemMinecart.h

// Declares the various minecart ItemHandlers





#pragma once

// Not needed, we're being included only from ItemHandler.cpp which already has this file: #include "ItemHandler.h"
#include "../Minecart.h"





class cItemMinecartHandler :
	public cItemHandler
{
	typedef cItemHandler super;
	
public:
	cItemMinecartHandler(int a_ItemType) :
		super(a_ItemType)
	{
	}
	
	
	
	virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
	{
		if (a_Dir < 0)
		{
			return false;
		}
		
		// Check that there's rail in there:
		BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
		switch (Block)
		{
			case E_BLOCK_MINECART_TRACKS:
			case E_BLOCK_POWERED_RAIL:
			case E_BLOCK_DETECTOR_RAIL:
			{
				// These are allowed
				break;
			}
			default:
			{
				LOGD("Used minecart on an unsuitable block %d (%s)", Block, ItemTypeToString(Block).c_str());
				return false;
			}
		}
		
		double x = (double)a_BlockX + 0.5;
		double y = (double)a_BlockY + 0.5;
		double z = (double)a_BlockZ + 0.5;
		cMinecart * Minecart = NULL;
		switch (m_ItemType)
		{
			case E_ITEM_MINECART:         Minecart = new cEmptyMinecart      (x, y, z); break;
			case E_ITEM_CHEST_MINECART:   Minecart = new cMinecartWithChest  (x, y, z); break;
			case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace(x, y, z); break;
			default:
			{
				ASSERT(!"Unhandled minecart item");
				return false;
			}
		}  // switch (m_ItemType)
		Minecart->Initialize(a_World);
		return true;
	}
	
} ;
{'fraction_non_alphanumeric': 0.10411694510739856, 'fraction_numerical': 0.004176610978520286, 'mean_word_length': 3.3320413436692506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4794545', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1258, 'n_words': 318}