Search in sources :

Example 1 with EnumDoorHalf

use of net.minecraft.block.BlockDoor.EnumDoorHalf in project MC-Prefab by Brian-Wuest.

the class Structure method ScanStructure.

public static void ScanStructure(World world, BlockPos originalPos, BlockPos cornerPos1, BlockPos cornerPos2, String fileLocation, BuildClear clearedSpace, EnumFacing playerFacing, boolean includeAir, boolean excludeWater) {
    Structure scannedStructure = new Structure();
    scannedStructure.setClearSpace(clearedSpace);
    for (BlockPos currentPos : BlockPos.getAllInBox(cornerPos1, cornerPos2)) {
        if (world.isAirBlock(currentPos) && !includeAir) {
            continue;
        }
        IBlockState currentState = world.getBlockState(currentPos);
        Block currentBlock = currentState.getBlock();
        if (currentState.getMaterial() == Material.WATER && excludeWater) {
            continue;
        }
        BuildBlock buildBlock = Structure.createBuildBlockFromBlockState(currentState, currentBlock, currentPos, originalPos);
        if (currentBlock instanceof BlockDoor) {
            EnumDoorHalf blockHalf = currentState.getValue(BlockDoor.HALF);
            if (blockHalf == EnumDoorHalf.LOWER) {
                IBlockState upperHalfState = world.getBlockState(currentPos.up());
                if (upperHalfState != null && upperHalfState.getBlock() instanceof BlockDoor) {
                    Block upperBlock = upperHalfState.getBlock();
                    BuildBlock upperHalf = Structure.createBuildBlockFromBlockState(upperHalfState, upperBlock, currentPos.up(), originalPos);
                    buildBlock.setSubBlock(upperHalf);
                }
            } else {
                // Don't process upper door halves. These were already done.
                continue;
            }
        } else if (currentBlock instanceof BlockBed) {
            EnumPartType bedPart = currentState.getValue(BlockBed.PART);
            if (bedPart == EnumPartType.HEAD) {
                IBlockState bedFoot = null;
                boolean foundFoot = false;
                EnumFacing facing = EnumFacing.NORTH;
                while (foundFoot == false) {
                    bedFoot = world.getBlockState(currentPos.offset(facing));
                    if (bedFoot.getBlock() instanceof BlockBed && bedFoot.getValue(BlockBed.PART) == EnumPartType.FOOT) {
                        foundFoot = true;
                        break;
                    }
                    facing = facing.rotateY();
                    if (facing == EnumFacing.NORTH) {
                        // Got back to north, break out to avoid infinite loop.
                        break;
                    }
                }
                if (foundFoot) {
                    Block footBedBlock = bedFoot.getBlock();
                    BuildBlock bed = Structure.createBuildBlockFromBlockState(bedFoot, footBedBlock, currentPos.offset(facing), originalPos);
                    buildBlock.setSubBlock(bed);
                }
            } else {
                // Don't process foot of bed, it was already done.
                continue;
            }
        }
        scannedStructure.getBlocks().add(buildBlock);
        TileEntity tileEntity = world.getTileEntity(currentPos);
        if (tileEntity != null) {
            // Don't write data for empty tile entities.
            if ((tileEntity instanceof TileEntityChest && ((TileEntityChest) tileEntity).isEmpty()) || (tileEntity instanceof TileEntityFurnace && ((TileEntityFurnace) tileEntity).isEmpty())) {
                continue;
            }
            ResourceLocation resourceLocation = TileEntity.getKey(tileEntity.getClass());
            NBTTagCompound tagCompound = new NBTTagCompound();
            tileEntity.writeToNBT(tagCompound);
            BuildTileEntity buildTileEntity = new BuildTileEntity();
            buildTileEntity.setEntityDomain(resourceLocation.getResourceDomain());
            buildTileEntity.setEntityName(resourceLocation.getResourcePath());
            buildTileEntity.setStartingPosition(Structure.getStartingPositionFromOriginalAndCurrentPosition(currentPos, originalPos));
            buildTileEntity.setEntityNBTData(tagCompound);
            scannedStructure.tileEntities.add(buildTileEntity);
        }
    }
    int x_radiusRangeBegin = cornerPos1.getX() < cornerPos2.getX() ? cornerPos1.getX() : cornerPos2.getX();
    int x_radiusRangeEnd = cornerPos1.getX() < cornerPos2.getX() ? cornerPos2.getX() : cornerPos1.getX();
    int y_radiusRangeBegin = cornerPos1.getY() < cornerPos2.getY() ? cornerPos1.getY() : cornerPos2.getY();
    int y_radiusRangeEnd = cornerPos1.getY() < cornerPos2.getY() ? cornerPos2.getY() : cornerPos1.getY();
    int z_radiusRangeBegin = cornerPos1.getZ() < cornerPos2.getZ() ? cornerPos1.getZ() : cornerPos2.getZ();
    int z_radiusRangeEnd = cornerPos1.getZ() < cornerPos2.getZ() ? cornerPos2.getZ() : cornerPos1.getZ();
    for (Entity entity : world.getLoadedEntityList()) {
        BlockPos entityPos = entity.getPosition();
        if (entityPos.getX() >= x_radiusRangeBegin && entityPos.getX() <= x_radiusRangeEnd && entityPos.getZ() >= z_radiusRangeBegin && entityPos.getZ() <= z_radiusRangeEnd && entityPos.getY() >= y_radiusRangeBegin && entityPos.getY() <= y_radiusRangeEnd) {
            BuildEntity buildEntity = new BuildEntity();
            buildEntity.setEntityId(EntityList.getID(entity.getClass()));
            buildEntity.setEntityResourceString(EntityList.getKey(entity));
            buildEntity.setStartingPosition(Structure.getStartingPositionFromOriginalAndCurrentPosition(entityPos, originalPos));
            buildEntity.entityXAxisOffset = entityPos.getX() - entity.posX;
            buildEntity.entityYAxisOffset = entityPos.getY() - entity.posY;
            buildEntity.entityZAxisOffset = entityPos.getZ() - entity.posZ;
            if (entity instanceof EntityItemFrame) {
                buildEntity.entityYAxisOffset = buildEntity.entityYAxisOffset * -1;
            }
            NBTTagCompound entityTagCompound = new NBTTagCompound();
            entity.writeToNBT(entityTagCompound);
            buildEntity.setEntityNBTData(entityTagCompound);
            scannedStructure.entities.add(buildEntity);
        }
    }
    Structure.CreateStructureFile(scannedStructure, fileLocation);
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumPartType(net.minecraft.block.BlockBed.EnumPartType) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) TileEntity(net.minecraft.tileentity.TileEntity) EnumDoorHalf(net.minecraft.block.BlockDoor.EnumDoorHalf) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with EnumDoorHalf

