Java Code Examples for net.minecraft.block.state.IBlockState#getBlock()

The following examples show how to use net.minecraft.block.state.IBlockState#getBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskCountBlocksPlacement.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void countAtPosition(BlockPos pos)
{
    IBlockState stateSchematic = this.worldSchematic.getBlockState(pos).getActualState(this.worldSchematic, pos);

    if (stateSchematic.getBlock() != Blocks.AIR)
    {
        IBlockState stateClient = this.worldClient.getBlockState(pos).getActualState(this.worldClient, pos);

        this.countsTotal.addTo(stateSchematic, 1);

        if (stateClient.getBlock() == Blocks.AIR)
        {
            this.countsMissing.addTo(stateSchematic, 1);
        }
        else if (stateClient != stateSchematic)
        {
            this.countsMissing.addTo(stateSchematic, 1);
            this.countsMismatch.addTo(stateSchematic, 1);
        }
    }
}
 
Example 2
Source File: StructureTofuVillagePieces.java    From TofuCraftReload with MIT License 6 votes vote down vote up
protected IBlockState getBiomeSpecificBlockState(IBlockState blockstateIn) {
    net.minecraftforge.event.terraingen.BiomeEvent.GetVillageBlockID event = new net.minecraftforge.event.terraingen.BiomeEvent.GetVillageBlockID(startPiece == null ? null : startPiece.biome, blockstateIn);
    net.minecraftforge.common.MinecraftForge.TERRAIN_GEN_BUS.post(event);

    if (event.getResult() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
        return event.getReplacement();
    if (event.getBiome() == TofuBiomes.ZUNDATOFU_PLAINS) {

        if (blockstateIn.getBlock() == BlockLoader.SOYMILK) {
            return BlockLoader.ZUNDASOYMILK.getDefaultState();
        }

        if (blockstateIn.getBlock() == BlockLoader.TOFUISHI_BRICK) {
            return BlockLoader.TOFUZUNDA_BRICK.getDefaultState();
        }

        if (blockstateIn.getBlock() == BlockLoader.TOFUMOMEN_STAIRS) {
            return BlockLoader.TOFUZUNDA_STAIRS.getDefaultState().withProperty(BlockStairs.FACING, blockstateIn.getValue(BlockStairs.FACING));
        }

    }

    return blockstateIn;
}
 
Example 3
Source File: BlockUnderVine.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos fromPos) {
    super.neighborChanged(state, world, pos, block, fromPos);
    if (!this.canBlockStay(world, pos)) {
        this.checkAndDropBlock(world, pos, state);
    }else {
        IBlockState blockState = world.getBlockState(pos.down());

        IBlockState newStuckState = state.withProperty(STUCK, true);
        IBlockState newNonStuckState = state.withProperty(STUCK, false);
        if (blockState.getBlock() == this) {
            world.setBlockState(pos, newStuckState, 2);
        } else {
            world.setBlockState(pos, newNonStuckState, 2);
        }
    }
}
 
Example 4
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void applyHammerDrops(Random random, IBlockState blockState, List<ItemStack> drops, int fortuneLevel, EntityPlayer player) {
    ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().getMetaFromState(blockState));
    Recipe recipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
    if (recipe != null && !recipe.getOutputs().isEmpty()) {
        drops.clear();
        for (ItemStack outputStack : recipe.getResultItemOutputs(Integer.MAX_VALUE, random, 0)) {
            outputStack = outputStack.copy();
            if (!(player instanceof FakePlayer) && OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) {
                int growAmount = Math.round(outputStack.getCount() * random.nextFloat());
                if (fortuneLevel > 0) {
                    int i = Math.max(0, random.nextInt(fortuneLevel + 2) - 1);
                    growAmount += outputStack.getCount() * i;
                }
                outputStack.grow(growAmount);
            }
            drops.add(outputStack);
        }
    }
}
 
Example 5
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getCombinedId4Data(ExtendedBlockStorage section, int x, int y, int z) {
    IBlockState ibd = section.getData().get(x & 15, y & 15, z & 15);
    Block block = ibd.getBlock();
    int id = Block.getIdFromBlock(block);
    if (FaweCache.hasData(id)) {
        return (id << 4) + block.getMetaFromState(ibd);
    } else {
        return id << 4;
    }
}
 
Example 6
Source File: GTModelMortar.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GTModelMortar(IBlockState state) {
	super(Ic2Models.getBlockTransforms());
	this.state = state;
	this.bowlSprite = state.getBlock() == GTBlocks.ironMortar
			? Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/stone")
			: Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/planks_oak");
	this.postSprite = state.getBlock() == GTBlocks.ironMortar
			? Ic2Models.getIconSafe(Ic2Icons.getTextures("b0")[17])
			: Ic2Icons.getTextures("b0")[35];
}
 
