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);
}
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;
}
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;
}
Aggregations