the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 148 lines 4.0 kB view raw
1#include "stdafx.h" 2#include "FenceGateTile.h" 3#include "AABB.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.h" 6#include "LevelEvent.h" 7 8FenceGateTile::FenceGateTile(int id) : DirectionalTile(id, Material::wood, isSolidRender() ) 9{ 10} 11 12Icon *FenceGateTile::getTexture(int face, int data) 13{ 14 return Tile::wood->getTexture(face); 15} 16 17bool FenceGateTile::mayPlace(Level *level, int x, int y, int z) 18{ 19 if (!level->getMaterial(x, y - 1, z)->isSolid()) return false; 20 return Tile::mayPlace(level, x, y, z); 21} 22 23AABB *FenceGateTile::getAABB(Level *level, int x, int y, int z) 24{ 25 int data = level->getData(x, y, z); 26 if (isOpen(data)) 27 { 28 return NULL; 29 } 30 // 4J Brought forward change from 1.2.3 to fix hit box rotation 31 if (data == Direction::NORTH || data == Direction::SOUTH) 32 { 33 return AABB::newTemp(x, y, z + 6.0f / 16.0f, x + 1, y + 1.5f, z + 10.0f / 16.0f); 34 } 35 return AABB::newTemp(x + 6.0f / 16.0f, y, z, x + 10.0f / 16.0f, y + 1.5f, z + 1); 36 //return AABB::newTemp(x, y, z, x + 1, y + 1.5f, z + 1); 37} 38 39// 4J - Brought forward from 1.2.3 to fix hit box rotation 40void FenceGateTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 41{ 42 int data = getDirection(level->getData(x, y, z)); 43 if (data == Direction::NORTH || data == Direction::SOUTH) 44 { 45 setShape(0, 0, 6.0f / 16.0f, 1, 1.0f, 10.0f / 16.0f); 46 } 47 else 48 { 49 setShape(6.0f / 16.0f, 0, 0, 10.0f / 16.0f, 1.0f, 1); 50 } 51} 52 53bool FenceGateTile::blocksLight() 54{ 55 return false; 56} 57 58bool FenceGateTile::isSolidRender(bool isServerLevel) 59{ 60 return false; 61} 62 63bool FenceGateTile::isCubeShaped() 64{ 65 return false; 66} 67 68bool FenceGateTile::isPathfindable(LevelSource *level, int x, int y, int z) 69{ 70 return isOpen(level->getData(x, y, z)); 71} 72 73int FenceGateTile::getRenderShape() 74{ 75 return Tile::SHAPE_FENCE_GATE; 76} 77 78void FenceGateTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 79{ 80 int dir = (((Mth::floor(by->yRot * 4 / (360) + 0.5)) & 3)) % 4; 81 level->setData(x, y, z, dir, Tile::UPDATE_CLIENTS); 82} 83 84bool FenceGateTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param 85{ 86 if (soundOnly) 87 { 88 // 4J - added - just do enough to play the sound 89 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); // 4J - changed event to pass player rather than NULL as the source of the event so we can filter the broadcast properly 90 return false; 91 } 92 93 int data = level->getData(x, y, z); 94 if (isOpen(data)) 95 { 96 level->setData(x, y, z, data & ~OPEN_BIT, Tile::UPDATE_CLIENTS); 97 } 98 else 99 { 100 // open the door from the player 101 int dir = (((Mth::floor(player->yRot * 4 / (360) + 0.5)) & 3)) % 4; 102 int current = getDirection(data); 103 if (current == ((dir + 2) % 4)) 104 { 105 data = dir; 106 } 107 level->setData(x, y, z, data | OPEN_BIT, Tile::UPDATE_CLIENTS); 108 } 109 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 110 return true; 111} 112 113void FenceGateTile::neighborChanged(Level *level, int x, int y, int z, int type) 114{ 115 if (level->isClientSide) return; 116 117 int data = level->getData(x, y, z); 118 119 bool signal = level->hasNeighborSignal(x, y, z); 120 if (signal || ((type > 0 && Tile::tiles[type]->isSignalSource()) || type == 0)) 121 { 122 if (signal && !isOpen(data)) 123 { 124 level->setData(x, y, z, data | OPEN_BIT, Tile::UPDATE_CLIENTS); 125 level->levelEvent(nullptr, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 126 } 127 else if (!signal && isOpen(data)) 128 { 129 level->setData(x, y, z, data & ~OPEN_BIT, Tile::UPDATE_CLIENTS); 130 level->levelEvent(nullptr, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 131 } 132 } 133} 134 135bool FenceGateTile::isOpen(int data) 136{ 137 return (data & OPEN_BIT) != 0; 138} 139 140void FenceGateTile::registerIcons(IconRegister *iconRegister) 141{ 142 // None 143} 144 145bool FenceGateTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) 146{ 147 return true; 148}