net.minecraft.block.BlockState Java Examples

The following examples show how to use net.minecraft.block.BlockState. 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: CoalGeneratorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Environment(EnvType.CLIENT)
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos blockPos_1, Random rand) {
    if (world.getBlockEntity(blockPos_1) instanceof CoalGeneratorBlockEntity && ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.ACTIVE || ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.WARMING) {
        double x = (double) blockPos_1.getX() + 0.5D;
        double y = blockPos_1.getY();
        double z = (double) blockPos_1.getZ() + 0.5D;
        if (rand.nextDouble() < 0.1D) {
            world.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
        }

        Direction direction_1 = state.get(FACING);
        Direction.Axis direction$Axis_1 = direction_1.getAxis();
        double d = rand.nextDouble() * 0.6D - 0.3D;
        double xo = direction$Axis_1 == Direction.Axis.X ? (double) direction_1.getOffsetX() * 0.52D : d;
        double yo = rand.nextDouble() * 6.0D / 16.0D;
        double zo = direction$Axis_1 == Direction.Axis.Z ? (double) direction_1.getOffsetZ() * 0.52D : d;
        world.addParticle(ParticleTypes.SMOKE, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D);
        world.addParticle(ParticleTypes.FLAME, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D);

    }
}
 
Example #2
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean tryFillWithFluid(IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1, FluidState fluidState_1) {
    return ((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1).getComponent(
            WrappingUtil.convert(iWorld_1),
            (Position) blockPos_1,
            Components.FLUID_COMPONENT
    ).map(container -> {
        FluidStack filled = FluidStack.of(WrappingUtil.convert(fluidState_1.getFluid()), 1000);
        FluidStack ret = container.insert(filled, true);
        if (ret.isEmpty()) {
            container.insert(filled);
            return true;
        } else {
            return false;
        }
    }).orElse(false);
}
 
Example #3
Source File: CompressorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
    super.onBreak(world, blockPos, blockState, playerEntity);

    BlockEntity blockEntity = world.getBlockEntity(blockPos);

    if (blockEntity != null) {
        if (blockEntity instanceof CompressorBlockEntity) {
            CompressorBlockEntity be = (CompressorBlockEntity) blockEntity;

            for (int i = 0; i < be.getInventory().getSize(); i++) {
                ItemStack itemStack = be.getInventory().getStack(i);

                if (!itemStack.isEmpty()) {
                    world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack.copy()));
                }
            }
        }
    }
}
 
Example #4
Source File: GratingBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public FluidState getFluidState(BlockState state) {
    FluidState state1 = Registry.FLUID.get(state.get(FLUID)).getDefaultState();
    if (state1.getEntries().containsKey(FlowableFluid.LEVEL)) {
        state1 = state1.with(FlowableFluid.LEVEL, state.get(FlowableFluid.LEVEL));
    }
    return state1;
}
 
Example #5
Source File: ObsidianBlock.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void scheduledTick(BlockState blockState_1, ServerWorld serverWorld_1, BlockPos blockPos_1, Random random_1)
{
    for (Direction dir : Direction.values())
    {
        FluidState neighbor = serverWorld_1.getFluidState(blockPos_1.offset(dir));
        if (neighbor.getFluid() != Fluids.LAVA || !neighbor.isStill())
            return;
    }
    if (random_1.nextInt(10) == 0)
    {
        serverWorld_1.setBlockState(blockPos_1, Blocks.LAVA.getDefaultState());
    }
}
 
Example #6
Source File: HallowedGateBlock.java    From the-hallow with MIT License 5 votes vote down vote up
public static boolean isValid(World world, BlockPos pos, BlockState state) {
	if (state.getBlock() != HallowedBlocks.HALLOWED_GATE) return false;
	for (int x = -1; x < 2; x++) {
		for (int z = -1; z < 2; z++) {
			if (x == 0 && z == 0) continue;
			BlockState newState = world.getBlockState(pos.add(x, 0, z));
			if (!HallowedTags.Blocks.GATE_CIRCLE.contains(newState.getBlock())) return false;
		}
	}
	return true;
}
 
Example #7
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileFrequencyOwner) {
        return ((TileFrequencyOwner) tile).getLightValue();
    }
    return 0;
}
 
