net.minecraft.block.Material Java Examples

The following examples show how to use net.minecraft.block.Material. 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: NukerLegitHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLeftClick(LeftClickEvent event)
{
	// check hitResult
	if(MC.crosshairTarget == null
		|| !(MC.crosshairTarget instanceof BlockHitResult))
		return;
	
	// check pos
	BlockPos pos = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
	if(pos == null
		|| BlockUtils.getState(pos).getMaterial() == Material.AIR)
		return;
	
	// check mode
	if(mode.getSelected() != Mode.ID)
		return;
	
	// set id
	WURST.getHax().nukerHack.setId(BlockUtils.getName(pos));
}
 
Example #2
Source File: SpeedNukerHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onLeftClick(LeftClickEvent event)
{
	// check hitResult
	if(MC.crosshairTarget == null
		|| !(MC.crosshairTarget instanceof BlockHitResult))
		return;
	
	// check pos
	BlockPos pos = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
	if(pos == null
		|| BlockUtils.getState(pos).getMaterial() == Material.AIR)
		return;
	
	// check mode
	if(mode.getSelected() != Mode.ID)
		return;
	
	// set id
	WURST.getHax().nukerHack.setId(BlockUtils.getName(pos));
}
 
Example #3
Source File: JesusHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
public boolean isOverLiquid()
{
	boolean foundLiquid = false;
	boolean foundSolid = false;
	
	// check collision boxes below player
	ArrayList<Box> blockCollisions = MC.world
		.getBlockCollisions(MC.player,
			MC.player.getBoundingBox().offset(0, -0.5, 0))
		.map(VoxelShape::getBoundingBox)
		.collect(Collectors.toCollection(() -> new ArrayList<>()));
	
	for(Box bb : blockCollisions)
	{
		BlockPos pos = new BlockPos(bb.getCenter());
		Material material = BlockUtils.getState(pos).getMaterial();
		
		if(material == Material.WATER || material == Material.LAVA)
			foundLiquid = true;
		else if(material != Material.AIR)
			foundSolid = true;
	}
	
	return foundLiquid && !foundSolid;
}
 
Example #4
Source File: RestlessCactusBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
	Iterator<Direction> iterator = Direction.Type.HORIZONTAL.iterator();
	
	Direction direction;
	Material material;
	do {
		if (!iterator.hasNext()) {
			Block block = world.getBlockState(pos.down()).getBlock();
			return (block == HallowedBlocks.RESTLESS_CACTUS || block == HallowedBlocks.TAINTED_SAND) && !world.getBlockState(pos.up()).getMaterial().isLiquid();
		}
		
		direction = iterator.next();
		BlockState state2 = world.getBlockState(pos.offset(direction));
		material = state2.getMaterial();
	} while (!material.isSolid() && !world.getFluidState(pos.offset(direction)).matches(FluidTags.LAVA));
	
	return false;
}
 
Example #5
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Use this to change the fog color used when the entity is "inside" a material.
 * {@link Vec3d} is used here as "r/g/b" 0 - 1 values.
 *
 * @param state         The state at the entity viewport.
 * @param world         The world.
 * @param pos           The position at the entity viewport.
 * @param entity        the entity
 * @param originalColor The current fog color, You are not expected to use this, Return as the default if applicable.
 * @return The new fog color.
 */
@Environment(EnvType.CLIENT)
default Vec3d getFogColor(BlockState state, CollisionView world, BlockPos pos, Entity entity, Vec3d originalColor, float partialTicks) {
	if (state.getMaterial() == Material.WATER) {
		float visibility = 0.0F;

		if (entity instanceof LivingEntity) {
			LivingEntity ent = (LivingEntity) entity;
			visibility = (float) EnchantmentHelper.getRespiration(ent) * 0.2F;

			if (ent.hasStatusEffect(StatusEffects.WATER_BREATHING)) {
				visibility = visibility * 0.3F + 0.6F;
			}
		}

		return new Vec3d(0.02F + visibility, 0.02F + visibility, 0.2F + visibility);
	} else if (state.getMaterial() == Material.LAVA) {
		return new Vec3d(0.6F, 0.1F, 0.0F);
	}

	return originalColor;
}
 
Example #6
Source File: CongealedBloodBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState state, BlockEntity be, ItemStack stack) {
	super.afterBreak(world, player, pos, state, be, stack);
	if (EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, stack) == 0) {
		Material material = world.getBlockState(pos.down()).getMaterial();
		if (material.blocksMovement() || material.isLiquid()) {
			world.setBlockState(pos, HallowedBlocks.BLOOD_BLOCK.getDefaultState());
		}
	}
}
 