use of net.minecraft.block.BlockDoor.EnumDoorHalf in project BuildCraft by BuildCraft.

the class VanillaRotationHandlers method rotateDoor.

private static EnumActionResult rotateDoor(World world, BlockPos pos, IBlockState state, EnumFacing sideWrenched) {
    if (state.getBlock() instanceof BlockDoor) {
        // Just check to make sure we have the right block...
        EnumDoorHalf half = state.getValue(BlockDoor.HALF);
        if (half == EnumDoorHalf.UPPER) {
            EnumHingePosition hinge = state.getValue(BlockDoor.HINGE);
            if (hinge == EnumHingePosition.LEFT)
                hinge = EnumHingePosition.RIGHT;
            else
                hinge = EnumHingePosition.LEFT;
            world.setBlockState(pos, state.withProperty(BlockDoor.HINGE, hinge));
        } else {
            // Lower
            rotateOnce(world, pos, state, BlockDoor.FACING, ROTATE_HORIZONTAL);
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) EnumDoorHalf(net.minecraft.block.BlockDoor.EnumDoorHalf) EnumHingePosition(net.minecraft.block.BlockDoor.EnumHingePosition)

Example 3 with EnumDoorHalf

use of net.minecraft.block.BlockDoor.EnumDoorHalf in project EnderIO by SleepyTrousers.

the class ItemYetaWrench method onItemUseFirst.

@Override
@Nonnull
public EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
    if (world.isRemote) {
        // If its client side we have to return pass so this method is called on server, where we need to perform the op
        return EnumActionResult.PASS;
    }
    final IBlockState blockState = world.getBlockState(pos);
    IBlockState bs = blockState;
    Block block = bs.getBlock();
    boolean ret = false;
    RightClickBlock e = new RightClickBlock(player, hand, pos, side, new Vec3d(hitX, hitY, hitZ));
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
        return EnumActionResult.PASS;
    }
    if (block instanceof BlockDoor) {
        EnumDoorHalf half = bs.getValue(BlockDoor.HALF);
        if (half == EnumDoorHalf.UPPER) {
            pos = pos.down();
        }
    }
    if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
        ret = true;
    } else if (block instanceof IBlockPaintableBlock && !player.isSneaking() && !YetaUtil.shouldHeldItemHideFacades(player)) {
        IBlockState paintSource = ((IBlockPaintableBlock) block).getPaintSource(blockState, world, pos);
        if (paintSource != null) {
            final IBlockState rotatedPaintSource = PaintUtil.rotate(paintSource);
            if (rotatedPaintSource != paintSource) {
                ((IBlockPaintableBlock) block).setPaintSource(blockState, world, pos, rotatedPaintSource);
            }
            ret = true;
        }
    }
    // so 'onBlockActivated' is never called
    if (!ret && player.isSneaking() && block instanceof BlockEio<?>) {
        BlockEio<?> beio = (BlockEio<?>) block;
        if (beio.shouldWrench(world, pos, player, side)) {
            beio.onBlockActivated(world, pos, bs, player, hand, side, hitX, hitY, hitZ);
            ret = true;
        }
    }
    if (ret) {
        player.swingArm(hand);
    }
    return ret ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) EnumDoorHalf(net.minecraft.block.BlockDoor.EnumDoorHalf) IBlockState(net.minecraft.block.state.IBlockState) BlockEio(crazypants.enderio.base.BlockEio) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) IYetaAwareBlock(crazypants.enderio.base.machine.interfaces.IYetaAwareBlock) Block(net.minecraft.block.Block) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) Vec3d(net.minecraft.util.math.Vec3d) Nonnull(javax.annotation.Nonnull)

Aggregations

EnumDoorHalf (net.minecraft.block.BlockDoor.EnumDoorHalf)3 BlockDoor (net.minecraft.block.BlockDoor)2 BlockEio (crazypants.enderio.base.BlockEio)1 IYetaAwareBlock (crazypants.enderio.base.machine.interfaces.IYetaAwareBlock)1 IBlockPaintableBlock (crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock)1 Nonnull (javax.annotation.Nonnull)1 Block (net.minecraft.block.Block)1 EnumPartType (net.minecraft.block.BlockBed.EnumPartType)1 EnumHingePosition (net.minecraft.block.BlockDoor.EnumHingePosition)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityChest (net.minecraft.tileentity.TileEntityChest)1 TileEntityFurnace (net.minecraft.tileentity.TileEntityFurnace)1 EnumFacing (net.minecraft.util.EnumFacing)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1