Example 7
Source File: ScannerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Pair<BlockPos, IBlockState> getHitBlock(EntityPlayer entityPlayer) {
    RayTraceResult result = RayTracer.retrace(entityPlayer);
    if (result.typeOfHit == Type.BLOCK) {
        BlockPos blockPos = result.getBlockPos();
        IBlockState blockState = entityPlayer.world.getBlockState(blockPos);
        if (blockState.getBlock() instanceof IScannableBlock) {
            return Pair.of(blockPos, blockState);
        }
    }
    return null;
}
 
Example 8
Source File: WorldHelper.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns true if block is replaceable and has no collider
 */
public static boolean isAirLikeBlock(World world, BlockPos pos)
{
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	boolean replaceable = block.isReplaceable(world, pos);
	boolean noCollider = (state.getCollisionBoundingBox(world, pos) == Block.NULL_AABB);
	return (replaceable || noCollider);
}
 
Example 9
Source File: ChunkProviderSurface.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This is for stripping a chunk of all but ore and BEDROCK for easier testing.
 */
protected void stripChunk(ChunkPrimer primer)
{
	Point p;
	Center closestCenter;
	IBlockState state;
	for(int x = 0; x < 16; x++)
	{
		for(int z = 0; z < 16; z++)
		{
			p = new Point(x, z);
			closestCenter = this.getHex(p);
			int hexElev = this.getHexElevation(closestCenter, p);

			if(closestCenter.hasAnyMarkersOf(Marker.Coast, Marker.Ocean))
				continue;

			for(int y = hexElev; y >= 0; y--)
			{
				state = primer.getBlockState(x, y, z);
				if(state.getBlock() != TFCBlocks.Ore && state.getBlock() != Blocks.BEDROCK && state.getBlock() != Blocks.WOOL)
				{
					primer.setBlockState(x, y, z, Blocks.AIR.getDefaultState());
				}
			}
		}
	}
}
 
Example 10
Source File: BlockVegetation.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IBlockState getPlant(IBlockAccess world, BlockPos pos) 
{
	IBlockState state = world.getBlockState(pos);
	if (state.getBlock() != this) 
		return getDefaultState();
	return state;
}
 
Example 11
Source File: HarvesterTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private EnumFacing getFacing() {
    IBlockState blockState = getWorld().getBlockState(getPos());

    if (blockState.getBlock() instanceof Harvester == false) {
        return EnumFacing.NORTH;
    }

    return blockState.getValue(Harvester.FACING);
}
 
Example 12
Source File: BlockVegDesert.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IBlockState getPlant(IBlockAccess world, BlockPos pos) 
{
	IBlockState state = world.getBlockState(pos);
	if (state.getBlock() != this) 
		return getDefaultState();
	return state;
}
 
