aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/CreativeMode.cpp
blob: 48342ebc10c1bf01f41f5516d4ef70f2da3b8154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdafx.h"
#include "CreativeMode.h"
#include "User.h"
#include "LocalPlayer.h"
#include "..\Minecraft.World\\net.minecraft.world.entity.player.h"
#include "..\Minecraft.World\net.minecraft.world.item.h"
#include "..\Minecraft.World\net.minecraft.world.inventory.h"
#include "..\Minecraft.World\net.minecraft.world.level.h"
#include "..\Minecraft.World\net.minecraft.world.level.tile.h"

CreativeMode::CreativeMode(Minecraft *minecraft) : GameMode(minecraft)
{
	destroyDelay = 0;
	instaBuild = true;
}

void CreativeMode::init()
{
	// initPlayer();
}

void CreativeMode::enableCreativeForPlayer(shared_ptr<Player> player)
{
	// please check ServerPlayerGameMode.java if you change these
	player->abilities.mayfly = true;
	player->abilities.instabuild = true;
	player->abilities.invulnerable = true;
}

void CreativeMode::disableCreativeForPlayer(shared_ptr<Player> player)
{
	player->abilities.mayfly = false;
	player->abilities.flying = false;
	player->abilities.instabuild = false;
	player->abilities.invulnerable = false;
}

void CreativeMode::adjustPlayer(shared_ptr<Player> player)
{
	enableCreativeForPlayer(player);

    for (int i = 0; i < 9; i++)
	{
        if (player->inventory->items[i] == NULL)
		{
            player->inventory->items[i] = shared_ptr<ItemInstance>( new ItemInstance(User::allowedTiles[i]) );
        }
		else
		{
			// 4J-PB - this line is commented out in 1.0.1
            //player->inventory->items[i]->count = 1;
        }
    }
}

void CreativeMode::creativeDestroyBlock(Minecraft *minecraft, GameMode *gameMode, int x, int y, int z, int face)
{
	if(!minecraft->level->extinguishFire(minecraft->player, x, y, z, face))
	{
		gameMode->destroyBlock(x, y, z, face);
	}
}

bool CreativeMode::useItemOn(shared_ptr<Player> player, Level *level, shared_ptr<ItemInstance> item, int x, int y, int z, int face, bool bTestUseOnOnly, bool *pbUsedItem)
{
	int t = level->getTile(x, y, z);
	if (t > 0)
	{
		if (Tile::tiles[t]->use(level, x, y, z, player)) return true;
	}
	if (item == NULL) return false;
	int aux = item->getAuxValue();
	int count = item->count;
	bool success = item->useOn(player, level, x, y, z, face);
	item->setAuxValue(aux);
	item->count = count;
	return success;
}

void CreativeMode::startDestroyBlock(int x, int y, int z, int face)
{
	creativeDestroyBlock(minecraft, this, x, y, z, face);
	destroyDelay = 5;
}

void CreativeMode::continueDestroyBlock(int x, int y, int z, int face)
{
	destroyDelay--;
	if (destroyDelay <= 0)
	{
		destroyDelay = 5;
		creativeDestroyBlock(minecraft, this, x, y, z, face);
	}
}

void CreativeMode::stopDestroyBlock()
{
}

bool CreativeMode::canHurtPlayer()
{
	return false;
}

void CreativeMode::initLevel(Level *level)
{
	GameMode::initLevel(level);
}

float CreativeMode::getPickRange()
{
	return 5.0f;
}

bool CreativeMode::hasMissTime()
{
	return false;
}

bool CreativeMode::hasInfiniteItems()
{
	return true;
}

bool CreativeMode::hasFarPickRange()
{
	return true;
}