Search in sources :

Example 46 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemSystemLinker method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    NBTTagCompound stackCompound = stack.getTagCompound();
    if (stackCompound == null) {
        stackCompound = new NBTTagCompound();
        stack.setTagCompound(stackCompound);
    }
    if (block instanceof BlockHovercraftController) {
        if (!worldIn.isRemote) {
            NBTUtils.writeBlockPosToNBT("controllerPos", pos, stackCompound);
            playerIn.addChatMessage(new TextComponentString("ControllerPos set <" + pos.getX() + ":" + pos.getY() + ":" + pos.getZ() + ">"));
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    if (block instanceof BlockEtherCompressor) {
        if (!worldIn.isRemote) {
            BlockPos controllerPos = NBTUtils.readBlockPosFromNBT("controllerPos", stackCompound);
            if (controllerPos.equals(BlockPos.ORIGIN)) {
                playerIn.addChatMessage(new TextComponentString("No selected Controller"));
            } else {
                PhysicsWrapperEntity controllerWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, controllerPos);
                PhysicsWrapperEntity engineWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, pos);
                if (controllerWrapper != engineWrapper) {
                    playerIn.addChatMessage(new TextComponentString("Controller and Engine are on seperate ships"));
                    return EnumActionResult.SUCCESS;
                }
                TileEntity worldTile = worldIn.getTileEntity(pos);
                if (worldTile instanceof TileEntityEtherCompressor) {
                    TileEntityEtherCompressor tileEntity = (TileEntityEtherCompressor) worldTile;
                    BlockPos gravControllerPos = tileEntity.controllerPos;
                    if (gravControllerPos.equals(BlockPos.ORIGIN)) {
                        playerIn.addChatMessage(new TextComponentString("Set Controller To " + controllerPos.toString()));
                    } else {
                        playerIn.addChatMessage(new TextComponentString("Replaced controller position from: " + gravControllerPos.toString() + " to: " + controllerPos.toString()));
                    }
                    tileEntity.setController(controllerPos);
                }
            }
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockHovercraftController(ValkyrienWarfareControl.Block.BlockHovercraftController) BlockEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.BlockEtherCompressor) IBlockState(net.minecraft.block.state.IBlockState) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) TileEntityEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.TileEntityEtherCompressor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 47 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BalloonDetector method isValidExpansion.