Example 13
Source File: CollectorHelper.java    From EmergingTechnology with MIT License 5 votes vote down vote up
public static boolean isFloatingInWater(World world, BlockPos pos) {

        IBlockState aboveBlock = world.getBlockState(pos.add(0, 1, 0));

        // If underwater, is invalid
        if (aboveBlock.getBlock() == Blocks.WATER) {
            return false;
        }

        BlockPos startPos = pos.add(-2, 0, -2);

        int waterBlockCount = 0;

        for (int x = 0; x < 5; x++) {
            for (int z = 0; z < 5; z++) {
                boolean isValidNeighbour = isValidNeighbour(world.getBlockState(startPos.add(x, 0, z)));
                if (isValidNeighbour) {
                    waterBlockCount++;
                    if (waterBlockCount >= EmergingTechnologyConfig.POLYMERS_MODULE.COLLECTOR.minimumWaterBlocks) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
 
Example 14
Source File: BlockFuton.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
	if (state.getValue(PART) == EnumPartType.FOOT) {
		IBlockState iblockstate = worldIn.getBlockState(pos.offset(state.getValue(FACING)));

		if (iblockstate.getBlock() == this) {
			state = state.withProperty(OCCUPIED, iblockstate.getValue(OCCUPIED));
		}
	}

	return state;
}
 
Example 15
Source File: DiffuserHelper.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private static int doBoost(World world, BlockPos pos, FluidTank gasHandler, int probability, int range) {
    int plantsBoosted = 0;

    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        for (int i = 1; i < range + 1; i++) {

            // Not enough gas
            if (gasHandler
                    .getFluidAmount() < EmergingTechnologyConfig.HYDROPONICS_MODULE.DIFFUSER.diffuserGasBaseUsage) {
                break;
            }

            BlockPos position = pos.offset(facing, i);
            IBlockState blockState = world.getBlockState(position);
            Block block = blockState.getBlock();

            if (PlantHelper.isPlantBlock(blockState.getBlock())) {

                boolean success = growBlock(world, blockState, block, position, gasHandler, probability);

                if (success)
                    plantsBoosted += 1;

            } else if (!blockState.getBlock().isFullBlock(blockState)) {
                continue;
            } else {
                break;
            }
        }
    }

    return plantsBoosted;
}
 
Example 16
Source File: TileEntityToroSpawner.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private boolean isGroundBlock(IBlockState blockState) {
	if (blockState.getBlock() == Blocks.LEAVES || blockState.getBlock() == Blocks.LEAVES2 || blockState.getBlock() == Blocks.LOG || blockState.getBlock() instanceof BlockBush) {
		return false;
	}
	return blockState.isOpaqueCube();
}
 
Example 17
Source File: TileEntityShipHelm.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public void calculateCompassAngle() {
    lastCompassAngle = compassAngle;

    IBlockState helmState = getWorld().getBlockState(getPos());
    if (helmState.getBlock() != ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipHelm) {
        return;
    }
    EnumFacing enumfacing = helmState.getValue(BlockShipHelm.FACING);
    double wheelAndCompassStateRotation = enumfacing.getHorizontalAngle();

    BlockPos spawnPos = getWorld().getSpawnPoint();
    Vector compassPoint = new Vector(getPos().getX(), getPos().getY(), getPos().getZ());
    compassPoint.add(1D, 2D, 1D);

    Optional<PhysicsObject> physicsObject = ValkyrienUtils
        .getPhysicsObject(getWorld(), getPos());
    if (physicsObject.isPresent()) {
        physicsObject.get()
            .getShipTransformationManager()
            .getCurrentTickTransform()
            .transform(compassPoint,
                TransformType.SUBSPACE_TO_GLOBAL);
        // RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform,
        // compassPoint);
    }

    Vector compassDirection = new Vector(compassPoint);
    compassDirection.subtract(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());

    if (physicsObject.isPresent()) {
        physicsObject.get()
            .getShipTransformationManager()
            .getCurrentTickTransform()
            .rotate(compassDirection,
                TransformType.GLOBAL_TO_SUBSPACE);
        // RotationMatrices.doRotationOnly(wrapper.wrapping.coordTransform.wToLTransform,
        // compassDirection);
    }

    compassDirection.normalize();
    compassAngle = Math.toDegrees(Math.atan2(compassDirection.X, compassDirection.Z))
        - wheelAndCompassStateRotation;
    compassAngle = (compassAngle + 360D) % 360D;
}
 
Example 18
Source File: BlockInfo.java    From ExNihiloAdscensio with MIT License 4 votes vote down vote up
public BlockInfo(IBlockState state)
{
    block = state == null ? null : state.getBlock();
    meta = state == null ? -1 : state.getBlock().getMetaFromState(state);
}
 
Example 19
Source File: BlockTraverseDeadGrass.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean canSustainBush(IBlockState state) {
    return state.getBlock() == getBlock("red_rock") || state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.HARDENED_CLAY || state.getBlock() == Blocks.STAINED_HARDENED_CLAY;
}
 
Example 20
Source File: GTItemCreativeScanner.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static EnumActionResult scanBlock(EntityPlayer player, World world, BlockPos pos, EnumFacing side,
		EnumHand hand) {
	if (IC2.platform.isRendering()) {
		IC2.audioManager.playOnce(player, Ic2Sounds.scannerUse);
		return EnumActionResult.SUCCESS;
	}
	TileEntity tileEntity = world.getTileEntity(pos);
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	IC2.platform.messagePlayer(player, "-----X: " + pos.getX() + " Y: " + pos.getY() + " Z: " + pos.getZ()
			+ " -----");
	IC2.platform.messagePlayer(player, "" + state.getBlock().getLocalizedName());
	if (tileEntity == null) {
		IC2.platform.messagePlayer(player, "Hardness: " + state.getBlock().getBlockHardness(state, world, pos));
		IC2.platform.messagePlayer(player, "Blast Resistance: "
				+ state.getBlock().getExplosionResistance(null) * 5.0F);
	}
	if (tileEntity instanceof IReactor) {
		IReactor te5 = (IReactor) tileEntity;
		IC2.platform.messagePlayer(player, "Reactor Heat: " + te5.getHeat());
		IC2.platform.messagePlayer(player, "Max Heat: " + te5.getMaxHeat());
		IC2.platform.messagePlayer(player, "HEM: " + te5.getHeatEffectModifier());
		IC2.platform.messagePlayer(player, "Output: " + te5.getReactorEnergyOutput() + " EU");
	}
	if (tileEntity instanceof IPersonalBlock) {
		IPersonalBlock te6 = (IPersonalBlock) tileEntity;
		IC2.platform.messagePlayer(player, "Can Access: " + te6.canAccess(player.getUniqueID()));
	}
	if (tileEntity instanceof TileEntityCrop) {
		TileEntityCrop te7 = (TileEntityCrop) tileEntity;
		IC2.platform.messagePlayer(player, "Crop: " + te7.getCrop().getId());
		IC2.platform.messagePlayer(player, "Size: " + te7.getCurrentSize());
		IC2.platform.messagePlayer(player, "Growth: " + te7.getStatGrowth());
		IC2.platform.messagePlayer(player, "Gain: " + te7.getStatGain());
		IC2.platform.messagePlayer(player, "Resistance: " + te7.getStatResistance());
		IC2.platform.messagePlayer(player, "Nutrients: " + te7.getTerrainNutrients());
		IC2.platform.messagePlayer(player, "Water: " + te7.getTerrainHumidity());
		IC2.platform.messagePlayer(player, "Growth Points: " + te7.getGrowthPoints());
	}
	if (tileEntity instanceof IEnergySink) {
		IEnergySink euSink = (IEnergySink) tileEntity;
		IC2.platform.messagePlayer(player, "Input Tier: " + euSink.getSinkTier());
		IC2.platform.messagePlayer(player, "Input Max: " + EnergyNet.instance.getPowerFromTier(euSink.getSinkTier())
				+ " EU");
	}
	if (tileEntity instanceof GTTileBaseMachine) {
		GTTileBaseMachine machine = (GTTileBaseMachine) tileEntity;
		IC2.platform.messagePlayer(player, "Usage: " + (double) machine.defaultEnergyConsume + " EU Per Tick");
	}
	if (tileEntity instanceof IEUStorage) {
		IEUStorage euStorage = (IEUStorage) tileEntity;
		IC2.platform.messagePlayer(player, "Stored: " + euStorage.getStoredEU() + " EU");
		IC2.platform.messagePlayer(player, "Storage Max: " + euStorage.getMaxEU() + " EU");
	}
	if (tileEntity instanceof IEnergyStorage) {
		IEnergyStorage te4 = (IEnergyStorage) tileEntity;
		IC2.platform.messagePlayer(player, "Output Tier: "
				+ EnergyNet.instance.getTierFromPower(te4.getOutputEnergyUnitsPerTick()));
		IC2.platform.messagePlayer(player, "Output: " + te4.getOutputEnergyUnitsPerTick() + " EU");
	}
	if (tileEntity instanceof IEnergySource) {
		IEnergySource euSource = (IEnergySource) tileEntity;
		IC2.platform.messagePlayer(player, "Output Source Tier: " + euSource.getSourceTier());
		IC2.platform.messagePlayer(player, "Output Source Max: "
				+ EnergyNet.instance.getPowerFromTier(euSource.getSourceTier()) + " EU");
		IC2.platform.messagePlayer(player, "Output Source Actual: " + euSource.getOfferedEnergy() + " EU");
	}
	if (tileEntity instanceof IProgressMachine) {
		IProgressMachine progress = (IProgressMachine) tileEntity;
		IC2.platform.messagePlayer(player, "Progress: "
				+ +(Math.round((progress.getProgress() / progress.getMaxProgress()) * 100)) + "%");
	}
	if (GTBedrockOreHandler.isBedrockOre(block)) {
		ItemStack resource = GTBedrockOreHandler.getResource(block);
		String amount = resource.getCount() > 1 ? " x " + resource.getCount() : "";
		IC2.platform.messagePlayer(player, "Contains: " + GTBedrockOreHandler.getResource(block).getDisplayName()
				+ amount);
	}
	if (tileEntity instanceof IGTMultiTileStatus) {
		IGTMultiTileStatus multi = (IGTMultiTileStatus) tileEntity;
		IC2.platform.messagePlayer(player, "Correct Strucuture: " + multi.getStructureValid());
	}
	if (tileEntity instanceof IGTDebuggableTile) {
		LinkedHashMap<String, Boolean> data = new LinkedHashMap<>();
		IGTDebuggableTile debug = (IGTDebuggableTile) tileEntity;
		debug.getData(data);
		for (Map.Entry<String, Boolean> entry : data.entrySet()) {
			IC2.platform.messagePlayer(player, entry.getKey());
		}
	}
	return EnumActionResult.SUCCESS;
}