use of net.minecraft.block.BlockBed.EnumPartType 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);
}
Aggregations