the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 128 lines 3.0 kB view raw
1#include "stdafx.h" 2#include "CreativeMode.h" 3#include "User.h" 4#include "LocalPlayer.h" 5#include "..\Minecraft.World\\net.minecraft.world.entity.player.h" 6#include "..\Minecraft.World\net.minecraft.world.item.h" 7#include "..\Minecraft.World\net.minecraft.world.inventory.h" 8#include "..\Minecraft.World\net.minecraft.world.level.h" 9#include "..\Minecraft.World\net.minecraft.world.level.tile.h" 10 11CreativeMode::CreativeMode(Minecraft *minecraft) : GameMode(minecraft) 12{ 13 destroyDelay = 0; 14 instaBuild = true; 15} 16 17void CreativeMode::init() 18{ 19 // initPlayer(); 20} 21 22void CreativeMode::enableCreativeForPlayer(shared_ptr<Player> player) 23{ 24 // please check ServerPlayerGameMode.java if you change these 25 player->abilities.mayfly = true; 26 player->abilities.instabuild = true; 27 player->abilities.invulnerable = true; 28} 29 30void CreativeMode::disableCreativeForPlayer(shared_ptr<Player> player) 31{ 32 player->abilities.mayfly = false; 33 player->abilities.flying = false; 34 player->abilities.instabuild = false; 35 player->abilities.invulnerable = false; 36} 37 38void CreativeMode::adjustPlayer(shared_ptr<Player> player) 39{ 40 enableCreativeForPlayer(player); 41 42 for (int i = 0; i < 9; i++) 43 { 44 if (player->inventory->items[i] == NULL) 45 { 46 player->inventory->items[i] = shared_ptr<ItemInstance>( new ItemInstance(User::allowedTiles[i]) ); 47 } 48 else 49 { 50 // 4J-PB - this line is commented out in 1.0.1 51 //player->inventory->items[i]->count = 1; 52 } 53 } 54} 55 56void CreativeMode::creativeDestroyBlock(Minecraft *minecraft, GameMode *gameMode, int x, int y, int z, int face) 57{ 58 if(!minecraft->level->extinguishFire(minecraft->player, x, y, z, face)) 59 { 60 gameMode->destroyBlock(x, y, z, face); 61 } 62} 63 64bool CreativeMode::useItemOn(shared_ptr<Player> player, Level *level, shared_ptr<ItemInstance> item, int x, int y, int z, int face, bool bTestUseOnOnly, bool *pbUsedItem) 65{ 66 int t = level->getTile(x, y, z); 67 if (t > 0) 68 { 69 if (Tile::tiles[t]->use(level, x, y, z, player)) return true; 70 } 71 if (item == NULL) return false; 72 int aux = item->getAuxValue(); 73 int count = item->count; 74 bool success = item->useOn(player, level, x, y, z, face); 75 item->setAuxValue(aux); 76 item->count = count; 77 return success; 78} 79 80void CreativeMode::startDestroyBlock(int x, int y, int z, int face) 81{ 82 creativeDestroyBlock(minecraft, this, x, y, z, face); 83 destroyDelay = 5; 84} 85 86void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) 87{ 88 destroyDelay--; 89 if (destroyDelay <= 0) 90 { 91 destroyDelay = 5; 92 creativeDestroyBlock(minecraft, this, x, y, z, face); 93 } 94} 95 96void CreativeMode::stopDestroyBlock() 97{ 98} 99 100bool CreativeMode::canHurtPlayer() 101{ 102 return false; 103} 104 105void CreativeMode::initLevel(Level *level) 106{ 107 GameMode::initLevel(level); 108} 109 110float CreativeMode::getPickRange() 111{ 112 return 5.0f; 113} 114 115bool CreativeMode::hasMissTime() 116{ 117 return false; 118} 119 120bool CreativeMode::hasInfiniteItems() 121{ 122 return true; 123} 124 125bool CreativeMode::hasFarPickRange() 126{ 127 return true; 128}