Every little fish swimming around is a visitor on this page right now, and one of them is you ( ´ ▽ ` )ノ If they get in the way of reading, feel free to turn them off.
Minecraft Block Wrapper
wrapperHey, ever played Minecraft?
Just between us, Codfish here is an old-timer, even published a map on Bahamut back in the day. (´,,•ω•,,)
Not long ago, Google dropped a Minecraft 15th Anniversary Easter egg.
I was so touched, I decided to make my own version! Though, my tech skills weren't quite there, so it took ages to whip up... (›´ω`‹ )
Let's turn web elements into Minecraft blocks together and dig, dig, dig away on our little webpage! ᕕ( ゚ ∀。)ᕗ
Tech Keywords
Section titled “Tech Keywords”| Name | Description |
|---|---|
| Babylon.js | 3D engine |
| Particle System | Spawns large numbers of small objects, commonly used to simulate smoke, fire, rain, and snow |
| Constructive Solid Geometry | Builds complex shapes by combining simple geometries with boolean operations (union, subtraction, intersection) |
Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”Hold down the mouse button to start digging an element. Keep holding, and after a bit, you'll dig it away.
Double-click the hole to put the element back. ( ´ ▽ ` )ノ










<template> <div class="w-full flex flex-col items-center gap-14 example-wrap"> <wrapper-minecraft-block class="w-1/2"> <div class="select-none border py-20 text-center"> {{ t('我是方塊') }} </div> </wrapper-minecraft-block>
<!-- 必須放置一個 world 元件 --> <wrapper-minecraft-world /> </div></template>
<script setup lang="ts">import { useI18n } from 'vue-i18n'import WrapperMinecraftBlock from '../wrapper-minecraft-block.vue'import WrapperMinecraftWorld from '../wrapper-minecraft-world.vue'
const { t } = useI18n()</script>More Blocks
Section titled “More Blocks”You can specify different block types too! ( ´ ▽ ` )ノ
































<template> <div class="grid grid-cols-2 w-full items-center justify-center gap-4 p-6"> <wrapper-minecraft-block class="col-span-2" block-type="stone" > <div class="border p-10"> {{ t('description') }} </div> </wrapper-minecraft-block>
<wrapper-minecraft-block> <img src="/low/profile.webp" alt="" class="pointer-events-none select-none border rounded" > </wrapper-minecraft-block>
<wrapper-minecraft-block block-type="sand"> <img src="/low/profile-2.webp" alt="" class="pointer-events-none select-none border rounded" > </wrapper-minecraft-block>
<!-- 必須放置一個 world 元件 --> <wrapper-minecraft-world /> </div></template>
<script setup lang="ts">import { useI18n } from 'vue-i18n'import WrapperMinecraftBlock from '../wrapper-minecraft-block.vue'import WrapperMinecraftWorld from '../wrapper-minecraft-world.vue'
const { t } = useI18n()</script>How It Works
Section titled “How It Works”It's mainly composed of two components: World and Block.
-
World provides the 3D scene.
-
Block handles the interactions.
Here's the concept:
We use babylon.js to create a 3D scene covering the entire webpage. Then, we use CSG (Constructive Solid Geometry) to cut meshes, creating a "hole" effect, and initialize the particle systems needed for each block.
The Block component manages interactions, sounds, crack animations, and state, notifying the World of various events via an EventBus.
Source Code
Section titled “Source Code”interface Props { /** 方塊種類。初始化後不可變更 */ blockType?: BlockType; /** 初始化是否為挖掉的狀態 */ isInitDug?: boolean;}const emit = defineEmits<{ digging: []; dug: []; place: [];}>()defineSlots<{ default?: () => unknown;}>()If you have any suggestions or questions, feel free to email me( ´ ▽ ` )ノ
If you like cool components, feel free to " Buy me a cup of coffee " to show your support!