Example #7
Source File: BlockSaplingHelper.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean hasWater(IWorld worldIn, BlockPos pos)
{
    for (BlockPos blockpos$mutableblockpos : BlockPos.iterate(pos.add(-4, -4, -4), pos.add(4, 1, 4)))
    {
        if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
        {
            return true;
        }
    }

    return false;
}
 
Example #8
Source File: WoolTool.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static DyeColor getWoolColorAtPosition(World worldIn, BlockPos pos)
{
    BlockState state = worldIn.getBlockState(pos);
    if (state.getMaterial() != Material.WOOL || !state.isSimpleFullBlock(worldIn, pos))
        return null;
    return Material2Dye.get(state.getTopMaterialColor(worldIn, pos));
}
 
Example #9
Source File: ShearsItem_missingToolsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "getMiningSpeed", at = @At("HEAD"), cancellable = true)
private void getCustomMaterial(ItemStack itemStack_1, BlockState blockState_1, CallbackInfoReturnable<Float> cir)
{
    if (CarpetSettings.missingTools && (blockState_1.getMaterial() == Material.SPONGE))
    {
        cir.setReturnValue(15.0F);
        cir.cancel();
    }
}
 
Example #10
Source File: PickaxeItem_missingToolsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "getMiningSpeed", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/BlockState;getMaterial()Lnet/minecraft/block/Material;"
))
private Material getCustomMaterial(BlockState blockState)
{
    Material material = blockState.getMaterial();
    if (CarpetSettings.missingTools && (material == Material.PISTON || material == Material.GLASS))
        material = Material.STONE;
    return material;
}
 
Example #11
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines if this block can support the passed in plant, allowing it to be planted and grow.
 * Some examples:
 * Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water
 * Cacti checks if its a cacti, or if its sand
 * Nether types check for soul sand
 * Crops check for tilled soil
 * Caves check if it's a solid surface
 * Plains check if its grass or dirt
 * Water check if its still water
 *
 * @param state     The Current state
 * @param world     The current world
 * @param facing    The direction relative to the given position the plant wants to be, typically its UP
 * @param plantable The plant that wants to check
 * @return True to allow the plant to be planted/stay.
 */
default boolean canSustainPlant(BlockState state, BlockView world, BlockPos pos, Direction facing, IPlantable plantable) {
	BlockState plant = plantable.getPlant(world, pos.offset(facing));

	if (plant.getBlock() == Blocks.CACTUS) {
		return this.getBlock() == Blocks.CACTUS || this.getBlock() == Blocks.SAND || this.getBlock() == Blocks.RED_SAND;
	}

	if (plant.getBlock() == Blocks.SUGAR_CANE && this.getBlock() == Blocks.SUGAR_CANE) {
		return true;
	}

	if (plantable instanceof PlantBlock && ((PlantBlockAccessor) plantable).invokeCanPlantOnTop(state, world, pos)) {
		return true;
	}

	switch (plantable.getPlantType(world, pos)) {
	case Desert:
		return this.getBlock() == Blocks.SAND || this.getBlock() == Blocks.TERRACOTTA || this.getBlock() instanceof GlazedTerracottaBlock;
	case Nether:
		return this.getBlock() == Blocks.SOUL_SAND;
	case Crop:
		return this.getBlock() == Blocks.FARMLAND;
	case Cave:
		return Block.isSideSolidFullSquare(state, world, pos, Direction.UP);
	case Plains:
		return this.getBlock() == Blocks.GRASS_BLOCK || Block.isNaturalDirt(this.getBlock()) || this.getBlock() == Blocks.FARMLAND;
	case Water:
		return state.getMaterial() == Material.WATER;
	case Beach:
		boolean isBeach = this.getBlock() == Blocks.GRASS_BLOCK || Block.isNaturalDirt(this.getBlock()) || this.getBlock() == Blocks.SAND;
		boolean hasWater = (world.getBlockState(pos.east()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.west()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.north()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.south()).getMaterial() == Material.WATER);
		return isBeach && hasWater;
	}

	return false;
}
 
Example #12
Source File: BlocksMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "<clinit>",
    slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=obsidian")),
    at = @At(value = "INVOKE",
        target = "Lnet/minecraft/block/Blocks;register(Ljava/lang/String;Lnet/minecraft/block/Block;)Lnet/minecraft/block/Block;",
        ordinal = 0))
private static Block registerObsidian(String id, Block obsidian)
{
    return register("obsidian", new ObsidianBlock(Block.Settings.of(Material.STONE, MaterialColor.BLACK).strength(50.0F, 1200.0F)));
}
 
