Search in sources :

Example 21 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class BlockContainerFacingBase method setState.

public static void setState(Direction facing, World worldIn, BlockPos pos) {
    BlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getBlockEntity(pos);
    worldIn.setBlock(pos, iblockstate.setValue(FACING, facing), 3);
    if (tileentity != null) {
        tileentity.clearRemoved();
        worldIn.setBlockEntity(pos, tileentity);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState)

Example 22 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class BlockContainerHorizontalFacingBase method setState.

public static void setState(boolean active, World worldIn, BlockPos pos) {
    BlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getBlockEntity(pos);
    worldIn.setBlock(pos, iblockstate.setValue(ACTIVE, active), 3);
    if (tileentity != null) {
        tileentity.clearRemoved();
        worldIn.setBlockEntity(pos, tileentity);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState)

Example 23 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class BlockContainerHorizontalFacingBase method setState.

public static void setState(Direction facing, World worldIn, BlockPos pos) {
    BlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getBlockEntity(pos);
    worldIn.setBlock(pos, iblockstate.setValue(FACING, facing), 3);
    if (tileentity != null) {
        tileentity.clearRemoved();
        worldIn.setBlockEntity(pos, tileentity);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState)

Example 24 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class BluePowerAPI method loadSilkySettings.

@Override
public void loadSilkySettings(World world, BlockPos pos, ItemStack stack) {
    TileEntity te = world.getBlockEntity(pos);
    BlockState blockState = world.getBlockState(pos);
    if (te == null)
        throw new IllegalStateException("This block doesn't have a tile entity?!");
    if (stack.isEmpty())
        throw new IllegalArgumentException("ItemStack is empty!");
    if (stack.hasTag()) {
        CompoundNBT tag = stack.getTag();
        if (tag.contains("tileData")) {
            if (te instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) te).readSilkyData(world, pos, tag.getCompound("tileData"));
            } else if (blockState.getBlock() instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) blockState.getBlock()).readSilkyData(world, pos, tag.getCompound("tileData"));
            } else {
                CompoundNBT tileTag = tag.getCompound("tileData");
                tileTag.putInt("x", pos.getX());
                tileTag.putInt("y", pos.getY());
                tileTag.putInt("z", pos.getZ());
                te.load(blockState, tileTag);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable)

Example 25 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class BPEventHandler method blockHighlightEvent.

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void blockHighlightEvent(DrawHighlightEvent event) {
    PlayerEntity player = Minecraft.getInstance().player;
    if (player == null) {
        return;
    }
    World world = player.level;
    if (world == null) {
        return;
    }
    RayTraceResult mop = event.getTarget();
    if (mop instanceof BlockRayTraceResult) {
        BlockPos pos = ((BlockRayTraceResult) mop).getBlockPos();
        BlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof BlockBPMultipart) {
            BlockState partstate = MultipartUtils.getClosestState(player, pos);
            IVertexBuilder builder = event.getBuffers().getBuffer(RenderType.lines());
            if (partstate != null) {
                VoxelShape shape = partstate.getShape(world, pos, ISelectionContext.of(player));
                Vector3d projectedView = event.getInfo().getPosition();
                double d0 = pos.getX() - projectedView.x();
                double d1 = pos.getY() - projectedView.y();
                double d2 = pos.getZ() - projectedView.z();
                Matrix4f matrix4f = event.getMatrix().last().pose();
                shape.forAllEdges((startX, startY, startZ, endX, endY, endZ) -> {
                    builder.vertex(matrix4f, (float) (startX + d0), (float) (startY + d1), (float) (startZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                    builder.vertex(matrix4f, (float) (endX + d0), (float) (endY + d1), (float) (endZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                });
                event.setCanceled(true);
            }
        }
    }
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

BlockState (net.minecraft.block.BlockState)79 BlockPos (net.minecraft.util.math.BlockPos)32 TileEntity (net.minecraft.tileentity.TileEntity)19 Direction (net.minecraft.util.Direction)16 Nonnull (javax.annotation.Nonnull)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 World (net.minecraft.world.World)12 ChunkPos (net.minecraft.util.math.ChunkPos)11 Block (net.minecraft.block.Block)10 Nullable (javax.annotation.Nullable)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashSet (java.util.HashSet)4 Blocks (net.minecraft.block.Blocks)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 IForgeBlockState (net.minecraftforge.common.extensions.IForgeBlockState)4 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3