Search in sources :

Example 11 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class GateHandler method teleport.

public static void teleport(int gateId, int dim, EntityPlayerMP player) {
    Location location = null;
    // Basically to avoid message spam when something goes wrong
    player.timeUntilPortal = player.getPortalCooldown();
    if (gateId == 1) {
        BlockPos pos = getGatePos(-1, dim);
        Random rand = player.world.rand;
        BlockPos spawn = player.world.provider.getSpawnPoint();
        if (pos != null)
            do {
                int radius = 160 + rand.nextInt(60);
                double d = rand.nextDouble();
                int i = radius * radius;
                int x = (int) Math.sqrt(i * d);
                int z = (int) Math.sqrt(i * (1 - d));
                if (rand.nextBoolean())
                    x = -x;
                if (rand.nextBoolean())
                    z = -z;
                BlockPos placement = pos.add(x, 0, z);
                if (player.world.getBiomeForCoordsBody(placement) == BiomeMinestuck.mediumNormal)
                    location = new Location(player.world.getTopSolidOrLiquidBlock(placement), dim);
            } while (// TODO replace with a more friendly version without a chance of freezing the game
            location == null);
        else
            Debug.errorf("Unexpected error: Couldn't find position for land gate for dimension %d.", dim);
    } else if (gateId == 2) {
        SburbConnection landConnection = SburbHandler.getConnectionForDimension(dim);
        if (landConnection != null) {
            SburbConnection clientConnection = SkaianetHandler.getMainConnection(landConnection.getClientIdentifier(), false);
            if (clientConnection != null && clientConnection.enteredGame() && MinestuckDimensionHandler.isLandDimension(clientConnection.getClientDimension())) {
                int clientDim = clientConnection.getClientDimension();
                BlockPos gatePos = getGatePos(-1, clientDim);
                WorldServer world = player.mcServer.getWorld(clientDim);
                if (gatePos == null) {
                    findGatePlacement(world);
                    gatePos = getGatePos(-1, clientDim);
                    if (gatePos == null) {
                        Debug.errorf("Unexpected error: Can't initiaize land gate placement for dimension %d!", clientDim);
                        return;
                    }
                }
                if (gatePos.getY() == -1) {
                    world.getChunkProvider().provideChunk(gatePos.getX() - 8 >> 4, gatePos.getZ() - 8 >> 4);
                    world.getChunkProvider().provideChunk(gatePos.getX() + 8 >> 4, gatePos.getZ() - 8 >> 4);
                    world.getChunkProvider().provideChunk(gatePos.getX() - 8 >> 4, gatePos.getZ() + 8 >> 4);
                    world.getChunkProvider().provideChunk(gatePos.getX() + 8 >> 4, gatePos.getZ() + 8 >> 4);
                    gatePos = getGatePos(-1, clientDim);
                    if (gatePos.getY() == -1) {
                        Debug.errorf("Unexpected error: Gate didn't generate after loading chunks! Dim: %d, pos: %s", clientDim, gatePos);
                        return;
                    }
                }
                location = new Location(gatePos, clientDim);
            } else
                player.sendMessage(new TextComponentTranslation("message.gateMissingLand"));
        } else
            Debug.errorf("Unexpected error: Can't find connection for dimension %d!", dim);
    } else if (gateId == -1) {
        SburbConnection landConnection = SburbHandler.getConnectionForDimension(dim);
        if (landConnection != null) {
            SburbConnection serverConnection = SkaianetHandler.getMainConnection(landConnection.getServerIdentifier(), true);
            if (// Last shouldn't be necessary, but just in case something goes wrong elsewhere...
            serverConnection != null && serverConnection.enteredGame() && MinestuckDimensionHandler.isLandDimension(serverConnection.getClientDimension())) {
                int serverDim = serverConnection.getClientDimension();
                location = new Location(getGatePos(2, serverDim), serverDim);
            } else
                player.sendMessage(new TextComponentTranslation("message.gateMissingLand"));
        } else
            Debug.errorf("Unexpected error: Can't find connection for dimension %d!", dim);
    } else
        Debug.errorf("Unexpected error: Gate id %d is out of bounds!", gateId);
    if (location != null) {
        if (gateId != 1) {
            WorldServer world = player.mcServer.getWorld(location.dim);
            IBlockState block = world.getBlockState(location.pos);
            if (block.getBlock() != MinestuckBlocks.gate) {
                Debug.debugf("Can't find destination gate at %s. Probably destroyed.", location);
                player.sendMessage(new TextComponentTranslation("message.gateDestroyed"));
                return;
            }
        }
        Teleport.teleportEntity(player, location.dim, null, location.pos);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) Location(com.mraof.minestuck.util.Location) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 12 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class Echeladder method increaseProgress.

public void increaseProgress(int exp) {
    SburbConnection c = SkaianetHandler.getMainConnection(identifier, true);
    int topRung = c != null && c.enteredGame() ? RUNG_COUNT - 1 : MinestuckConfig.preEntryRungLimit;
    int expReq = getRungProgressReq();
    if (rung >= topRung || exp < expReq * MIN_PROGRESS_MODIFIER)
        return;
    int prevRung = rung;
    int prevExp = exp;
    increasment: {
        while (progress + exp >= expReq) {
            rung++;
            MinestuckPlayerData.getData(identifier).boondollars += BOONDOLLARS[Math.min(rung, BOONDOLLARS.length - 1)];
            exp -= (expReq - progress);
            progress = 0;
            expReq = getRungProgressReq();
            if (rung >= topRung)
                break increasment;
            if (rung > prevRung + 1)
                exp = (int) (exp / 1.5);
        }
        if (exp >= expReq / 50)
            progress += exp;
    }
    EntityPlayer player = identifier.getPlayer();
    if (player != null) {
        MinestuckPlayerTracker.updateEcheladder(player, false);
        if (rung != prevRung) {
            updateEcheladderBonuses(player);
            MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(Type.PLAYER_DATA, PlayerDataPacket.BOONDOLLAR, MinestuckPlayerData.getData(identifier).boondollars), player);
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 13 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class ContainerEditmode method updateInventory.

private void updateInventory() {
    ArrayList<ItemStack> itemList = new ArrayList<ItemStack>();
    SburbConnection c = SkaianetHandler.getClientConnection(ServerEditHandler.getData(player).getTarget());
    ArrayList<ItemStack> tools = new ArrayList<ItemStack>();
    // Fill list with tool items when implemented
    ArrayList<ItemStack> deployItems = DeployList.getItemList();
    Iterator<ItemStack> iter = deployItems.iterator();
    int playerTier = SburbHandler.availableTier(c.getClientIdentifier());
    while (iter.hasNext()) {
        ItemStack stack = iter.next();
        if (DeployList.getTier(stack) > playerTier)
            iter.remove();
        else if (DeployList.getSecondaryCost(stack) == null && c.givenItems()[DeployList.getOrdinal(stack)])
            iter.remove();
        else if (stack.getItem().equals(MinestuckItems.captchaCard) && AlchemyRecipeHandler.getDecodedItem(stack).getItem() instanceof ItemCruxiteArtifact)
            if (c.enteredGame())
                iter.remove();
            else
                stack.setTagCompound(AlchemyRecipeHandler.createCard(SburbHandler.getEntryItem(c.getClientIdentifier()), true).getTagCompound());
        else if (stack.getItem().equals(Item.getItemFromBlock(MinestuckBlocks.sburbMachine)) && stack.getMetadata() == 0) {
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setInteger("color", MinestuckPlayerData.getData(c.getClientIdentifier()).color);
            stack.setTagCompound(nbt);
        }
    }
    for (int i = 0; i < Math.max(tools.size(), deployItems.size()); i++) {
        itemList.add(i >= tools.size() ? ItemStack.EMPTY : tools.get(i));
        itemList.add(i >= deployItems.size() ? ItemStack.EMPTY : deployItems.get(i));
    }
    boolean changed = false;
    if (itemList.size() != this.items.size())
        changed = true;
    else
        for (int i = 0; i < itemList.size(); i++) if (!ItemStack.areItemStacksEqual(itemList.get(i), this.items.get(i))) {
            changed = true;
            break;
        }
    if (changed) {
        this.items = itemList;
        sendPacket();
    }
}
Also used : ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) ItemCruxiteArtifact(com.mraof.minestuck.item.ItemCruxiteArtifact) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 14 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class ServerEditHandler method tickEnd.

@SubscribeEvent
public void tickEnd(PlayerTickEvent event) {
    if (event.phase != Phase.END || event.side.isClient())
        return;
    EntityPlayerMP player = (EntityPlayerMP) event.player;
    EditData data = getData(player);
    if (data == null)
        return;
    SburbConnection c = data.connection;
    int range = MinestuckDimensionHandler.isLandDimension(player.dimension) ? MinestuckConfig.landEditRange : MinestuckConfig.overworldEditRange;
    updateInventory(player, c.givenItems(), c.enteredGame(), c.getClientIdentifier());
    updatePosition(player, range, c.centerX, c.centerZ);
    player.timeUntilPortal = player.getPortalCooldown();
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with SburbConnection

use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.

the class CommandGristSend method isPermittedFor.

private static boolean isPermittedFor(EntityPlayerMP player, EntityPlayerMP player2) {
    PlayerIdentifier name1 = IdentifierHandler.encode(player), name2 = IdentifierHandler.encode(player2);
    SburbConnection c1 = SkaianetHandler.getMainConnection(name1, true);
    SburbConnection c2 = SkaianetHandler.getMainConnection(name2, true);
    if (c1 == null || c2 == null || !c1.enteredGame() || !c2.enteredGame())
        return false;
    else
        return SessionHandler.getPlayerSession(name1) == SessionHandler.getPlayerSession(name2);
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Aggregations

SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)3 ArrayList (java.util.ArrayList)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 ItemStack (net.minecraft.item.ItemStack)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EditData (com.mraof.minestuck.editmode.EditData)1 EntityDecoy (com.mraof.minestuck.entity.EntityDecoy)1 ItemCruxiteArtifact (com.mraof.minestuck.item.ItemCruxiteArtifact)1 Location (com.mraof.minestuck.util.Location)1 Title (com.mraof.minestuck.util.Title)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)1 Map (java.util.Map)1 Random (java.util.Random)1