use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class SkaianetHandler method requestConnection.
public static void requestConnection(ComputerData player, PlayerIdentifier otherPlayer, boolean isClient) {
if (player.dimension == -1)
return;
TileEntityComputer te = getComputer(player);
if (te == null)
return;
if (// Is server
!isClient) {
if (serversOpen.containsKey(player.owner) || resumingServers.containsKey(player.owner))
return;
if (// Wants to open
otherPlayer == null) {
if (resumingClients.containsKey(getAssociatedPartner(player.owner, false)))
connectTo(player, false, getAssociatedPartner(player.owner, false), resumingClients);
else {
te.getData(1).setBoolean("isOpen", true);
serversOpen.put(player.owner, player);
}
} else if (// Wants to resume
otherPlayer != null && getAssociatedPartner(player.owner, false).equals(otherPlayer)) {
if (// The client is already waiting
resumingClients.containsKey(otherPlayer))
connectTo(player, false, otherPlayer, resumingClients);
else // Client is not currently trying to resume
{
te.getData(1).setBoolean("isOpen", true);
resumingServers.put(player.owner, player);
}
} else
return;
} else // Is client
{
if (getClientConnection(player.owner) != null || resumingClients.containsKey(player.owner))
return;
PlayerIdentifier p = getAssociatedPartner(player.owner, true);
if (// If trying to connect to the associated partner
p != null && (otherPlayer == null || p.equals(otherPlayer))) {
if (// If server is "resuming".
resumingServers.containsKey(p))
connectTo(player, true, p, resumingServers);
else if (// If server is normally open.
serversOpen.containsKey(p))
connectTo(player, true, p, serversOpen);
else // If server isn't open
{
te.getData(0).setBoolean("isResuming", true);
resumingClients.put(player.owner, player);
}
} else if (// If the server is open.
serversOpen.containsKey(otherPlayer))
connectTo(player, true, otherPlayer, serversOpen);
}
te.markBlockForUpdate();
updateAll();
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class SkaianetHandler method closeConnection.
public static void closeConnection(PlayerIdentifier player, PlayerIdentifier otherPlayer, boolean isClient) {
if (otherPlayer == null) {
if (isClient) {
if (movingComputers.contains(resumingClients.get(player)))
return;
TileEntityComputer te = getComputer(resumingClients.remove(player));
if (te != null) {
te.getData(0).setBoolean("isResuming", false);
te.latestmessage.put(0, "computer.messageResumeStop");
te.markBlockForUpdate();
}
} else if (serversOpen.containsKey(player)) {
if (movingComputers.contains(serversOpen.get(player)))
return;
TileEntityComputer te = getComputer(serversOpen.remove(player));
if (te != null) {
te.getData(1).setBoolean("isOpen", false);
te.latestmessage.put(1, "computer.messageClosedServer");
te.markBlockForUpdate();
}
} else if (resumingServers.containsKey(player)) {
if (movingComputers.contains(resumingServers.get(player)))
return;
TileEntityComputer te = getComputer(resumingServers.remove(player));
if (te != null) {
te.getData(1).setBoolean("isOpen", false);
te.latestmessage.put(1, "computer.messageResumeStop");
te.markBlockForUpdate();
}
} else
Debug.warn("[SKAIANET] Got disconnect request but server is not open! " + player);
} else {
SburbConnection c = isClient ? getConnection(player, otherPlayer) : getConnection(otherPlayer, player);
if (c != null) {
if (c.isActive) {
if (movingComputers.contains(isClient ? c.client : c.server))
return;
TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
if (cc != null) {
cc.getData(0).setBoolean("connectedToServer", false);
cc.latestmessage.put(0, "computer.messageClosed");
cc.markBlockForUpdate();
}
if (sc != null) {
sc.getData(1).setString("connectedClient", "");
sc.latestmessage.put(1, "computer.messageClosed");
sc.markBlockForUpdate();
}
SessionHandler.onConnectionClosed(c, true);
ServerEditHandler.onDisconnect(c);
if (c.isMain)
// That's everything that is neccesary.
c.isActive = false;
else
connections.remove(c);
} else if (getAssociatedPartner(player, isClient).equals(otherPlayer)) {
if (movingComputers.contains(isClient ? resumingClients.get(player) : resumingServers.get(player)))
return;
TileEntityComputer te = getComputer(isClient ? resumingClients.remove(player) : resumingServers.remove(player));
if (te != null) {
te.latestmessage.put(isClient ? 0 : 1, "computer.messageResumeStop");
te.markBlockForUpdate();
}
}
}
}
updateAll();
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class ClearMessagePacket method execute.
@Override
public void execute(EntityPlayer player) {
TileEntityComputer te = SkaianetHandler.getComputer(computer);
if (te != null) {
te.latestmessage.put(program, "");
te.markBlockForUpdate();
}
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class ItemCruxiteArtifact method makeDestination.
@Override
public void makeDestination(Entity entity, WorldServer worldserver0, WorldServer worldserver1) {
if (entity instanceof EntityPlayerMP) {
// ((EntityPlayerMP) entity).addStat(MinestuckAchievementHandler.enterMedium);
Debug.infof("Starting entry for player %s", entity.getName());
int x = (int) entity.posX;
if (entity.posX < 0)
x--;
int y = (int) entity.posY;
int z = (int) entity.posZ;
if (entity.posZ < 0)
z--;
boolean creative = ((EntityPlayerMP) entity).interactionManager.isCreative();
int topY = MinestuckConfig.adaptEntryBlockHeight ? getTopHeight(worldserver0, x, y, z) : y + artifactRange;
int yDiff = 127 - topY;
// Set again, but with a more precise now that the y-coordinate is properly decided.
MinestuckDimensionHandler.setSpawn(worldserver1.provider.getDimension(), new BlockPos(x, y + yDiff, z));
Debug.debug("Loading spawn chunks...");
for (// Prevent anything to generate on the piece that we move
int chunkX = ((x - artifactRange) >> 4) - 1; // Prevent anything to generate on the piece that we move
chunkX <= ((x + artifactRange) >> 4) + 2; // Prevent anything to generate on the piece that we move
chunkX++) for (// from the overworld.
int chunkZ = ((z - artifactRange) >> 4) - 1; // from the overworld.
chunkZ <= ((z + artifactRange) >> 4) + 2; // from the overworld.
chunkZ++) worldserver1.getChunkProvider().provideChunk(chunkX, chunkZ);
Debug.debug("Placing blocks...");
long time = System.currentTimeMillis();
int bl = 0;
for (int blockX = x - artifactRange; blockX <= x + artifactRange; blockX++) {
int zWidth = (int) Math.sqrt((artifactRange + 0.5) * (artifactRange + 0.5) - (blockX - x) * (blockX - x));
for (int blockZ = z - zWidth; blockZ <= z + zWidth; blockZ++) {
Chunk chunk = worldserver1.getChunkFromChunkCoords(blockX >> 4, blockZ >> 4);
Chunk chunk2 = worldserver0.getChunkFromChunkCoords(blockX >> 4, blockZ >> 4);
int height = (int) Math.sqrt(artifactRange * artifactRange - (((blockX - x) * (blockX - x) + (blockZ - z) * (blockZ - z)) / 2));
for (int blockY = Math.max(0, y - height); blockY <= Math.min(topY, y + height); blockY++) {
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
BlockPos pos1 = pos.up(yDiff);
IBlockState block = worldserver0.getBlockState(pos);
TileEntity te = worldserver0.getTileEntity(pos);
long t = System.currentTimeMillis();
if (block.getBlock() != Blocks.BEDROCK && block.getBlock() != Blocks.PORTAL) {
copyBlockDirect(chunk, chunk2, blockX & 15, blockY + yDiff, blockY, blockZ & 15);
} else {
worldserver1.setBlockState(new BlockPos(blockX, blockY + yDiff, blockZ), Blocks.AIR.getDefaultState(), 3);
}
bl += System.currentTimeMillis() - t;
if ((te) != null) {
TileEntity te1 = null;
try {
te1 = te.getClass().newInstance();
} catch (Exception e) {
e.printStackTrace();
continue;
}
NBTTagCompound nbt = new NBTTagCompound();
te.writeToNBT(nbt);
nbt.setInteger("y", pos1.getY());
te1.readFromNBT(nbt);
worldserver1.removeTileEntity(pos1);
worldserver1.setTileEntity(pos1, te1);
if (te instanceof TileEntityComputer)
SkaianetHandler.movingComputer((TileEntityComputer) te, (TileEntityComputer) te1);
}
}
for (int blockY = Math.min(topY, y + height) + yDiff + 1; blockY < 256; blockY++) worldserver1.setBlockState(new BlockPos(blockX, blockY, blockZ), Blocks.AIR.getDefaultState(), 0);
}
}
int total = (int) (System.currentTimeMillis() - time);
Debug.debugf("Total: %d, block: %d", total, bl);
Debug.debug("Teleporting entities...");
AxisAlignedBB entityTeleportBB = entity.getEntityBoundingBox().grow((double) artifactRange, artifactRange, (double) artifactRange);
List<Entity> list = worldserver0.getEntitiesWithinAABBExcludingEntity(entity, entityTeleportBB);
Iterator<Entity> iterator = list.iterator();
entity.setPositionAndUpdate(entity.posX, entity.posY + yDiff, entity.posZ);
while (iterator.hasNext()) {
Entity e = iterator.next();
if (MinestuckConfig.entryCrater || e instanceof EntityPlayer || !creative && e instanceof EntityItem) {
if (e instanceof EntityPlayer && ServerEditHandler.getData((EntityPlayer) e) != null)
ServerEditHandler.reset(ServerEditHandler.getData((EntityPlayer) e));
else {
Teleport.teleportEntity(e, worldserver1.provider.getDimension(), null, e.posX, e.posY + yDiff, e.posZ);
}
} else // Copy instead of teleport
{
Entity newEntity = EntityList.newEntity(entity.getClass(), worldserver1);
if (newEntity != null) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
entity.writeToNBT(nbttagcompound);
nbttagcompound.removeTag("Dimension");
newEntity.readFromNBT(nbttagcompound);
newEntity.dimension = worldserver1.provider.getDimension();
newEntity.setPosition(newEntity.posX, newEntity.posY + yDiff, newEntity.posZ);
worldserver1.spawnEntity(newEntity);
}
}
}
Debug.debug("Removing old blocks...");
for (int blockX = x - artifactRange; blockX <= x + artifactRange; blockX++) {
int zWidth = (int) Math.sqrt(artifactRange * artifactRange - (blockX - x) * (blockX - x));
boolean isEdgeX = Math.abs(blockX - x) == artifactRange;
for (int blockZ = z - zWidth; blockZ <= z + zWidth; blockZ++) {
double radius = Math.sqrt(((blockX - x) * (blockX - x) + (blockZ - z) * (blockZ - z)) / 2);
int height = (int) (Math.sqrt(artifactRange * artifactRange - radius * radius));
int minY = y - height;
minY = minY < 0 ? 0 : minY;
int maxY = MinestuckConfig.entryCrater ? Math.min(topY, y + height) + 1 : 256;
boolean isEdgeZ = Math.abs(blockZ - z) == zWidth;
for (int blockY = minY; blockY < maxY; blockY++) {
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
if (MinestuckConfig.entryCrater) {
if (worldserver0.getBlockState(pos).getBlock() != Blocks.BEDROCK) {
if (isEdgeX || isEdgeZ || blockY == minY || blockY == maxY - 1) {
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
} else {
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
}
} else {
TileEntity tileEntity = worldserver0.getTileEntity(pos);
if (tileEntity != null)
if (!creative)
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
else if (// Avoid duplicating computer data when a computer is kept in the overworld
tileEntity instanceof TileEntityComputer)
((TileEntityComputer) tileEntity).programData = new NBTTagCompound();
else if (tileEntity instanceof TileEntityTransportalizer)
worldserver0.removeTileEntity(pos);
}
}
}
}
SkaianetHandler.clearMovingList();
if (!creative || MinestuckConfig.entryCrater) {
// Normally only items in containers
Debug.debug("Removing entities created from removing blocks...");
list = worldserver0.getEntitiesWithinAABBExcludingEntity(entity, entityTeleportBB);
iterator = list.iterator();
while (iterator.hasNext()) if (MinestuckConfig.entryCrater)
iterator.next().setDead();
else {
Entity e = iterator.next();
if (e instanceof EntityItem)
e.setDead();
}
}
Debug.debug("Placing gates...");
GateHandler.findGatePlacement(worldserver1);
placeGate(1, new BlockPos(x, GateHandler.gateHeight1, z), worldserver1);
placeGate(2, new BlockPos(x, GateHandler.gateHeight2, z), worldserver1);
ServerEventHandler.tickTasks.add(new PostEntryTask(worldserver1.provider.getDimension(), x, y + yDiff, z, artifactRange, (byte) 0));
Debug.info("Entry finished");
}
}
use of com.mraof.minestuck.tileentity.TileEntityComputer in project Minestuck by mraof.
the class BlockComputerOff method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (playerIn.isSneaking() || !EnumFacing.UP.equals(facing) || !heldItem.isEmpty() && ComputerProgram.getProgramID(heldItem) == -2)
return false;
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, MinestuckBlocks.blockComputerOn.getDefaultState().withProperty(DIRECTION, state.getValue(DIRECTION)), 2);
TileEntityComputer te = (TileEntityComputer) worldIn.getTileEntity(pos);
te.owner = IdentifierHandler.encode(playerIn);
MinestuckBlocks.blockComputerOn.onBlockActivated(worldIn, pos, worldIn.getBlockState(pos), playerIn, hand, facing, hitX, hitY, hitZ);
}
return true;
}
Aggregations