use of mekanism.common.lib.multiblock.Structure in project Mekanism by mekanism.
the class TileEntityStructuralMultiblock method onActivate.
@Override
public ActionResultType onActivate(PlayerEntity player, Hand hand, ItemStack stack) {
for (Map.Entry<MultiblockManager<?>, Structure> entry : structures.entrySet()) {
Structure structure = entry.getValue();
IMultiblock<?> master = structure.getController();
if (master != null) {
MultiblockData data = getMultiblockData(structure);
if (data.isFormed() && structuralGuiAccessAllowed(entry.getKey().getNameLower())) {
// make sure this block is on the structure first
if (data.getBounds().getRelativeLocation(getBlockPos()).isWall()) {
return master.onActivate(player, hand, stack);
}
}
}
}
return ActionResultType.PASS;
}
use of mekanism.common.lib.multiblock.Structure in project Mekanism by mekanism.
the class TileEntityStructuralMultiblock method onUpdateServer.
@Override
protected void onUpdateServer() {
super.onUpdateServer();
if (ticker % 10 == 0) {
String activeMultiblock = null;
if (!structures.isEmpty()) {
Iterator<Map.Entry<MultiblockManager<?>, Structure>> iterator = structures.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<MultiblockManager<?>, Structure> entry = iterator.next();
Structure structure = entry.getValue();
if (structure.isValid()) {
if (activeMultiblock == null && structure.getController() != null && getMultiblockData(structure).isFormed()) {
activeMultiblock = entry.getKey().getNameLower();
}
} else {
iterator.remove();
}
}
}
if (ticker >= 3 && structures.isEmpty()) {
invalidStructure.tick(this, true);
// If we managed to find any structures check which one is active
for (Map.Entry<MultiblockManager<?>, Structure> entry : structures.entrySet()) {
Structure structure = entry.getValue();
if (structure.getController() != null && getMultiblockData(structure).isFormed()) {
activeMultiblock = entry.getKey().getNameLower();
break;
}
}
}
// this could potentially fail if this structural multiblock tracks multiple structures, but 99.99% of the time this will be accurate
if (!Objects.equals(activeMultiblock, clientActiveMultiblock)) {
clientActiveMultiblock = activeMultiblock;
sendUpdatePacket();
}
}
}
Aggregations