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.renderer.model.RenderMaterial;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.state.StateContainer;
import net.minecraft.world.level.block.state.BlockState;
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 (STATIC_DEFINITIONS instanceof ImmutableMap) {
			final Map<ResourceLocation, StateContainer<Block, BlockState>> mutableMap = new HashMap<>();
			STATIC_DEFINITIONS.forEach(mutableMap::put);
			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, StateContainer<Block, BlockState> container) {
		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(RenderMaterial material) {
		UNREFERENCED_TEXTURES.add(material);
	}
	
	/**
	 * Utility class for an empty state container
	 * 
	 * @author HyCraftHD
	 */
	public static class EmptyStateContainer extends StateContainer<Block, BlockState> {
		
		public EmptyStateContainer(Block block) {
			super(Block::defaultBlockState, block, BlockState::new, new HashMap<>());
		}
		
		@Override
		public ImmutableList<BlockState> getPossibleStates() {
			return getOwner().getStateDefinition().getPossibleStates();
		}
		
	}
	
}

@@ -211,27 +211,22 @@
 t.re
-nderer
+sources
 .model.
-Render
 Mate
@@ -362,28 +362,31 @@
 aft.
-state.StateContainer
+world.level.block.Block
 ;%0Aim
@@ -440,16 +440,78 @@
 kState;%0A
+import net.minecraft.world.level.block.state.StateDefinition;%0A
 import n
@@ -792,16 +792,28 @@
 %7B%0A%09%09if (
+ModelBakery.
 STATIC_D
@@ -882,33 +882,34 @@
 ation, State
-Container
+Definition
 %3CBlock, Bloc
@@ -946,24 +946,36 @@
 Map%3C%3E();%0A%09%09%09
+ModelBakery.
 STATIC_DEFIN
@@ -1010,16 +1010,28 @@
 ut);%0A%09%09%09
+ModelBakery.
 STATIC_D
@@ -1344,33 +1344,34 @@
 ation, State
-Container
+Definition
 %3CBlock, Bloc
@@ -1393,16 +1393,28 @@
 er) %7B%0A%09%09
+ModelBakery.
 STATIC_D
@@ -1616,22 +1616,16 @@
 Texture(
-Render
 Material
@@ -1639,16 +1639,28 @@
 al) %7B%0A%09%09
+ModelBakery.
 UNREFERE
@@ -1831,25 +1831,26 @@
 ds State
-Container
+Definition
 %3CBlock, 

Fix model util