use of net.minecraft.block.BlockBed in project minecolonies by Minecolonies.
the class WindowBuildBuilding method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
final World world = Minecraft.getMinecraft().world;
resources.clear();
final int nextLevel = building.getBuildingLevel() == building.getBuildingMaxLevel() ? building.getBuildingMaxLevel() : (building.getBuildingLevel() + 1);
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), building.getSchematicName() + nextLevel);
final StructureWrapper wrapper = new StructureWrapper(world, sn.toString());
wrapper.setPosition(building.getLocation());
wrapper.rotate(building.getRotation(), world, building.getLocation(), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE);
while (wrapper.findNextBlock()) {
@Nullable final Template.BlockInfo blockInfo = wrapper.getBlockInfo();
@Nullable final Template.EntityInfo entityInfo = wrapper.getEntityinfo();
if (entityInfo != null) {
for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, Minecraft.getMinecraft().player)) {
if (!ItemStackUtils.isEmpty(stack)) {
addNeededResource(stack, 1);
}
}
}
if (blockInfo == null) {
continue;
}
@Nullable final IBlockState blockState = blockInfo.blockState;
@Nullable final Block block = blockState.getBlock();
if (wrapper.isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
continue;
}
if (block != null && block != Blocks.AIR && !AbstractEntityAIStructure.isBlockFree(block, 0) && block != ModBlocks.blockSolidSubstitution && block != ModBlocks.blockSubstitution) {
if (wrapper.getBlockInfo().tileentityData != null) {
final List<ItemStack> itemList = new ArrayList<>();
if (wrapper.getBlockInfo() != null && wrapper.getBlockInfo().tileentityData != null) {
itemList.addAll(ItemStackUtils.getItemStacksOfTileEntity(wrapper.getBlockInfo().tileentityData, world));
}
for (final ItemStack stack : itemList) {
addNeededResource(stack, 1);
}
}
addNeededResource(BlockUtils.getItemStackFromBlockState(blockState), 1);
}
}
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
use of net.minecraft.block.BlockBed in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method requestMaterials.
/**
* Iterates through all the required resources and stores them in the building.
* Suppressing Sonar Rule Squid:S135
* The rule thinks we should have less continue and breaks.
* But in this case the rule does not apply because code would become unreadable and uneffective without.
*/
@SuppressWarnings(LOOPS_SHOULD_NOT_CONTAIN_MORE_THAN_A_SINGLE_BREAK_OR_CONTINUE_STATEMENT)
private void requestMaterials() {
if (job.getWorkOrder().isRequested()) {
return;
}
final AbstractBuildingWorker buildingWorker = getOwnBuilding();
if (buildingWorker instanceof BuildingBuilder) {
((BuildingBuilder) buildingWorker).resetNeededResources();
}
while (job.getStructure().findNextBlock()) {
@Nullable final Template.BlockInfo blockInfo = job.getStructure().getBlockInfo();
@Nullable final Template.EntityInfo entityInfo = job.getStructure().getEntityinfo();
if (entityInfo != null) {
for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, worker)) {
final BuildingBuilder building = (BuildingBuilder) getOwnBuilding();
if (!ItemStackUtils.isEmpty(stack)) {
building.addNeededResource(stack, 1);
}
}
}
if (blockInfo == null) {
continue;
}
@Nullable IBlockState blockState = blockInfo.blockState;
@Nullable Block block = blockState.getBlock();
if (job.getStructure().isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
continue;
}
if (block instanceof BlockSolidSubstitution) {
blockState = getSolidSubstitution(job.getStructure().getBlockPosition());
block = blockState.getBlock();
}
final Block worldBlock = BlockPosUtil.getBlock(world, job.getStructure().getBlockPosition());
if (block != null && block != Blocks.AIR && worldBlock != Blocks.BEDROCK && !(worldBlock instanceof AbstractBlockHut) && !isBlockFree(block, 0)) {
requestBlockToBuildingIfRequired((BuildingBuilder) getOwnBuilding(), blockState);
}
}
job.getWorkOrder().setRequested(true);
}
use of net.minecraft.block.BlockBed in project minecolonies by Minecolonies.
the class BuildingHome method onWakeUp.
@Override
public void onWakeUp() {
final World world = getColony().getWorld();
if (world == null) {
return;
}
for (final BlockPos pos : bedList) {
IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos);
if (state.getBlock() instanceof BlockBed && state.getValue(BlockBed.OCCUPIED) && state.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.HEAD)) {
world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, false), 0x03);
}
}
}
use of net.minecraft.block.BlockBed in project minecolonies by Minecolonies.
the class BuildingHome method registerBlockPosition.
@Override
public void registerBlockPosition(@NotNull final IBlockState blockState, @NotNull final BlockPos pos, @NotNull final World world) {
super.registerBlockPosition(blockState, pos, world);
BlockPos registrationPosition = pos;
if (blockState.getBlock() instanceof BlockBed) {
if (blockState.getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT) {
registrationPosition = registrationPosition.offset(blockState.getValue(BlockBed.FACING));
}
if (!bedList.contains(registrationPosition)) {
bedList.add(registrationPosition);
}
}
}
use of net.minecraft.block.BlockBed in project Armourers-Workshop by RiskyKen.
the class ItemArmourersHammer method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
Block block = world.getBlock(x, y, z);
if (block != null) {
if (block instanceof BlockBed) {
rotateBed(world, x, y, z, (BlockBed) block, ForgeDirection.getOrientation(side));
player.swingItem();
return !world.isRemote;
}
if (block instanceof BlockChest) {
return false;
}
ForgeDirection dir = ForgeDirection.getOrientation(side);
if (player.isSneaking()) {
dir = dir.getOpposite();
}
if (block.rotateBlock(world, x, y, z, dir)) {
player.swingItem();
return !world.isRemote;
}
}
return false;
}
Aggregations