package info.u_team.u_team_core.data;

import java.io.IOException;
import java.util.Iterator;
import java.util.function.Consumer;

import org.apache.logging.log4j.*;

import net.minecraft.block.Block;
import net.minecraft.data.*;
import net.minecraft.item.Item;
import net.minecraft.util.*;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.client.model.generators.ModelFile.UncheckedModelFile;

public abstract class CommonItemModelsProvider extends ItemModelProvider {
	
	protected final Marker marker;
	
	protected final GenerationData data;
	protected final String modid;
	protected final DataGenerator generator;
	
	public CommonItemModelsProvider(GenerationData data) {
		super(data.getGenerator(), data.getModid(), data.getExistingFileHelper());
		this.data = data;
		this.modid = data.getModid();
		this.generator = data.getGenerator();
		marker = MarkerManager.getMarker(getName());
	}
	
	@Override
	public void act(DirectoryCache cache) throws IOException {
		generatedModels.clear();
		registerModels();
		generatedModels.values().forEach(model -> {
			try {
				final ResourceLocation location = model.getLocation();
				CommonProvider.write(cache, model.toJson(), generator.getOutputFolder().resolve("assets/" + location.getNamespace() + "/models/" + location.getPath() + ".json"));
			} catch (final IOException ex) {
				CommonProvider.LOGGER.error(marker, "Could not write data.", ex);
			}
		});
	}
	
	@Override
	public String getName() {
		return "Item-Models";
	}
	
	// Item model methods
	
	protected void simpleGenerated(IItemProvider provider) {
		simpleParent(provider, "item/generated");
	}
	
	protected void simpleHandheld(IItemProvider provider) {
		simpleParent(provider, "item/handheld");
	}
	
	protected void simpleParent(IItemProvider provider, final String parent) {
		final String registryPath = provider.asItem().getRegistryName().getPath();
		getBuilder(registryPath).parent(new UncheckedModelFile(parent)).texture("layer0", "item/" + registryPath);
	}
	
	protected void simpleBlock(Block block) {
		final ResourceLocation registryName = block.getRegistryName();
		getBuilder(registryName.getPath()).parent(new UncheckedModelFile(new ResourceLocation(registryName.getNamespace(), "block/" + registryName.getPath())));
	}
	
	// Utility methods
	protected void iterateItems(Iterator<? extends Item> iterator, Consumer<IItemProvider> item) {
		iterator.forEachRemaining(item);
	}
	
	protected void iterateBlocks(Iterator<? extends Block> iterator, Consumer<IItemProvider> item) {
		iterator.forEachRemaining(item);
	}
	
	protected String getPath(IItemProvider provider) {
		return provider.asItem().getRegistryName().getPath();
	}
	
}

@@ -64,35 +64,8 @@
 on;%0A
-import java.util.Iterator;%0A
 impo
@@ -86,24 +86,17 @@
 unction.
-Consumer
+*
 ;%0A%0Aimpor
@@ -122,24 +122,67 @@
 g.log4j.*;%0A%0A
+import com.google.common.collect.Streams;%0A%0A
 import net.m
@@ -441,16 +441,62 @@
 delFile;
+%0Aimport net.minecraftforge.fml.RegistryObject;
 %0A%0Apublic
@@ -2400,26 +2400,45 @@
 eItems(Itera
-to
+ble%3C? extends Supplie
 r%3C? extends 
@@ -2442,25 +2442,26 @@
 ds Item%3E
+%3E
  itera
-tor
+ble
 , Consum
@@ -2492,33 +2492,59 @@
 %7B%0A%09%09
-iterator.forEachRemaining
+Streams.stream(iterable).map(Supplier::get).forEach
 (ite
@@ -2587,19 +2587,44 @@
 ks(Itera
-tor
+ble%3C? extends RegistryObject
 %3C? exten
@@ -2636,17 +2636,18 @@
 ock%3E
+%3E
  itera
-tor
+ble
 , Co
@@ -2682,33 +2682,59 @@
 %7B%0A%09%09
-iterator.forEachRemaining
+Streams.stream(iterable).map(Supplier::get).forEach
 (ite

Fix iterate methods now. These generics uff