Java Code Examples for net.minecraft.world.World.isBlockLoaded()

The following are Jave code examples for showing how to use isBlockLoaded() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: pnc-repressurized   File: IC2.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    BlockPos pos = new BlockPos(x, y, z);
    TileEntity te = world.isBlockLoaded(pos) ? world.getTileEntity(pos) : null;
    switch (EnumGuiId.values()[ID]) {
        case PNEUMATIC_GENERATOR:
            return new GuiPneumaticGenerator(player.inventory, (TileEntityPneumaticGenerator) te);
        case ELECTRIC_COMPRESSOR:
            return new GuiElectricCompressor(player.inventory, (TileEntityElectricCompressor) te);
    }
    return null;
}
 
Example 2
Project: pnc-repressurized   File: PneumaticCraftUtils.java   Source Code and License Vote up 5 votes
public static TileEntity getTileEntity(BlockPos pos, int dimension) {
    World world = DimensionManager.getWorld(dimension);
    if (world != null && world.isBlockLoaded(pos)) {
        return world.getTileEntity(pos);
    }
    return null;
}
 
Example 3
Project: ModularMachinery   File: BlockArray.java   Source Code and License Vote up 5 votes
public boolean matches(World world, BlockPos center, boolean oldState) {
    lblPattern:
    for (Map.Entry<BlockPos, BlockInformation> entry : pattern.entrySet()) {
        BlockInformation info = entry.getValue();
        BlockPos at = center.add(entry.getKey());
        if(!world.isBlockLoaded(at)) { //We can't say if it's actually properly formed, but it didn't get changed from the last check so....
            return oldState;
        }

        if(info.matchingTag != null) {
            TileEntity te = world.getTileEntity(at);
            if(te != null && info.matchingTag.getSize() > 0) {
                NBTTagCompound cmp = new NBTTagCompound();
                te.writeToNBT(cmp);
                if(!NBTMatchingHelper.matchNBTCompound(info.matchingTag, cmp)) {
                    return false; //No match at this position.
                }
            }
        }

        IBlockState state = world.getBlockState(at);
        Block atBlock = state.getBlock();
        int atMeta = atBlock.getMetaFromState(state);

        for (IBlockStateDescriptor descriptor : info.matchingStates) {
            for (IBlockState applicable : descriptor.applicable) {
                Block type = applicable.getBlock();
                int meta = type.getMetaFromState(applicable);
                if(type.equals(state.getBlock()) && meta == atMeta) {
                    continue lblPattern; //Matches
                }
            }
        }
        return false;
    }
    return true;
}
 
