use of net.minecraft.block.BlockBed in project RFToolsDimensions by McJty.
the class ForgeEventHandlers method onPlayerRightClickEvent.
@SubscribeEvent
public void onPlayerRightClickEvent(PlayerInteractEvent.RightClickBlock event) {
World world = event.getWorld();
if (world.isRemote)
return;
BlockPos pos = event.getPos();
WorldProvider provider = world.provider;
if (!(world.getBlockState(pos).getBlock() instanceof BlockBed && provider instanceof GenericWorldProvider))
return;
// We are in an RFTools dimension.
switch(GeneralConfiguration.bedBehaviour) {
case 0:
event.setCanceled(true);
Logging.message(event.getEntityPlayer(), "You cannot sleep in this dimension!");
break;
// In case 1, just do the usual thing (this typically mean explosion).
case 2:
event.setCanceled(true);
event.getEntityPlayer().setSpawnChunk(pos, true, provider.getDimension());
Logging.message(event.getEntityPlayer(), "Spawn point set!");
}
}
use of net.minecraft.block.BlockBed in project MC-Prefab by Brian-Wuest.
the class StructureAlternateStart method CustomBlockProcessingHandled.
@Override
protected Boolean CustomBlockProcessingHandled(StructureConfiguration configuration, BuildBlock block, World world, BlockPos originalPos, EnumFacing assumedNorth, Block foundBlock, IBlockState blockState, EntityPlayer player) {
HouseConfiguration houseConfig = (HouseConfiguration) configuration;
if ((!houseConfig.addBed && foundBlock instanceof BlockBed) || (!houseConfig.addChest && foundBlock instanceof BlockChest) || (!houseConfig.addTorches && foundBlock instanceof BlockTorch) || (!houseConfig.addCraftingTable && (foundBlock instanceof BlockWorkbench || foundBlock instanceof BlockFurnace))) {
// "handled"
return true;
}
if (foundBlock instanceof BlockFurnace) {
this.furnacePosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockTrapDoor && houseConfig.addMineShaft) {
// The trap door will still be added, but the mine shaft may not be
// built.
this.trapDoorPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockChest && this.chestPosition == null) {
this.chestPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockStandingSign) {
this.signPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
}
if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS.getRegistryName().getResourcePath())) {
blockState = blockState.withProperty(BlockStainedGlass.COLOR, houseConfig.glassColor);
block.setBlockState(blockState);
this.priorityOneBlocks.add(block);
return true;
} else if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourcePath())) {
block.setBlockState(foundBlock.getStateFromMeta(houseConfig.glassColor.getMetadata()));
this.priorityOneBlocks.add(block);
return true;
}
return false;
}
use of net.minecraft.block.BlockBed in project minecolonies by Minecolonies.
the class EntityAISleep method shouldContinueExecuting.
/**
* Continue executing if he should sleep.
* Call the wake up method as soon as this isn't the case anymore.
* Might search a bed while he is trying to sleep.
*
* @return true while he should sleep.
*/
@Override
public boolean shouldContinueExecuting() {
if (citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
wokeUp = false;
final Colony colony = citizen.getColony();
if (colony == null || colony.getBuildingManager().getBuilding(citizen.getHomePosition()) == null) {
return true;
}
if (usedBed == null) {
final AbstractBuilding hut = colony.getBuildingManager().getBuilding(citizen.getHomePosition());
if (hut instanceof BuildingHome) {
for (final BlockPos pos : ((BuildingHome) hut).getBedList()) {
final World world = citizen.world;
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)) {
usedBed = pos;
citizen.world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, true), 0x03);
final BlockPos feetPos = pos.offset(state.getValue(BlockBed.FACING).getOpposite());
final IBlockState feetState = citizen.world.getBlockState(feetPos);
citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
return true;
}
}
}
usedBed = citizen.getHomePosition();
} else {
if (citizen.isWorkerAtSiteWithMove(usedBed, 1)) {
citizen.trySleep(usedBed);
return true;
}
}
return true;
}
citizen.onWakeUp();
if (usedBed != null) {
final IBlockState state = citizen.world.getBlockState(usedBed);
if (state.getBlock() instanceof BlockBed) {
final IBlockState headState = citizen.world.getBlockState(usedBed);
citizen.world.setBlockState(usedBed, headState.withProperty(BlockBed.OCCUPIED, false), 0x03);
final BlockPos feetPos = usedBed.offset(headState.getValue(BlockBed.FACING).getOpposite());
final IBlockState feetState = citizen.world.getBlockState(feetPos);
citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
}
usedBed = null;
}
wokeUp = true;
return false;
}
use of net.minecraft.block.BlockBed in project Armourers-Workshop by RiskyKen.
the class ItemArmourersHammer method rotateBed.
private boolean rotateBed(World world, int x, int y, int z, BlockBed block, ForgeDirection axis) {
int meta = world.getBlockMetadata(x, y, z);
ForgeDirection[] bedRots = { ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.NORTH, ForgeDirection.EAST };
int bedDir = ((BlockBed) block).getDirection(meta);
ForgeDirection bedRot = bedRots[bedDir];
ForgeDirection otherHalf = bedRot;
boolean isHead = block.isBlockHeadOfBed(meta);
if (isHead) {
otherHalf = bedRot.getOpposite();
}
if (world.getBlock(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ) == block) {
int otherMeta = world.getBlockMetadata(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ);
int newMeta = (meta & 3) + 2 % 3;
if (!isHead) {
newMeta += 8;
}
world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
newMeta = (otherMeta & 3) + 2 % 3;
if (isHead) {
newMeta += 8;
}
world.setBlockMetadataWithNotify(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ, newMeta, 3);
return true;
}
return false;
}
Aggregations