Example #8
Source File: GetAmbientOcclusionLightLevelListener.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
public GetAmbientOcclusionLightLevelEvent(BlockState state,
	float lightLevel)
{
	this.state = state;
	this.lightLevel = lightLevel;
	defaultLightLevel = lightLevel;
}
 
Example #9
Source File: AluminumWireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext context) {
    ArrayList<VoxelShape> shapes = new ArrayList<>();

    if (blockState.get(ATTACHED_NORTH)) {
        shapes.add(NORTH);
    }
    if (blockState.get(ATTACHED_SOUTH)) {
        shapes.add(SOUTH);
    }
    if (blockState.get(ATTACHED_EAST)) {
        shapes.add(EAST);
    }
    if (blockState.get(ATTACHED_WEST)) {
        shapes.add(WEST);
    }
    if (blockState.get(ATTACHED_UP)) {
        shapes.add(UP);
    }
    if (blockState.get(ATTACHED_DOWN)) {
        shapes.add(DOWN);
    }
    if (shapes.isEmpty()) {
        return NONE;
    } else {
        return VoxelShapes.union(NONE, shapes.toArray(new VoxelShape[0]));
    }
}
 
Example #10
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BlockState rotate(BlockState blockState_1, BlockRotation blockRotation_1) {
    return WrappingUtil.convert(block.rotate(
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            WrappingUtil.convert(blockRotation_1)
    ));
}
 
Example #11
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@link Block#addHitEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 * Use the default PerspectiveModel implementations inside CCL, Destroy effects will just be handled for you.
 *
 * @param world   The world.
 * @param pos     The position of the block.
 * @param manager The ParticleManager.
 * @return True if particles were added, basically just return the result of this method inside {@link Block#addHitEffects}
 */
@OnlyIn (Dist.CLIENT)
public static boolean handleDestroyEffects(World world, BlockPos pos, BlockState state, ParticleManager manager) {
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        Cuboid6 bounds = new Cuboid6(state.getShape(world, pos).getBoundingBox());
        addBlockDestroyEffects(world, bounds.add(pos), new ArrayList<>(((IModelParticleProvider) model).getDestroyEffects(state, world, pos, modelData)), manager);
        return true;
    }
    return false;
}
 
Example #12
Source File: AluminumWireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction_1, BlockState blockState_2, WorldAccess world, BlockPos thisWire, BlockPos otherConnectable) {
    return state.with(getPropForDirection(direction_1), (
            !(blockState_2).isAir()
                    && blockState_2.getBlock() instanceof WireConnectable
                    // get opposite of direction so the WireConnectable can check from its perspective.
                    && (((WireConnectable) blockState_2.getBlock()).canWireConnect(world, direction_1.getOpposite(), thisWire, otherConnectable) != WireConnectionType.NONE)
    ));
}
 
Example #13
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BlockState getStateForNeighborUpdate(BlockState blockState_1, Direction direction_1, BlockState blockState_2, IWorld iWorld_1, BlockPos blockPos_1, BlockPos blockPos_2) {
    return WrappingUtil.convert(block.updateOnNeighborChanged(
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1, WrappingUtil.convert(direction_1), (org.sandboxpowered.sandbox.api.state.BlockState) blockState_2, (org.sandboxpowered.sandbox.api.world.World) iWorld_1.getWorld(),
            (Position) blockPos_1,
            (Position) blockPos_2
    ));
}
 
Example #14
Source File: BlockEnderChest.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
    VoxelShape shape = CHEST_SHAPE;
    TileEntity t = worldIn.getTileEntity(pos);
    if (t instanceof TileEnderChest) {
        TileEnderChest tile = (TileEnderChest) t;
        shape = SHAPES[tile.rotation][tile.getRadianLidAngle(0) >= 0 ? 0 : 1];
    }
    return shape;
}
 
Example #15
Source File: RedstoneWireBlockMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
/**
 * @author theosib, soykaf, gnembon
 */
@Inject(method = "updateLogic", at = @At("HEAD"), cancellable = true)
private void updateLogicAlternative(World world, BlockPos pos, BlockState state, CallbackInfoReturnable<BlockState> cir)
{
    if (CarpetSettings.fastRedstoneDust)
        cir.setReturnValue(updateLogicPublic(world, pos, state));
}
 
