aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins/custommodels/ReferenceCustomModelsPatch.java
blob: 14c84abed8f305eab9223ea9ee728daa86daae97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package moe.nea.firmament.mixins.custommodels;

import moe.nea.firmament.events.BakeExtraModelsEvent;
import net.minecraft.client.render.model.BlockStatesLoader;
import net.minecraft.client.render.model.ItemModel;
import net.minecraft.client.render.model.ReferencedModelsCollector;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Map;

@Mixin(ReferencedModelsCollector.class)
public abstract class ReferenceCustomModelsPatch {
	@Shadow
	protected abstract void addTopLevelModel(ModelIdentifier modelId, UnbakedModel model);

	@Shadow
	@Final
	private Map<Identifier, UnbakedModel> inputs;

	@Inject(method = "addBlockStates", at = @At("RETURN"))
	private void addFirmamentReferencedModels(
		BlockStatesLoader.BlockStateDefinition definition, CallbackInfo ci
	) {
		inputs.keySet().stream().filter(it->it.toString().contains("firm")).forEach(System.out::println);
		BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(
			(modelIdentifier, identifier) -> addTopLevelModel(modelIdentifier, new ItemModel(identifier))));

	}
}