Search in sources :

Example 1 with SpawnCureParticles

use of uk.co.wehavecookies56.kk.common.network.packet.client.SpawnCureParticles in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class BlockSavePoint method updateState.

private void updateState(World world, BlockPos pos) {
    List list = world.getEntitiesWithinAABBExcludingEntity((Entity) null, new AxisAlignedBB(pos.add(0, 0, 0), pos.add(1, 1, 1)));
    if (!list.isEmpty())
        for (int i = 0; i < list.size(); i++) {
            Entity e = (Entity) list.get(i);
            if (e instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) e;
                IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
                // System.out.println(player.getBedLocation());
                // System.out.println(pos.getX());
                boolean samePos;
                BlockPos bedPos;
                if (player.getBedLocation() == null) {
                    IFirstTimeJoin originalPos = player.getCapability(ModCapabilities.FIRST_TIME_JOIN, null);
                    bedPos = new BlockPos(originalPos.getPosX(), originalPos.getPosY(), originalPos.getPosZ());
                } else {
                    bedPos = player.getBedLocation();
                }
                samePos = bedPos.getX() == pos.getX() && bedPos.getY() == pos.getY() && bedPos.getZ() == pos.getZ();
                if (player.isSneaking() && !samePos) {
                    player.setSpawnChunk(pos, true, 0);
                    player.setSpawnPoint(pos, true);
                    TextHelper.sendFormattedChatMessage("Spawn point saved!", TextFormatting.GREEN, player);
                    world.playSound((EntityPlayer) null, player.getPosition(), ModSounds.savespawn, SoundCategory.BLOCKS, 1.0f, 1.0f);
                }
                if (player.getHealth() < player.getMaxHealth() || STATS.getMP() < STATS.getMaxMP()) {
                    player.heal(1);
                    STATS.addMP(2);
                    if (player.getFoodStats().getFoodLevel() < 20)
                        player.getFoodStats().addStats(4, 0);
                    if (timeHealed + 1 <= (int) Minecraft.getSystemTime() / 1000) {
                        world.playSound((EntityPlayer) null, player.getPosition(), ModSounds.savepoint, SoundCategory.BLOCKS, 1.0f, 1.0f);
                        PacketDispatcher.sendToAllAround(new SpawnCureParticles(pos, true), player, 64.0D);
                    }
                    PacketDispatcher.sendTo(new SyncMagicData(player.getCapability(ModCapabilities.MAGIC_STATE, null), STATS), (EntityPlayerMP) player);
                }
            }
        }
    world.scheduleUpdate(new BlockPos(pos), this, this.tickRate(world));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SpawnCureParticles(uk.co.wehavecookies56.kk.common.network.packet.client.SpawnCureParticles) Entity(net.minecraft.entity.Entity) IFirstTimeJoin(uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability.IFirstTimeJoin) IPlayerStats(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData)

Aggregations

List (java.util.List)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 IFirstTimeJoin (uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability.IFirstTimeJoin)1 IPlayerStats (uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats)1 SpawnCureParticles (uk.co.wehavecookies56.kk.common.network.packet.client.SpawnCureParticles)1 SyncMagicData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData)1