use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class SkaianetHandler method getComputer.
/**
* Gets the <code>TileEntityComputer</code> at the given position.
* @param data A <code>ComputerData</code> representing the computer,
* this method does not compare the variable <code>data.owner</code>.
* @return The <code>TileEntityComputer</code> at the given position,
* or <code>null</code> if there isn't one there.
*/
public static TileEntityComputer getComputer(ComputerData data) {
if (data == null)
return null;
World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(data.dimension);
if (world == null)
return null;
TileEntity te = world.getTileEntity(new BlockPos(data.x, data.y, data.z));
if (te == null || !(te instanceof TileEntityComputer))
return null;
else
return (TileEntityComputer) te;
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class SkaianetHandler method checkData.
private static void checkData() {
Iterator<PlayerIdentifier> iter0 = infoToSend.keySet().iterator();
while (iter0.hasNext()) if (iter0.next().getPlayer() == null) {
// Debug.print("[SKAIANET] Player disconnected, removing data.");
iter0.remove();
}
@SuppressWarnings("unchecked") Iterator<ComputerData>[] iter1 = new Iterator[] { serversOpen.values().iterator(), resumingClients.values().iterator(), resumingServers.values().iterator() };
for (Iterator<ComputerData> i : iter1) while (i.hasNext()) {
ComputerData data = i.next();
if (getComputer(data) == null || data.dimension == -1 || !getComputer(data).owner.equals(data.owner) || !(i == iter1[1] && getComputer(data).getData(0).getBoolean("isResuming") || i != iter1[1] && getComputer(data).getData(1).getBoolean("isOpen"))) {
Debug.warn("[SKAIANET] Invalid computer in waiting list!");
i.remove();
}
}
Iterator<SburbConnection> iter2 = connections.iterator();
while (iter2.hasNext()) {
SburbConnection c = iter2.next();
if (c.getClientIdentifier() == null || c.getServerIdentifier() == null) {
Debug.warn("Found a broken connection with the client \"" + c.getClientIdentifier() + "\" and server \"" + c.getServerIdentifier() + ". If this message continues to show up, something isn't working as it should.");
iter2.remove();
continue;
}
if (c.isActive) {
TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
if (cc == null || sc == null || c.client.dimension == -1 || c.server.dimension == -1 || !c.getClientIdentifier().equals(cc.owner) || !c.getServerIdentifier().equals(sc.owner) || !cc.getData(0).getBoolean("connectedToServer")) {
Debug.warnf("[SKAIANET] Invalid computer in connection between %s and %s.", c.getClientIdentifier(), c.getServerIdentifier());
if (!c.isMain)
iter2.remove();
else
c.isActive = false;
SessionHandler.onConnectionClosed(c, true);
ServerEditHandler.onDisconnect(c);
if (cc != null) {
cc.getData(0).setBoolean("connectedToServer", false);
cc.latestmessage.put(0, "computer.messageClosed");
cc.markBlockForUpdate();
} else if (sc != null) {
sc.latestmessage.put(1, "computer.messageClosed");
sc.markBlockForUpdate();
}
}
if (// If the center location isn't defined
cc != null && c.enteredGame && c.inventory == null && c.centerX == 0 && c.centerZ == 0) {
c.centerX = cc.getPos().getX();
c.centerZ = cc.getPos().getZ();
c.inventory = new NBTTagList();
}
if (cc != null && c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand))
c.clientHomeLand = c.client.dimension;
}
if (c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
EntityPlayerMP player = c.getClientIdentifier().getPlayer();
if (player != null) {
c.clientHomeLand = player.dimension;
if (!MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
iter2.remove();
SessionHandler.onConnectionClosed(c, false);
if (c.isActive) {
TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
cc.getData(0).setBoolean("connectedToServer", false);
cc.latestmessage.put(0, "computer.messageClosed");
cc.markBlockForUpdate();
sc.getData(1).setString("connectedClient", "");
sc.latestmessage.put(1, "computer.messageClosed");
sc.markBlockForUpdate();
}
}
}
}
}
if (MinestuckConfig.privateComputers) {
for (Entry<PlayerIdentifier, PlayerIdentifier[]> entry : infoToSend.entrySet()) {
EntityPlayerMP player = entry.getKey().getPlayer();
UserListOpsEntry opsEntry = player == null ? null : player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
if (opsEntry != null && opsEntry.getPermissionLevel() >= 2)
continue;
for (int i = 0; i < entry.getValue().length; i++) if (entry.getValue()[i] != null && !entry.getValue()[i].equals(entry.getKey()))
entry.getValue()[i] = null;
}
}
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class BlockComputerOn method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntityComputer tileEntity = (TileEntityComputer) worldIn.getTileEntity(pos);
if (tileEntity == null || playerIn.isSneaking()) {
return false;
}
int id = ComputerProgram.getProgramID(playerIn.getHeldItem(hand));
if (id != -2 && !tileEntity.hasProgram(id) && tileEntity.installedPrograms.size() < 2 && !tileEntity.hasProgram(-1)) {
if (worldIn.isRemote)
return true;
playerIn.setHeldItem(hand, ItemStack.EMPTY);
if (id == -1) {
tileEntity.closeAll();
worldIn.setBlockState(pos, state.withProperty(BSOD, true), 2);
} else
tileEntity.installedPrograms.put(id, true);
tileEntity.markDirty();
worldIn.notifyBlockUpdate(pos, state, state, 3);
return true;
}
if (worldIn.isRemote && SkaiaClient.requestData(tileEntity))
playerIn.openGui(Minestuck.instance, GuiHandler.GuiId.COMPUTER.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class BlockComputerOn method dropItems.
private void dropItems(World world, int x, int y, int z, IBlockState state) {
Random rand = new Random();
TileEntityComputer te = (TileEntityComputer) world.getTileEntity(new BlockPos(x, y, z));
if (te == null) {
return;
}
te.closeAll();
float factor = 0.05F;
Iterator<Entry<Integer, Boolean>> it = te.installedPrograms.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, Boolean> pairs = it.next();
if (!pairs.getValue())
continue;
int program = pairs.getKey();
float rx = rand.nextFloat() * 0.8F + 0.1F;
float ry = rand.nextFloat() * 0.8F + 0.1F;
float rz = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, ComputerProgram.getItem(program));
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
}
if (state.getValue(BSOD)) {
float rx = rand.nextFloat() * 0.8F + 0.1F;
float ry = rand.nextFloat() * 0.8F + 0.1F;
float rz = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, ComputerProgram.getItem(-1));
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
}
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class SkaianetHandler method connectTo.
private static void connectTo(ComputerData player, boolean isClient, PlayerIdentifier otherPlayer, Map<PlayerIdentifier, ComputerData> map) {
TileEntityComputer c1 = getComputer(player), c2 = getComputer(map.get(otherPlayer));
if (c2 == null) {
// Invalid, should not be in the list
map.remove(otherPlayer);
return;
}
if (c1 == null)
return;
SburbConnection c;
// True if new, false if resuming.
boolean newConnection = false;
if (isClient) {
c = getConnection(player.owner, otherPlayer);
if (c == null) {
c = new SburbConnection();
connections.add(c);
newConnection = true;
}
c.client = player;
c.server = map.remove(otherPlayer);
c.isActive = true;
} else {
c = getConnection(otherPlayer, player.owner);
if (c == null)
// A server should only be able to resume
return;
c.client = map.remove(otherPlayer);
c.server = player;
c.isActive = true;
}
if (newConnection) {
SburbConnection conn = getMainConnection(c.getClientIdentifier(), true);
if (conn != null && conn.getServerIdentifier().equals(IdentifierHandler.nullIdentifier) && getMainConnection(c.getServerIdentifier(), false) == null) {
connections.remove(c);
conn.client = c.client;
conn.server = c.server;
conn.serverIdentifier = c.getServerIdentifier();
conn.isActive = true;
c = conn;
} else {
String s = SessionHandler.onConnectionCreated(c);
if (s != null) {
Debug.warnf("SessionHandler denied connection between %s and %s, reason: %s", c.getClientIdentifier().getUsername(), c.getServerIdentifier().getUsername(), s);
connections.remove(c);
TileEntityComputer cte = getComputer(c.client);
if (cte != null)
cte.latestmessage.put(0, s);
map.put(c.server.owner, c.server);
return;
}
SburbHandler.onConnectionCreated(c);
if (conn != null) {
c.enteredGame = conn.enteredGame;
c.canSplit = conn.canSplit;
c.centerX = conn.centerX;
c.centerZ = conn.centerZ;
c.clientHomeLand = conn.clientHomeLand;
c.artifactType = conn.artifactType;
if (c.inventory != null)
c.inventory = (NBTTagList) conn.inventory.copy();
}
}
}
c1.connected(otherPlayer, isClient);
c2.connected(player.owner, !isClient);
if (c1 != c2)
c2.markBlockForUpdate();
}
Aggregations