@Override
public boolean isValidExpansion(int x, int y, int z) {
    IBlockState state = cache.getBlockState(x, y, z);
    if (!state.getBlock().blockMaterial.blocksMovement()) {
        Chunk chunk = cache.getChunkAt(x >> 4, z >> 4);
        mutable.setPos(x, y, z);
        if (!chunk.canSeeSky(mutable)) {
            return true;
        } else {
            cleanHouse = true;
        // System.out.println("Found a Hole in the Air-Balloon");
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Chunk(net.minecraft.world.chunk.Chunk)

Example 48 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BlockBalloonBurner method getTileEntity.

private BalloonBurnerTileEntity getTileEntity(World world, BlockPos pos, IBlockState state, Entity shipEntity) {
    PhysicsWrapperEntity wrapper = (PhysicsWrapperEntity) shipEntity;
    PhysicsObject obj = wrapper.wrapping;
    IBlockState controllerState = obj.VKChunkCache.getBlockState(pos);
    TileEntity worldTile = obj.VKChunkCache.getTileEntity(pos);
    if (worldTile == null) {
        return null;
    }
    if (worldTile instanceof BalloonBurnerTileEntity) {
        BalloonBurnerTileEntity burnerTile = (BalloonBurnerTileEntity) worldTile;
        return burnerTile;
    }
    return null;
}
Also used : BalloonBurnerTileEntity(ValkyrienWarfareControl.TileEntity.BalloonBurnerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) BalloonBurnerTileEntity(ValkyrienWarfareControl.TileEntity.BalloonBurnerTileEntity) PhysicsObject(ValkyrienWarfareBase.PhysicsManagement.PhysicsObject)

Example 49 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenLog method generate.

public boolean generate(World world, Random rand, int x, int y, int z) {
    IBlockState g = world.getBlockState(new BlockPos(x, y - 1, z));
    if (g.getMaterial() != Material.GROUND && g.getMaterial() != Material.GRASS && g.getMaterial() != Material.SAND && g.getMaterial() != Material.ROCK) {
        return false;
    }
    WorldUtil worldUtil = new WorldUtil(world);
    // The direction of the log (0 = X; 1 = Z)
    int dir = rand.nextInt(2);
    int i;
    IBlockState b;
    int air = 0;
    ArrayList<Integer> aX = new ArrayList<Integer>();
    ArrayList<Integer> aY = new ArrayList<Integer>();
    ArrayList<Integer> aZ = new ArrayList<Integer>();
    ArrayList<IBlockState> aBlock = new ArrayList<IBlockState>();
    for (i = 0; i < logLength; i++) {
        b = world.getBlockState(new BlockPos(x - (dir == 0 ? 1 : 0), y, z - (dir == 1 ? 1 : 0)));
        if (b.getMaterial() != Material.AIR && b.getMaterial() != Material.VINE && b.getMaterial() != Material.PLANTS) {
            break;
        }
        x -= dir == 0 ? 1 : 0;
        z -= dir == 1 ? 1 : 0;
        if (airCheck(world, rand, x, y, z) > 0) {
            return false;
        }
    }
    for (i = 0; i < logLength * 2; i++) {
        b = world.getBlockState(new BlockPos(x + (dir == 0 ? 1 : 0), y, z + (dir == 1 ? 1 : 0)));
        if (b.getMaterial() != Material.AIR && b.getMaterial() != Material.VINE && b.getMaterial() != Material.PLANTS) {
            break;
        }
        air += airCheck(world, rand, x, y, z);
        if (air > 2) {
            return false;
        }
        /**
             * Before we place the log block, let's make sure that there's an air block immediately above it.
             * This is to ensure that the log doesn't override, for example, a 2-block tall plant,
             * which some mods (like WAILA) have trouble handling.
             *
             * Also, to ensure that we don't have 'broken' logs, if one log block fails the check,
             * then no logs actually get placed.
             */
        if (!worldUtil.isBlockAbove(Blocks.AIR.getDefaultState(), 1, world, x, y, z, true)) {
            //Logger.debug("Found non-air block above log at %d %d %d", x, y, z);
            return false;
        }
        // Store the log information instead of placing it straight away.
        aX.add(x);
        aY.add(y);
        aZ.add(z);
        // If we can't rotate the log block for whatever reason, then just place it as it is.
        try {
            aBlock.add(logBlock.withProperty(BlockLog.LOG_AXIS, (dir == 0 ? BlockLog.EnumAxis.X : BlockLog.EnumAxis.Z)));
        } catch (Exception e) {
            aBlock.add(logBlock);
        }
        if (this.generateLeaves) {
            addLeaves(world, rand, dir, x, y, z);
        }
        x += dir == 0 ? 1 : 0;
        z += dir == 1 ? 1 : 0;
    }
    for (int i1 = 0; i1 < aBlock.size(); i1++) {
        world.setBlockState(new BlockPos(aX.get(i1).intValue(), aY.get(i1).intValue(), aZ.get(i1).intValue()), aBlock.get(i1), 2);
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) WorldUtil(rtg.api.util.WorldUtil)

Example 50 with IBlockState

use of net.minecraft.block.state.IBlockState in project Traverse by ProfessorProspector.

the class WorldGenCustomSwampTree method addVine.

private void addVine(World worldIn, BlockPos pos, PropertyBool prop) {
    IBlockState iblockstate = Blocks.VINE.getDefaultState().withProperty(prop, Boolean.valueOf(true));
    this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
    int i = 4;
    for (pos = pos.down(); isAir(worldIn, pos) && i > 0; --i) {
        this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
        pos = pos.down();
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2979 BlockPos (net.minecraft.util.math.BlockPos)1194 Block (net.minecraft.block.Block)797 ItemStack (net.minecraft.item.ItemStack)517 EnumFacing (net.minecraft.util.EnumFacing)420 TileEntity (net.minecraft.tileentity.TileEntity)339 World (net.minecraft.world.World)255 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)171 EntityPlayer (net.minecraft.entity.player.EntityPlayer)136 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)126 ArrayList (java.util.ArrayList)125 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)121 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 Entity (net.minecraft.entity.Entity)94 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)93 ItemBlock (net.minecraft.item.ItemBlock)89 BlockPos (net.minecraft.util.BlockPos)84 Random (java.util.Random)82 Vec3d (net.minecraft.util.math.Vec3d)81 RayTraceResult (net.minecraft.util.math.RayTraceResult)76