Example #13
Source File: GlideHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	ClientPlayerEntity player = MC.player;
	Vec3d v = player.getVelocity();
	
	if(player.isOnGround() || player.isTouchingWater() || player.isInLava()
		|| player.isClimbing() || v.y >= 0)
		return;
	
	if(minHeight.getValue() > 0)
	{
		Box box = player.getBoundingBox();
		box = box.union(box.offset(0, -minHeight.getValue(), 0));
		if(!MC.world.doesNotCollide(box))
			return;
		
		BlockPos min =
			new BlockPos(new Vec3d(box.minX, box.minY, box.minZ));
		BlockPos max =
			new BlockPos(new Vec3d(box.maxX, box.maxY, box.maxZ));
		Stream<BlockPos> stream = StreamSupport
			.stream(BlockUtils.getAllInBox(min, max).spliterator(), true);
		
		// manual collision check, since liquids don't have bounding boxes
		if(stream.map(BlockUtils::getState).map(BlockState::getMaterial)
			.anyMatch(Material::isLiquid))
			return;
	}
	
	player.setVelocity(v.x, Math.max(v.y, -fallSpeed.getValue()), v.z);
	player.flyingSpeed *= moveSpeed.getValueF();
}
 
Example #14
Source File: Pony.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public boolean isPartiallySubmerged(LivingEntity entity) {
    return entity.isSubmergedInWater()
            || entity.getEntityWorld().getBlockState(entity.getBlockPos()).getMaterial() == Material.WATER;
}
 
Example #15
Source File: Pony.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public boolean isFullySubmerged(LivingEntity entity) {
    return entity.isSubmergedInWater()
            && entity.getEntityWorld().getBlockState(new BlockPos(getVisualEyePosition(entity))).getMaterial() == Material.WATER;
}
 
Example #16
Source File: OptimizedExplosion.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static void blastCalc(Explosion e){
    ExplosionAccessor eAccess = (ExplosionAccessor) e;
    if(blastChanceLocation == null || blastChanceLocation.getSquaredDistance(eAccess.getX(), eAccess.getY(), eAccess.getZ(), false) > 200) return;
    chances.clear();
    for (int j = 0; j < 16; ++j) {
        for (int k = 0; k < 16; ++k) {
            for (int l = 0; l < 16; ++l) {
                if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                    double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
                    double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
                    double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 = d0 / d3;
                    d1 = d1 / d3;
                    d2 = d2 / d3;
                    float f = eAccess.getPower() * (0.7F + 0.6F);
                    double d4 = eAccess.getX();
                    double d6 = eAccess.getY();
                    double d8 = eAccess.getZ();
                    boolean found = false;

                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        BlockState state = eAccess.getWorld().getBlockState(blockpos);
                        FluidState fluidState = eAccess.getWorld().getFluidState(blockpos);

                        if (state.getMaterial() != Material.AIR) {
                            float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance());
                            if (eAccess.getEntity() != null)
                                f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2);
                            f -= (f2 + 0.3F) * 0.3F;
                        }

                        if (f > 0.0F && (eAccess.getEntity() == null ||
                                eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f))) {
                            if(!found && blockpos.equals(blastChanceLocation)){
                                chances.add(f);
                                found = true;
                            }
                        }

                        d4 += d0 * 0.30000001192092896D;
                        d6 += d1 * 0.30000001192092896D;
                        d8 += d2 * 0.30000001192092896D;
                    }
                }
            }
        }
    }

    showTNTblastChance(e);
}
 
Example #17
Source File: OptimizedExplosion.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static boolean checkAffectedPosition(Explosion e, double xRel, double yRel, double zRel)
{
    ExplosionAccessor eAccess = (ExplosionAccessor) e;
    double len = Math.sqrt(xRel * xRel + yRel * yRel + zRel * zRel);
    double xInc = (xRel / len) * 0.3;
    double yInc = (yRel / len) * 0.3;
    double zInc = (zRel / len) * 0.3;
    float rand = eAccess.getWorld().random.nextFloat();
    float sizeRand = (CarpetSettings.tntRandomRange >= 0 ? (float) CarpetSettings.tntRandomRange : rand);
    float size = eAccess.getPower() * (0.7F + sizeRand * 0.6F);
    double posX = eAccess.getX();
    double posY = eAccess.getY();
    double posZ = eAccess.getZ();

    for (float f1 = 0.3F; size > 0.0F; size -= 0.22500001F)
    {
        posMutable.set(posX, posY, posZ);

        // Don't query already cached positions again from the world
        BlockState state = stateCache.get(posMutable);
        FluidState fluid = fluidCache.get(posMutable);
        BlockPos posImmutable = null;

        if (state == null)
        {
            posImmutable = posMutable.toImmutable();
            state = eAccess.getWorld().getBlockState(posImmutable);
            stateCache.put(posImmutable, state);
            fluid = eAccess.getWorld().getFluidState(posImmutable);
            fluidCache.put(posImmutable, fluid);
        }

        if (state.getMaterial() != Material.AIR)
        {
            float resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance());

            if (eAccess.getEntity() != null)
            {
                resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), posMutable, state, fluid, resistance);
            }

            size -= (resistance + 0.3F) * 0.3F;
        }

        if (size > 0.0F && (eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), posMutable, state, size)))
        {
            affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.toImmutable());
        }
        else if (firstRay)
        {
            rayCalcDone = true;
            return true;
        }

        firstRay = false;

        posX += xInc;
        posY += yInc;
        posZ += zInc;
    }

    return false;
}
 