Example #16
Source File: BlockEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
    VoxelShape shape = TANK_SHAPE;
    TileEntity t = worldIn.getTileEntity(pos);
    if (t instanceof TileEnderTank) {
        TileEnderTank tile = (TileEnderTank) t;
        shape = SHAPES[tile.rotation];
    }
    return shape;
}
 
Example #17
Source File: WitchWaterBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void onEntityCollision(BlockState blockState, World world, BlockPos pos, Entity entity) {
	if(!world.isClient) {
		if (entity instanceof LivingEntity) {
			LivingEntity livingEntity = (LivingEntity) entity;
			if (!livingEntity.isUndead() && !(livingEntity instanceof PumpcownEntity) && !(livingEntity instanceof WitchEntity)) {
				livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.POISON, 100));
				livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 100));
				livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 100));
			}
			if (pos.equals(entity.getBlockPos())) {
				if (entity.getType() == EntityType.SKELETON) {
					WitherSkeletonEntity witherSkeletonEntity = new WitherSkeletonEntity(EntityType.WITHER_SKELETON, world);
					witherSkeletonEntity.copyPositionAndRotation(entity);
					entity.remove();

					world.spawnEntity(witherSkeletonEntity);
				} else if (entity.getType() == EntityType.SPIDER) {
					CaveSpiderEntity caveSpiderEntity = new CaveSpiderEntity(EntityType.CAVE_SPIDER, world);
					caveSpiderEntity.copyPositionAndRotation(entity);
					entity.remove();

					world.spawnEntity(caveSpiderEntity);
				} else if (entity.getType() == EntityType.COW) {
					PumpcownEntity pumpcownEntity = new PumpcownEntity(HallowedEntities.PUMPCOWN, world);
					pumpcownEntity.copyPositionAndRotation(entity);
					entity.remove();

					world.spawnEntity(pumpcownEntity);
				} else if (entity.getType() == EntityType.VILLAGER && world.getDifficulty() != Difficulty.PEACEFUL) {
					WitchEntity witchEntity = new WitchEntity(EntityType.WITCH, world);
					witchEntity.copyPositionAndRotation(entity);
					entity.remove();

					world.spawnEntity(witchEntity);
				}
			}
		}
	}

	super.onEntityCollision(blockState, world, pos, entity);
}
 
Example #18
Source File: RestlessCactusBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState state2, IWorld world, BlockPos pos, BlockPos pos2) {
	if (!state.canPlaceAt(world, pos)) {
		world.getBlockTickScheduler().schedule(pos, this, 1);
	}
	
	return super.getStateForNeighborUpdate(state, direction, state2, world, pos, pos2);
}
 
Example #19
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static BlockRayTraceResult retraceBlock(IBlockReader world, PlayerEntity player, BlockPos pos) {
    Vec3d startVec = getStartVec(player);
    Vec3d endVec = getEndVec(player);
    BlockState state = world.getBlockState(pos);
    VoxelShape baseShape = state.getShape(world, pos);
    BlockRayTraceResult baseTraceResult = baseShape.rayTrace(startVec, endVec, pos);
    if (baseTraceResult != null) {
        BlockRayTraceResult raytraceTraceShape = state.getRaytraceShape(world, pos).rayTrace(startVec, endVec, pos);
        if (raytraceTraceShape != null) {
            return raytraceTraceShape;
        }
    }
    return baseTraceResult;
}
 
Example #20
Source File: GratingBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
    FluidState fluidState = context.getWorld().getFluidState(context.getBlockPos());
    BlockState blockState = this.getDefaultState().with(GRATING_STATE, GratingState.LOWER)
            .with(FLUID, Registry.FLUID.getId(fluidState.getFluid()))
            .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1));
    BlockPos blockPos = context.getBlockPos();
    Direction direction = context.getPlayerFacing();

    return direction != Direction.DOWN && (direction == Direction.UP || context.getBlockPos().getY() - (double) blockPos.getY() <= 0.5D) ? blockState : blockState.with(GRATING_STATE, GratingState.UPPER);
}
 