Example 4
Project: Firma   File: GrassBlock2.java   Source Code and License Vote up 5 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
   {
       if (!worldIn.isRemote)
       {
           if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
           {
               worldIn.setBlockState(pos,Util.getDirt(state));
           }
           else
           {
               if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
               {
                   for (int i = 0; i < 4; ++i)
                   {
                       BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                       if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                       {
                           return;
                       }

                       IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                       IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                       if (Util.isDirt(iblockstate1.getBlock()) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                       {
                           worldIn.setBlockState(blockpos, Util.getGrass(iblockstate1));
                       }
                   }
               }
           }
       }
   }
 
Example 5
Project: Firma   File: SparseGrassBlock2.java   Source Code and License Vote up 5 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
   {
       if (!worldIn.isRemote)
       {
           if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
           {
               worldIn.setBlockState(pos,Util.getDirt(state));
           }
           else
           {
               if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
               {
                   for (int i = 0; i < 4; ++i)
                   {
                       BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                       if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                       {
                           return;
                       }

                       IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                       IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                       if (Util.isDirt(iblockstate1.getBlock()) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                       {
                           worldIn.setBlockState(blockpos, Util.getGrass(iblockstate1));
                       }
                   }
               }
           }
       }
   }
 
Example 6
Project: Firma   File: GrassBlock.java   Source Code and License Vote up 5 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
   {
       if (!worldIn.isRemote)
       {
           if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
           {
               worldIn.setBlockState(pos,Util.getDirt(state));
           }
           else
           {
               if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
               {
                   for (int i = 0; i < 4; ++i)
                   {
                       BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                       if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                       {
                           return;
                       }

                       IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                       IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                       if (Util.isDirt(iblockstate1.getBlock()) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                       {
                           worldIn.setBlockState(blockpos, Util.getGrass(iblockstate1));
                       }
                   }
               }
           }
       }
   }
 
Example 7
Project: CustomWorldGen   File: BlockGrass.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
        {
            worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
        }
        else
        {
            if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
            {
                for (int i = 0; i < 4; ++i)
                {
                    BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                    if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                    {
                        worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 8
Project: ModularMachinery   File: BlockArray.java   Source Code and License Vote up 5 votes
public boolean matches(World world, BlockPos at, boolean default_) {
    if(!world.isBlockLoaded(at)) {
        return default_;
    }

    if(matchingTag != null) {
        TileEntity te = world.getTileEntity(at);
        if(te != null && matchingTag.getSize() > 0) {
            NBTTagCompound cmp = new NBTTagCompound();
            te.writeToNBT(cmp);
            if(!NBTMatchingHelper.matchNBTCompound(matchingTag, cmp)) {
                return false; //No match at this position.
            }
        }
    }

    IBlockState state = world.getBlockState(at);
    Block atBlock = state.getBlock();
    int atMeta = atBlock.getMetaFromState(state);

    for (IBlockStateDescriptor descriptor : matchingStates) {
        for (IBlockState applicable : descriptor.applicable) {
            Block type = applicable.getBlock();
            int meta = type.getMetaFromState(applicable);
            if(type.equals(state.getBlock()) && meta == atMeta) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Project: Backmemed   File: BlockGrass.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity() > 2)
        {
            worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
        }
        else
        {
            if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
            {
                for (int i = 0; i < 4; ++i)
                {
                    BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                    if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity() <= 2)
                    {
                        worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 10
Project: CustomWorldGen   File: BlockStaticLiquid.java   Source Code and License Vote up 4 votes
private boolean getCanBlockBurn(World worldIn, BlockPos pos)
{
    return pos.getY() >= 0 && pos.getY() < 256 && !worldIn.isBlockLoaded(pos) ? false : worldIn.getBlockState(pos).getMaterial().getCanBurn();
}
 
Example 11
Project: CustomWorldGen   File: EntityLivingBase.java   Source Code and License Vote up 4 votes
/**
 * Teleports the entity to the specified location. Used for Enderman and Chorus Fruit teleportation
 */
public boolean attemptTeleport(double x, double y, double z)
{
    double d0 = this.posX;
    double d1 = this.posY;
    double d2 = this.posZ;
    this.posX = x;
    this.posY = y;
    this.posZ = z;
    boolean flag = false;
    BlockPos blockpos = new BlockPos(this);
    World world = this.worldObj;
    Random random = this.getRNG();

    if (world.isBlockLoaded(blockpos))
    {
        boolean flag1 = false;

        while (!flag1 && blockpos.getY() > 0)
        {
            BlockPos blockpos1 = blockpos.down();
            IBlockState iblockstate = world.getBlockState(blockpos1);

            if (iblockstate.getMaterial().blocksMovement())
            {
                flag1 = true;
            }
            else
            {
                --this.posY;
                blockpos = blockpos1;
            }
        }

        if (flag1)
        {
            this.setPositionAndUpdate(this.posX, this.posY, this.posZ);

            if (world.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty() && !world.containsAnyLiquid(this.getEntityBoundingBox()))
            {
                flag = true;
            }
        }
    }

    if (!flag)
    {
        this.setPositionAndUpdate(d0, d1, d2);
        return false;
    }
    else
    {
        int i = 128;

        for (int j = 0; j < 128; ++j)
        {
            double d6 = (double)j / 127.0D;
            float f = (random.nextFloat() - 0.5F) * 0.2F;
            float f1 = (random.nextFloat() - 0.5F) * 0.2F;
            float f2 = (random.nextFloat() - 0.5F) * 0.2F;
            double d3 = d0 + (this.posX - d0) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D;
            double d4 = d1 + (this.posY - d1) * d6 + random.nextDouble() * (double)this.height;
            double d5 = d2 + (this.posZ - d2) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D;
            world.spawnParticle(EnumParticleTypes.PORTAL, d3, d4, d5, (double)f, (double)f1, (double)f2, new int[0]);
        }

        if (this instanceof EntityCreature)
        {
            ((EntityCreature)this).getNavigator().clearPathEntity();
        }

        return true;
    }
}
 
Example 12
Project: DecompiledMinecraft   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.markBlockForUpdate(blockpos);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 13
Project: DecompiledMinecraft   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.markBlockForUpdate(blockpos);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 14
Project: CustomWorldGen   File: BlockStaticLiquid.java   Source Code and License Vote up 4 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (this.blockMaterial == Material.LAVA)
    {
        if (worldIn.getGameRules().getBoolean("doFireTick"))
        {
            int i = rand.nextInt(3);

            if (i > 0)
            {
                BlockPos blockpos = pos;

                for (int j = 0; j < i; ++j)
                {
                    blockpos = blockpos.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < worldIn.getHeight() && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    Block block = worldIn.getBlockState(blockpos).getBlock();

                    if (block.blockMaterial == Material.AIR)
                    {
                        if (this.isSurroundingBlockFlammable(worldIn, blockpos))
                        {
                            worldIn.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
                            return;
                        }
                    }
                    else if (block.blockMaterial.blocksMovement())
                    {
                        return;
                    }
                }
            }
            else
            {
                for (int k = 0; k < 3; ++k)
                {
                    BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1);

                    if (blockpos1.getY() >= 0 && blockpos1.getY() < 256 && !worldIn.isBlockLoaded(blockpos1))
                    {
                        return;
                    }

                    if (worldIn.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(worldIn, blockpos1))
                    {
                        worldIn.setBlockState(blockpos1.up(), Blocks.FIRE.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 15
Project: BaseClient   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.markBlockForUpdate(blockpos);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 16
Project: Adventurers-Toolbox   File: ItemATHammer.java   Source Code and License Vote up 4 votes
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
	World world = player.getEntityWorld();

	if (!world.isRemote && player instanceof EntityPlayerMP) {

		RayTraceResult rt = this.rayTrace(world, player, false);
		if (rt.typeOfHit == RayTraceResult.Type.BLOCK) {
			EnumFacing side = rt.sideHit;

			List<BlockPos> extraBlocks = getExtraBlocks(world, rt, player);

			for (BlockPos pos2 : extraBlocks) {

				IBlockState state = world.getBlockState(pos2);

				if (!world.isBlockLoaded(pos2) || !player.canPlayerEdit(pos2, side, itemstack) || !(state.getBlock().canHarvestBlock(world, pos2, player))) {
					continue;
				}

				if (player.capabilities.isCreativeMode) {
					state.getBlock().onBlockHarvested(world, pos2, state, player);
					if (state.getBlock().removedByPlayer(state, world, pos2, player, false)) {
						state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
					}
				} else {
					int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos2);

					state.getBlock().onBlockHarvested(world, pos2, state, player);
					this.onBlockDestroyed(itemstack, world, state, pos2, player);
					if (state.getBlock().removedByPlayer(state, world, pos2, player, true)) {
						state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
						state.getBlock().harvestBlock(world, player, pos2, state, world.getTileEntity(pos2), itemstack);
						state.getBlock().dropXpOnBlockBreak(world, pos2, xp);
					}
				}

				world.playEvent(2001, pos, Block.getStateId(state));
				((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));

			}

		}

	}

	return false;
}
 
Example 17
Project: Backmemed   File: EntityLivingBase.java   Source Code and License Vote up 4 votes
/**
 * Teleports the entity to the specified location. Used for Enderman and Chorus Fruit teleportation
 */
public boolean attemptTeleport(double x, double y, double z)
{
    double d0 = this.posX;
    double d1 = this.posY;
    double d2 = this.posZ;
    this.posX = x;
    this.posY = y;
    this.posZ = z;
    boolean flag = false;
    BlockPos blockpos = new BlockPos(this);
    World world = this.world;
    Random random = this.getRNG();

    if (world.isBlockLoaded(blockpos))
    {
        boolean flag1 = false;

        while (!flag1 && blockpos.getY() > 0)
        {
            BlockPos blockpos1 = blockpos.down();
            IBlockState iblockstate = world.getBlockState(blockpos1);

            if (iblockstate.getMaterial().blocksMovement())
            {
                flag1 = true;
            }
            else
            {
                --this.posY;
                blockpos = blockpos1;
            }
        }

        if (flag1)
        {
            this.setPositionAndUpdate(this.posX, this.posY, this.posZ);

            if (world.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty() && !world.containsAnyLiquid(this.getEntityBoundingBox()))
            {
                flag = true;
            }
        }
    }

    if (!flag)
    {
        this.setPositionAndUpdate(d0, d1, d2);
        return false;
    }
    else
    {
        int i = 128;

        for (int j = 0; j < 128; ++j)
        {
            double d6 = (double)j / 127.0D;
            float f = (random.nextFloat() - 0.5F) * 0.2F;
            float f1 = (random.nextFloat() - 0.5F) * 0.2F;
            float f2 = (random.nextFloat() - 0.5F) * 0.2F;
            double d3 = d0 + (this.posX - d0) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D;
            double d4 = d1 + (this.posY - d1) * d6 + random.nextDouble() * (double)this.height;
            double d5 = d2 + (this.posZ - d2) * d6 + (random.nextDouble() - 0.5D) * (double)this.width * 2.0D;
            world.spawnParticle(EnumParticleTypes.PORTAL, d3, d4, d5, (double)f, (double)f1, (double)f2, new int[0]);
        }

        if (this instanceof EntityCreature)
        {
            ((EntityCreature)this).getNavigator().clearPathEntity();
        }

        return true;
    }
}
 
Example 18
Project: Backmemed   File: BlockStaticLiquid.java   Source Code and License Vote up 4 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (this.blockMaterial == Material.LAVA)
    {
        if (worldIn.getGameRules().getBoolean("doFireTick"))
        {
            int i = rand.nextInt(3);

            if (i > 0)
            {
                BlockPos blockpos = pos;

                for (int j = 0; j < i; ++j)
                {
                    blockpos = blockpos.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    Block block = worldIn.getBlockState(blockpos).getBlock();

                    if (block.blockMaterial == Material.AIR)
                    {
                        if (this.isSurroundingBlockFlammable(worldIn, blockpos))
                        {
                            worldIn.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
                            return;
                        }
                    }
                    else if (block.blockMaterial.blocksMovement())
                    {
                        return;
                    }
                }
            }
            else
            {
                for (int k = 0; k < 3; ++k)
                {
                    BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1);

                    if (blockpos1.getY() >= 0 && blockpos1.getY() < 256 && !worldIn.isBlockLoaded(blockpos1))
                    {
                        return;
                    }

                    if (worldIn.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(worldIn, blockpos1))
                    {
                        worldIn.setBlockState(blockpos1.up(), Blocks.FIRE.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 19
Project: CustomWorldGen   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 20
Project: Backmemed   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}