import {
  world
} from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('we:paper_box_connection', {
    onTick(e) {
      const {
        block
      } = e;
      if (block.typeId === 'minecraft:air') return;
      const permutation = block.permutation;
      const above = block.above().typeId;
      const below = block.below().typeId;


      if (above !== block.typeId && below !== block.typeId) {
        const newPermutation = permutation.withState('we:texture', 0);
        block.setPermutation(newPermutation);
        return;
      } else if (above === block.typeId && below !== block.typeId) {
        const newPermutation = permutation.withState('we:texture', 1);
        block.setPermutation(newPermutation);
        return;
      } else if (above === block.typeId && below === block.typeId) {
        const newPermutation = permutation.withState('we:texture', 2);
        block.setPermutation(newPermutation);
        return;
      } else if (above !== block.typeId && below === block.typeId) {
        const newPermutation = permutation.withState('we:texture', 3);
        block.setPermutation(newPermutation);
        return;
      }
    }
  });
});