Search in sources :

Example 46 with BlockState

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

the class IOHelper method getInventoryForTE.

public static IInventory getInventoryForTE(TileEntity te) {
    if (te instanceof IInventory) {
        IInventory inv = (IInventory) te;
        BlockState block = te.getBlockState();
        if (block.getBlock() instanceof ChestBlock) {
            inv = (IInventory) ((ChestBlock) block.getBlock()).getMenuProvider(block, te.getLevel(), te.getBlockPos());
        }
        return inv;
    } else {
        return null;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) BlockState(net.minecraft.block.BlockState) ChestBlock(net.minecraft.block.ChestBlock)

Example 47 with BlockState

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

the class BlockContainerFacingBase 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 48 with BlockState

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

the class RenderEngine method render.

@Override
public void render(TileEngine engine, float f, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int i, int i1) {
    World world = engine.getLevel();
    BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
    BlockPos pos = engine.getBlockPos();
    BlockState state = BPBlocks.engine.defaultBlockState().setValue(BlockEngine.FACING, engine.getOrientation());
    Direction facing = engine.getOrientation();
    matrixStack.pushPose();
    float rotationX = 90.0F;
    float rotation = 0.0F;
    if (facing == Direction.NORTH) {
        matrixStack.translate(0, 1, 0);
        rotation = 0F;
    } else if (facing == Direction.SOUTH) {
        matrixStack.translate(1, 1, 1);
        rotation = 180F;
    } else if (facing == Direction.EAST) {
        matrixStack.translate(1, 1, 0);
        rotation = 90F;
    } else if (facing == Direction.WEST) {
        matrixStack.translate(0, 1, 1);
        rotation = -90F;
    } else if (facing == Direction.UP) {
        matrixStack.translate(0, 1, 1);
        rotationX = 180F;
    } else if (facing == Direction.DOWN) {
        rotationX = 0F;
    }
    matrixStack.mulPose(Vector3f.XP.rotationDegrees(rotationX));
    matrixStack.mulPose(Vector3f.ZP.rotationDegrees(rotation));
    matrixStack.pushPose();
    float f2 = 0;
    if (engine.isActive) {
        f += engine.pumpTick;
        if (engine.pumpSpeed > 0) {
            f /= engine.pumpSpeed;
        }
        f2 = ((float) (.5 - .5 * Math.cos(3.1415926535897931D * (double) f)) / 4);
    }
    matrixStack.translate(0, f2, 0);
    IBakedModel glider = dispatcher.getBlockModel(state.setValue(BlockEngine.GLIDER, true));
    // Render the glider
    IVertexBuilder builder = iRenderTypeBuffer.getBuffer(RenderType.cutout());
    dispatcher.getModelRenderer().renderModel(world, glider, state.setValue(BlockEngine.GLIDER, true), pos, matrixStack, builder, false, new Random(), 0, 0, EmptyModelData.INSTANCE);
    matrixStack.popPose();
    matrixStack.pushPose();
    matrixStack.translate(0.5, 0, 0.5);
    long angle = engine.isActive ? (System.currentTimeMillis() / 10) % 360 : 0;
    matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
    matrixStack.translate(-0.5, 0, -0.5);
    IBakedModel gear = dispatcher.getBlockModel(state.setValue(BlockEngine.GEAR, true));
    // Render the rotating cog
    dispatcher.getModelRenderer().renderModel(world, gear, state.setValue(BlockEngine.GEAR, true), pos, matrixStack, iRenderTypeBuffer.getBuffer(RenderType.cutout()), false, new Random(), 0, 0, EmptyModelData.INSTANCE);
    matrixStack.popPose();
    matrixStack.popPose();
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.model.IBakedModel) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 49 with BlockState

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

the class TileBPMicroblock method markDirtyClient.

private void markDirtyClient() {
    setChanged();
    if (getLevel() != null) {
        BlockState state = getLevel().getBlockState(getBlockPos());
        getLevel().sendBlockUpdated(getBlockPos(), state, state, 3);
    }
}
Also used : BlockState(net.minecraft.block.BlockState)

Example 50 with BlockState

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

the class ItemSickle method mineBlock.

@Override
public boolean mineBlock(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity entityLiving) {
    boolean used = false;
    if (!(entityLiving instanceof PlayerEntity))
        return false;
    PlayerEntity player = (PlayerEntity) entityLiving;
    if (state.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || state.getBlock() instanceof LeavesBlock) {
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                for (int k = -1; k <= 1; k++) {
                    BlockState blockToCheck = world.getBlockState(pos.offset(i, j, k));
                    if (blockToCheck.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || blockToCheck.getBlock() instanceof LeavesBlock) {
                        if (blockToCheck.canHarvestBlock(world, pos.offset(i, j, k), player)) {
                            world.destroyBlock(pos.offset(i, j, k), true);
                        }
                        used = true;
                    }
                }
            }
        }
        if (used) {
            stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
        }
        return used;
    }
    if ((state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                BlockState meta = world.getBlockState(pos.offset(i, 0, j));
                if (blockToCheck instanceof LilyPadBlock) {
                    if (blockToCheck.canHarvestBlock(meta, world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (!(state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                if (blockToCheck instanceof BushBlock && !(blockToCheck instanceof LilyPadBlock)) {
                    if (blockToCheck.canHarvestBlock(world.getBlockState(pos.offset(i, 0, j)), world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (used) {
        stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
    }
    return used;
}
Also used : BushBlock(net.minecraft.block.BushBlock) BlockState(net.minecraft.block.BlockState) LilyPadBlock(net.minecraft.block.LilyPadBlock) ResourceLocation(net.minecraft.util.ResourceLocation) BushBlock(net.minecraft.block.BushBlock) LilyPadBlock(net.minecraft.block.LilyPadBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

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