the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.inventory.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.redstone.h"
5#include "net.minecraft.world.entity.h"
6#include "net.minecraft.world.entity.item.h"
7#include "net.minecraft.world.phys.h"
8#include "net.minecraft.world.h"
9#include "DetectorRailTile.h"
10#include "net.minecraft.h"
11
12DetectorRailTile::DetectorRailTile(int id) : BaseRailTile(id, true)
13{
14 setTicking(true);
15 icons = NULL;
16}
17
18int DetectorRailTile::getTickDelay(Level *level)
19{
20 return 20;
21}
22
23bool DetectorRailTile::isSignalSource()
24{
25 return true;
26}
27
28void DetectorRailTile::entityInside(Level *level, int x, int y, int z, shared_ptr<Entity> entity)
29{
30 if (level->isClientSide)
31 {
32 return;
33 }
34
35 int data = level->getData(x, y, z);
36 if ((data & RAIL_DATA_BIT) != 0)
37 {
38 return;
39 }
40
41 checkPressed(level, x, y, z, data);
42}
43
44void DetectorRailTile::tick(Level *level, int x, int y, int z, Random *random)
45{
46 if (level->isClientSide) return;
47
48 int data = level->getData(x, y, z);
49 if ((data & RAIL_DATA_BIT) == 0)
50 {
51 return;
52 }
53
54 checkPressed(level, x, y, z, data);
55}
56
57int DetectorRailTile::getSignal(LevelSource *level, int x, int y, int z, int dir)
58{
59 return (level->getData(x, y, z) & RAIL_DATA_BIT) != 0 ? Redstone::SIGNAL_MAX : Redstone::SIGNAL_NONE;
60}
61
62int DetectorRailTile::getDirectSignal(LevelSource *level, int x, int y, int z, int facing)
63{
64 if ((level->getData(x, y, z) & RAIL_DATA_BIT) == 0) return Redstone::SIGNAL_NONE;
65 return (facing == Facing::UP) ? Redstone::SIGNAL_MAX : Redstone::SIGNAL_NONE;
66}
67
68void DetectorRailTile::checkPressed(Level *level, int x, int y, int z, int currentData)
69{
70 bool wasPressed = (currentData & RAIL_DATA_BIT) != 0;
71 bool shouldBePressed = false;
72
73 float b = 2 / 16.0f;
74 vector<shared_ptr<Entity> > *entities = level->getEntitiesOfClass(typeid(Minecart), AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b));
75 if (!entities->empty())
76 {
77 shouldBePressed = true;
78 }
79
80 if (shouldBePressed && !wasPressed)
81 {
82 level->setData(x, y, z, currentData | RAIL_DATA_BIT, Tile::UPDATE_ALL);
83 level->updateNeighborsAt(x, y, z, id);
84 level->updateNeighborsAt(x, y - 1, z, id);
85 level->setTilesDirty(x, y, z, x, y, z);
86 }
87 if (!shouldBePressed && wasPressed)
88 {
89 level->setData(x, y, z, currentData & RAIL_DIRECTION_MASK, Tile::UPDATE_ALL);
90 level->updateNeighborsAt(x, y, z, id);
91 level->updateNeighborsAt(x, y - 1, z, id);
92 level->setTilesDirty(x, y, z, x, y, z);
93 }
94
95 if (shouldBePressed)
96 {
97 level->addToTickNextTick(x, y, z, id, getTickDelay(level));
98 }
99
100 level->updateNeighbourForOutputSignal(x, y, z, id);
101
102 delete entities;
103}
104
105void DetectorRailTile::onPlace(Level *level, int x, int y, int z)
106{
107 BaseRailTile::onPlace(level, x, y, z);
108 checkPressed(level, x, y, z, level->getData(x, y, z));
109}
110
111bool DetectorRailTile::hasAnalogOutputSignal()
112{
113 return true;
114}
115
116int DetectorRailTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir)
117{
118 if ((level->getData(x, y, z) & RAIL_DATA_BIT) > 0)
119 {
120 float b = 2 / 16.0f;
121 vector<shared_ptr<Entity> > *entities = level->getEntitiesOfClass(typeid(Minecart), AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b), EntitySelector::CONTAINER_ENTITY_SELECTOR);
122
123 if (entities->size() > 0)
124 {
125 shared_ptr<Entity> out = entities->at(0);
126 delete entities;
127 return AbstractContainerMenu::getRedstoneSignalFromContainer(dynamic_pointer_cast<Container>(out));
128 }
129 }
130
131 return Redstone::SIGNAL_NONE;
132}
133
134void DetectorRailTile::registerIcons(IconRegister *iconRegister)
135{
136 icons = new Icon*[2];
137 icons[0] = iconRegister->registerIcon(L"detectorRail");
138 icons[1] = iconRegister->registerIcon(L"detectorRail_on");
139}
140
141Icon *DetectorRailTile::getTexture(int face, int data)
142{
143 if ((data & RAIL_DATA_BIT) != 0)
144 {
145 return icons[1];
146 }
147 return icons[0];
148}