package info.sleeplessacorn.nomagi.block;

import info.sleeplessacorn.nomagi.Nomagi;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
import tehnut.lib.mc.block.BlockEnum;
import tehnut.lib.mc.model.IModeled;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class BlockNature extends BlockEnum<BlockNature.Nature> implements IModeled {

    public BlockNature() {
        super(Material.ROCK, Nature.class);

        setUnlocalizedName(Nomagi.MODID + ".nature");
        setCreativeTab(Nomagi.TAB_NOMAGI);
        setSoundType(SoundType.WOOD);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
        IBlockState iblockstate = world.getBlockState(pos.offset(side));
        return state != iblockstate || !Objects.equals(state.getValue(getProperty()).getName(), "ancient_leaves");
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        if (getProperty() == null)
            return super.isOpaqueCube(state); // Fuck you Mojang
        else
            return !Objects.equals(state.getValue(getProperty()).getName(), "ancient_leaves")
                    && state.getValue(getProperty()).getHitBox() == FULL_BLOCK_AABB;
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return !Objects.equals(state.getValue(getProperty()).getName(), "ancient_leaves")
                && state.getValue(getProperty()).getHitBox() == FULL_BLOCK_AABB;
    }

    @Override
    public boolean isFullBlock(IBlockState state) {
        return !Objects.equals(state.getValue(getProperty()).getName(), "ancient_leaves")
                && state.getValue(getProperty()).getHitBox() == FULL_BLOCK_AABB;
    }

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return state.getValue(getProperty()).getHitBox();
    }

    @Override
    public Material getMaterial(IBlockState state) {
        return state.getValue(getProperty()).getBlockType().getLeft();
    }

    @Override
    public SoundType getSoundType(IBlockState state, World world, BlockPos pos, @Nullable Entity entity) {
        return state.getValue(getProperty()).getBlockType().getRight();
    }

    @Override
    public BlockRenderLayer getBlockLayer() {
        return BlockRenderLayer.CUTOUT_MIPPED;
    }

    @Override
    public void getVariants(List<String> variants) {
        for (BlockNature.Nature nature : BlockNature.Nature.values())
            variants.add("type=" + nature.getName());
    }

    public enum Nature implements IStringSerializable {
        RADIANT_GRASS(Material.GROUND, SoundType.GROUND),
        ANCIENT_BARK(Material.WOOD, SoundType.WOOD),
        ANCIENT_PLANKS(Material.WOOD, SoundType.WOOD),
        ANCIENT_LEAVES(Material.LEAVES, SoundType.PLANT),
        ;

        private final AxisAlignedBB hitBox;
        private final Pair<Material, SoundType> blockType;

        Nature(Material material, SoundType soundType) {
            this(FULL_BLOCK_AABB, material, soundType);
        }

        Nature(AxisAlignedBB bounds, Material material, SoundType soundType) {
            this.hitBox = bounds;
            this.blockType = Pair.of(material, soundType);
        }

        public AxisAlignedBB getHitBox() {
            return hitBox;
        }

        public Pair<Material, SoundType> getBlockType() {
            return blockType;
        }

    @Override
    public String getName() {
        return name().toLowerCase(Locale.ENGLISH);
    }
    }

}

@@ -1427,32 +1427,16 @@
 tate %7C%7C 
-!Objects.equals(
 state.ge
@@ -1460,37 +1460,33 @@
 y())
-.getName(), %22ancient_leaves%22)
+ != Nature.ANCIENT_LEAVES
 ;%0A  
@@ -1661,20 +1661,8 @@
 ang%0A
-        else
 %0A   
@@ -1677,32 +1677,16 @@
  return 
-!Objects.equals(
 state.ge
@@ -1710,57 +1710,33 @@
 y())
-.getName(), %22ancient_leaves%22)%0A                   
+ != Nature.ANCIENT_LEAVES
  && 
@@ -1884,32 +1884,16 @@
  return 
-!Objects.equals(
 state.ge
@@ -1917,53 +1917,33 @@
 y())
-.getName(), %22ancient_leaves%22)%0A               
+ != Nature.ANCIENT_LEAVES
  && 
@@ -2096,24 +2096,8 @@
 urn 
-!Objects.equals(
 stat
@@ -2125,53 +2125,33 @@
 y())
-.getName(), %22ancient_leaves%22)%0A               
+ != Nature.ANCIENT_LEAVES
  && 
@@ -3929,24 +3929,28 @@
 %0A        %7D%0A%0A
+    
     @Overrid
@@ -3943,32 +3943,36 @@
       @Override%0A
+    
     public Strin
@@ -3989,24 +3989,28 @@
 ) %7B%0A        
+ 
+   
 return name(
@@ -4040,16 +4040,20 @@
 GLISH);%0A
+    
     %7D%0A  
@@ -4056,11 +4056,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

Make BlockNature not stupid