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);
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations