package info.u_team.u_team_core.util;

import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraftforge.client.event.ModelRegistryEvent;

/**
 * Utility methods for interaction with {@link ModelBakery} private methods.<br>
 * All methods should be called in the {@link ModelRegistryEvent} event.
 *
 * @author HyCraftHD
 */
public class ModelUtil {
	
	static {
		if (ModelBakery.STATIC_DEFINITIONS instanceof ImmutableMap) {
			final Map<ResourceLocation, StateDefinition<Block, BlockState>> mutableMap = new HashMap<>();
			ModelBakery.STATIC_DEFINITIONS.forEach(mutableMap::put);
			ModelBakery.STATIC_DEFINITIONS = mutableMap;
		}
	}
	
	/**
	 * Replace the default state container with a custom one. Can remove or add states for the model
	 *
	 * @param location Resource location of the model
	 * @param container Custom state container
	 */
	public static void addCustomStateContainer(ResourceLocation location, StateDefinition<Block, BlockState> container) {
		ModelBakery.STATIC_DEFINITIONS.put(location, container);
	}
	
	/**
	 * Add {@link RenderMaterial} to be loaded to the atlas texture and stitched.
	 *
	 * @param material Render Material
	 */
	public static void addTexture(Material material) {
		ModelBakery.UNREFERENCED_TEXTURES.add(material);
	}
	
	/**
	 * Utility class for an empty state container
	 *
	 * @author HyCraftHD
	 */
	public static class EmptyStateContainer extends StateDefinition<Block, BlockState> {
		
		public EmptyStateContainer(Block block) {
			super(Block::defaultBlockState, block, BlockState::new, new HashMap<>());
		}
		
		@Override
		public ImmutableList<BlockState> getPossibleStates() {
			return getOwner().getStateDefinition().getPossibleStates();
		}
		
	}
	
}

@@ -1098,25 +1098,26 @@
 t state 
-container
+definition
  with a 
@@ -1233,25 +1233,26 @@
  @param 
-container
+definition
  Custom 
@@ -1253,33 +1253,34 @@
 ustom state 
-container
+definition
 %0A%09 */%0A%09publi
@@ -1379,25 +1379,26 @@
 kState%3E 
-container
+definition
 ) %7B%0A%09%09Mo
@@ -1440,25 +1440,26 @@
 cation, 
-container
+definition
 );%0A%09%7D%0A%09%0A
@@ -1478,22 +1478,16 @@
  %7B@link 
-Render
 Material
@@ -1735,17 +1735,18 @@
 ate 
-container
+definition
 %0A%09 *
@@ -1804,25 +1804,26 @@
 ptyState
-Container
+Definition
  extends
@@ -1882,25 +1882,26 @@
 ptyState
-Container
+Definition
 (Block b

Update docs for model util