Search in sources :

Example 1 with VoxelShape

use of net.minecraft.util.math.shapes.VoxelShape 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)

Example 2 with VoxelShape

use of net.minecraft.util.math.shapes.VoxelShape in project BluePower by Qmunity.

the class AABBUtils method rotate.

public static VoxelShape rotate(VoxelShape shape, Direction facing) {
    VoxelShape out = VoxelShapes.empty();
    for (AxisAlignedBB aabb : shape.toAabbs()) {
        aabb = rotate(aabb, facing);
        out = VoxelShapes.or(out, Block.box(aabb.minX * 16, aabb.minY * 16, aabb.minZ * 16, aabb.maxX * 16, aabb.maxY * 16, aabb.maxZ * 16));
    }
    return out;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) VoxelShape(net.minecraft.util.math.shapes.VoxelShape)

Example 3 with VoxelShape

use of net.minecraft.util.math.shapes.VoxelShape in project BluePower by Qmunity.

the class MicroblockRecipe method matches.

@Override
public boolean matches(CraftingInventory inv, World worldIn) {
    int blockCount = 0;
    int saw = 0;
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty()) {
            if (stack.getItem() instanceof BlockItem && (Block.byItem(stack.getItem()) instanceof BlockBPMicroblock || !Block.byItem(stack.getItem()).hasTileEntity(Block.byItem(stack.getItem()).defaultBlockState()))) {
                VoxelShape shape = null;
                try {
                    shape = Block.byItem(stack.getItem()).defaultBlockState().getShape(null, null);
                } catch (NullPointerException ignored) {
                // Shulker Boxes try to query the Tile Entity
                }
                if (shape == VoxelShapes.block() || Block.byItem(stack.getItem()) == BPBlocks.half_block || Block.byItem(stack.getItem()) == BPBlocks.panel) {
                    blockCount++;
                }
            } else if (stack.getItem() instanceof ItemSaw) {
                saw++;
            } else {
                return false;
            }
        }
    }
    return blockCount == 1 && saw == 1;
}
Also used : VoxelShape(net.minecraft.util.math.shapes.VoxelShape) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) ItemSaw(com.bluepowermod.item.ItemSaw) BlockBPMicroblock(com.bluepowermod.block.BlockBPMicroblock)

Example 4 with VoxelShape

use of net.minecraft.util.math.shapes.VoxelShape in project BluePower by Qmunity.

the class JEIPlugin method getMicroblockRecipes.

private static List<IRecipe<?>> getMicroblockRecipes() {
    List<IRecipe<?>> recipes = new ArrayList<>();
    for (Block block : ForgeRegistries.BLOCKS.getValues().stream().filter(b -> !b.hasTileEntity(b.defaultBlockState())).collect(Collectors.toList())) {
        VoxelShape shape = null;
        try {
            shape = block.defaultBlockState().getShape(null, null);
        } catch (NullPointerException ignored) {
        // Shulker Boxes try to query the Tile Entity
        }
        if (block.getRegistryName() != null && shape == VoxelShapes.block()) {
            ItemStack output = ItemStack.EMPTY;
            for (Block mb : BPBlocks.microblocks) {
                NonNullList<Ingredient> input = NonNullList.create();
                input.add(Ingredient.of(ItemTags.createOptional(new ResourceLocation("bluepower:saw"))));
                if (mb == BPBlocks.half_block) {
                    input.add(Ingredient.of(new ItemStack(block)));
                } else {
                    input.add(Ingredient.of(output));
                }
                CompoundNBT nbt = new CompoundNBT();
                nbt.putString("block", block.getRegistryName().toString());
                ItemStack stack = new ItemStack(mb);
                stack.setTag(nbt);
                stack.setHoverName(new TranslationTextComponent(block.getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(mb.getDescriptionId())));
                output = stack;
                recipes.add(new ShapelessRecipe(new ResourceLocation("bluepower:" + mb.getDescriptionId() + block.getDescriptionId()), "", output, input));
            }
        }
    }
    return recipes;
}
Also used : Refs(com.bluepowermod.reference.Refs) java.util(java.util) ContainerBlulectricAlloyFurnace(com.bluepowermod.container.ContainerBlulectricAlloyFurnace) GuiBlulectricAlloyFurnace(com.bluepowermod.client.gui.GuiBlulectricAlloyFurnace) Item(net.minecraft.item.Item) BPBlocks(com.bluepowermod.init.BPBlocks) CompoundNBT(net.minecraft.nbt.CompoundNBT) AlloyFurnaceRegistry(com.bluepowermod.recipe.AlloyFurnaceRegistry) net.minecraft.item.crafting(net.minecraft.item.crafting) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ContainerBlulectricFurnace(com.bluepowermod.container.ContainerBlulectricFurnace) ItemStack(net.minecraft.item.ItemStack) IAlloyFurnaceRecipe(com.bluepowermod.api.recipe.IAlloyFurnaceRecipe) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) IRecipeCategory(mezz.jei.api.recipe.category.IRecipeCategory) mezz.jei.api(mezz.jei.api) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) StringTextComponent(net.minecraft.util.text.StringTextComponent) NonNullList(net.minecraft.util.NonNullList) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) ContainerAlloyFurnace(com.bluepowermod.container.ContainerAlloyFurnace) ItemTags(net.minecraft.tags.ItemTags) ContainerProjectTable(com.bluepowermod.container.ContainerProjectTable) ItemStackUtils(com.bluepowermod.util.ItemStackUtils) mezz.jei.api.registration(mezz.jei.api.registration) Collectors(java.util.stream.Collectors) IJeiHelpers(mezz.jei.api.helpers.IJeiHelpers) GuiBlulectricFurnace(com.bluepowermod.client.gui.GuiBlulectricFurnace) ResourceLocation(net.minecraft.util.ResourceLocation) VoxelShapes(net.minecraft.util.math.shapes.VoxelShapes) BluePower(com.bluepowermod.BluePower) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) GuiAlloyFurnace(com.bluepowermod.client.gui.GuiAlloyFurnace) CompoundNBT(net.minecraft.nbt.CompoundNBT) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 5 with VoxelShape