Example #21
Source File: MixinBlockModelRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void render(BlockRenderView blockRenderView_1, BakedModel bakedModel_1, BlockState blockState_1, BlockPos blockPos_1, MatrixStack matrixStack_1, VertexConsumer vertexConsumer_1, boolean boolean_1, Random random_1, long long_1, int int_1, CallbackInfoReturnable<Boolean> ci) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (!xray.isVisible(blockState_1.getBlock())) {
            ci.setReturnValue(false);
            ci.cancel();
        }
    } catch (Exception ignored) {}
}
 
Example #22
Source File: AbstractBlockStateMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("TAIL")},
	method = {
		"getAmbientOcclusionLightLevel(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F"},
	cancellable = true)
private void onGetAmbientOcclusionLightLevel(BlockView blockView,
	BlockPos blockPos, CallbackInfoReturnable<Float> cir)
{
	GetAmbientOcclusionLightLevelEvent event =
		new GetAmbientOcclusionLightLevelEvent((BlockState)(Object)this,
			cir.getReturnValueF());
	
	WurstClient.INSTANCE.getEventManager().fire(event);
	cir.setReturnValue(event.getLightLevel());
}
 
Example #23
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public static void interactEvent(PlayerInteractEvent.LeftClickBlock event)
{
    PlayerEntity player = event.getPlayer();
    World world = player.world;
    BlockPos pos = event.getPos();
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof ChoppingBlock)
    {
        if (((ChoppingBlock) block).interceptClick(world, pos, state, player))
            event.setCanceled(true);
    }
}
 
Example #24
Source File: BasicSolarPanelBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void appendProperties(StateManager.Builder<Block, BlockState> stateBuilder) {
    super.appendProperties(stateBuilder);
    stateBuilder.add(FACING);

    stateBuilder.add(FRONT_SIDE_OPTION);
    stateBuilder.add(BACK_SIDE_OPTION);
    stateBuilder.add(RIGHT_SIDE_OPTION);
    stateBuilder.add(LEFT_SIDE_OPTION);
    stateBuilder.add(TOP_SIDE_OPTION);
    stateBuilder.add(BOTTOM_SIDE_OPTION);
}
 
Example #25
Source File: BlockTagCondition.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean test(LootContext lootContext)
{
    BlockState state = lootContext.get(LootParameters.BLOCK_STATE);
    if (state == null)
        return false;
    return blockTag.func_230235_a_(state.getBlock());
}
 
Example #26
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileFrequencyOwner) {
        ((TileFrequencyOwner) tile).onNeighborChange(fromPos);
    }
}
 
Example #27
Source File: SawmillTileEntity.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void func_230337_a_(BlockState state, CompoundNBT compound)
{
    super.func_230337_a_(state, compound);

    ITEMS_CAP.readNBT(inventory, null, compound.get("Items"));

    remainingBurnTime = compound.getInt("BurnTime");
    cookTime = compound.getInt("CookTime");
    needRefreshRecipe = true;
}
 
Example #28
Source File: BasicSolarPanelBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public boolean canPlaceAt(BlockState blockState_1, WorldView WorldView_1, BlockPos blockPos_1) {
    for (BlockPos otherPart : getOtherParts(blockState_1, blockPos_1)) {
        if (!WorldView_1.getBlockState(otherPart).getMaterial().isReplaceable()) {
            return false;
        }
    }
    return super.canPlaceAt(blockState_1, WorldView_1, blockPos_1);
}
 
Example #29
Source File: ScorchedRockBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
    double x = (double) pos.getX() + random.nextDouble() * 0.10000000149011612D;
    double y = (double) pos.getY() + random.nextDouble();
    double z = (double) pos.getZ() + random.nextDouble();

    world.addParticle(ParticleTypes.LARGE_SMOKE, x, y, z, 0.0D, 0.0D, 0.0D);
}
 
Example #30
Source File: AbstractProtocol.java    From multiconnect with MIT License 5 votes vote down vote up
protected void recomputeStatesForBlock(Block block) {
    for (BlockState state : block.getStateManager().getStates()) {
        if (acceptBlockState(state)) {
            Block.STATE_IDS.add(state);
        }
    }
}