Example #18
Source File: OptimizedExplosion.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static void rayCalcs(Explosion e) {
    ExplosionAccessor eAccess = (ExplosionAccessor) e;
    boolean first = true;

    for (int j = 0; j < 16; ++j) {
        for (int k = 0; k < 16; ++k) {
            for (int l = 0; l < 16; ++l) {
                if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                    double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
                    double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
                    double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 = d0 / d3;
                    d1 = d1 / d3;
                    d2 = d2 / d3;
                    float rand = eAccess.getWorld().random.nextFloat();
                    if (CarpetSettings.tntRandomRange >= 0) {
                        rand = (float) CarpetSettings.tntRandomRange;
                    }
                    float f = eAccess.getPower() * (0.7F + rand * 0.6F);
                    double d4 = eAccess.getX();
                    double d6 = eAccess.getY();
                    double d8 = eAccess.getZ();

                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        BlockState state = eAccess.getWorld().getBlockState(blockpos);
                        FluidState fluidState = eAccess.getWorld().getFluidState(blockpos);

                        if (state.getMaterial() != Material.AIR) {
                            float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance());
                            if (eAccess.getEntity() != null)
                                f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2);
                            f -= (f2 + 0.3F) * 0.3F;
                        }

                        if (f > 0.0F && (eAccess.getEntity() == null ||
                                eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f)))
                        {
                            affectedBlockPositionsSet.add(blockpos);
                        }
                        else if (first) {
                            return;
                        }

                        first = false;

                        d4 += d0 * 0.30000001192092896D;
                        d6 += d1 * 0.30000001192092896D;
                        d8 += d2 * 0.30000001192092896D;
                    }
                }
            }
        }
    }
}
 
Example #19
Source File: WorldUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isFluid(BlockPos pos) {
List<Material> fluids = Arrays.asList(Material.WATER, Material.LAVA, Material.SEAGRASS);

      return fluids.contains(MinecraftClient.getInstance().world.getBlockState(pos).getMaterial());
  }
 
Example #20
Source File: WorldUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isFluid(BlockPos pos) {
List<Material> fluids = Arrays.asList(Material.WATER, Material.LAVA, Material.UNDERWATER_PLANT);

      return fluids.contains(MinecraftClient.getInstance().world.getBlockState(pos).getMaterial());
  }
 
Example #21
Source File: WorldUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isFluid(BlockPos pos) {
List<Material> fluids = Arrays.asList(Material.WATER, Material.LAVA, Material.SEAGRASS);

      return fluids.contains(MinecraftClient.getInstance().world.getBlockState(pos).getMaterial());
  }
 
Example #22
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static org.sandboxpowered.sandbox.api.block.Material convert(Material material) {
    return castOrWrap(material, org.sandboxpowered.sandbox.api.block.Material.class, m -> null);
}
 
Example #23
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Material convert(org.sandboxpowered.sandbox.api.block.Material material) {
    return castOrWrap(material, Material.class, m -> null);
}
 
Example #24
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static org.sandboxpowered.sandbox.api.block.Material.PistonInteraction convert(PistonBehavior behavior) {
    return org.sandboxpowered.sandbox.api.block.Material.PistonInteraction.values()[behavior.ordinal()];
}
 
Example #25
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static PistonBehavior convert(org.sandboxpowered.sandbox.api.block.Material.PistonInteraction interaction) {
    return PistonBehavior.values()[interaction.ordinal()];
}
 
Example #26
Source File: DummyBlock.java    From multiconnect with MIT License 4 votes vote down vote up
DummyBlock(BlockState original) {
    super(Block.Settings.of(Material.AIR));
    this.original = original;
}
 
Example #27
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Determines this block should be treated as an air block
 * by the rest of the code. This method is primarily
 * useful for creating pure logic-blocks that will be invisible
 * to the player and otherwise interact as air would.
 *
 * @param state The current state
 * @param world The current world
 * @param pos   Block position in world
 * @return True if the block considered air
 */
default boolean isAir(BlockState state, BlockView world, BlockPos pos) {
	return state.getMaterial() == Material.AIR;
}