use of net.minecraft.util.math.shapes.VoxelShape in project BluePower by Qmunity.

the class BlockBPCableBase method makeShapes.

private VoxelShape[] makeShapes(float width, float height) {
    float gap = 0;
    float f = 8.0F - width;
    float f1 = 8.0F + width;
    float f2 = 8.0F - width;
    float f3 = 8.0F + width;
    VoxelShape voxelshape = Block.box((double) f, 0, (double) f, (double) f1, (double) height, (double) f1);
    VoxelShape voxelshape1 = Block.box((double) f2, (double) gap, 0, (double) f3, (double) height, (double) f3);
    VoxelShape voxelshape2 = Block.box((double) f2, (double) gap, (double) f2, (double) f3, (double) height, 16.0D);
    VoxelShape voxelshape3 = Block.box(0, (double) gap, (double) f2, (double) f3, (double) height, (double) f3);
    VoxelShape voxelshape4 = Block.box((double) f2, (double) gap, (double) f2, 16.0D, (double) height, (double) f3);
    VoxelShape voxelshape5 = VoxelShapes.or(voxelshape1, voxelshape4);
    VoxelShape voxelshape6 = VoxelShapes.or(voxelshape2, voxelshape3);
    VoxelShape[] avoxelshape = new VoxelShape[] { VoxelShapes.empty(), voxelshape2, voxelshape3, voxelshape6, voxelshape1, VoxelShapes.or(voxelshape2, voxelshape1), VoxelShapes.or(voxelshape3, voxelshape1), VoxelShapes.or(voxelshape6, voxelshape1), voxelshape4, VoxelShapes.or(voxelshape2, voxelshape4), VoxelShapes.or(voxelshape3, voxelshape4), VoxelShapes.or(voxelshape6, voxelshape4), voxelshape5, VoxelShapes.or(voxelshape2, voxelshape5), VoxelShapes.or(voxelshape3, voxelshape5), VoxelShapes.or(voxelshape6, voxelshape5), Block.box(f2, 0, -height, f3, height, 0), Block.box(f2, 0, 16 + height, f3, height, 16), Block.box(-height, 0, f2, 0, height, f3), Block.box(16 + height, 0, f2, 16, height, f3) };
    for (int i = 0; i < 16; ++i) {
        avoxelshape[i] = VoxelShapes.or(voxelshape, avoxelshape[i]);
    }
    return avoxelshape;
}
Also used : VoxelShape(net.minecraft.util.math.shapes.VoxelShape)

Aggregations

VoxelShape (net.minecraft.util.math.shapes.VoxelShape)5 ItemStack (net.minecraft.item.ItemStack)2 BluePower (com.bluepowermod.BluePower)1 IAlloyFurnaceRecipe (com.bluepowermod.api.recipe.IAlloyFurnaceRecipe)1 BlockBPMicroblock (com.bluepowermod.block.BlockBPMicroblock)1 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1 GuiAlloyFurnace (com.bluepowermod.client.gui.GuiAlloyFurnace)1 GuiBlulectricAlloyFurnace (com.bluepowermod.client.gui.GuiBlulectricAlloyFurnace)1 GuiBlulectricFurnace (com.bluepowermod.client.gui.GuiBlulectricFurnace)1 ContainerAlloyFurnace (com.bluepowermod.container.ContainerAlloyFurnace)1 ContainerBlulectricAlloyFurnace (com.bluepowermod.container.ContainerBlulectricAlloyFurnace)1 ContainerBlulectricFurnace (com.bluepowermod.container.ContainerBlulectricFurnace)1 ContainerProjectTable (com.bluepowermod.container.ContainerProjectTable)1 BPBlocks (com.bluepowermod.init.BPBlocks)1 ItemSaw (com.bluepowermod.item.ItemSaw)1 AlloyFurnaceRegistry (com.bluepowermod.recipe.AlloyFurnaceRegistry)1 Refs (com.bluepowermod.reference.Refs)1 ItemStackUtils (com.bluepowermod.util.ItemStackUtils)1 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)1 java.util (java.util)1