-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
BlockstateRetextureTest.java
61 lines (51 loc) · 2.88 KB
/
BlockstateRetextureTest.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package net.minecraftforge.debug;
import java.util.function.Function;
import com.google.common.collect.ImmutableMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = BlockstateRetextureTest.MODID, name = "BlockstateRetextureTest", version = BlockstateRetextureTest.VERSION, acceptableRemoteVersions = "*")
public class BlockstateRetextureTest
{
public static final String MODID = "forge_blockstate_retexture_test";
public static final String VERSION = "1.0";
static final boolean ENABLED = false;
private static ResourceLocation fenceName = new ResourceLocation("minecraft", "fence");
private static ModelResourceLocation fenceLocation = new ModelResourceLocation(fenceName, "east=true,north=false,south=false,west=true");
private static ResourceLocation stoneName = new ResourceLocation("minecraft", "stone");
private static ModelResourceLocation stoneLocation = new ModelResourceLocation(stoneName, "normal");
private static Function<ResourceLocation, TextureAtlasSprite> textureGetter = location ->
{
assert location != null;
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
};
@Mod.EventBusSubscriber(modid = MODID, value = Side.CLIENT)
public static class ClientEvents
{
@SubscribeEvent
public static void onModelBakeEvent(ModelBakeEvent event)
{
if (!ENABLED)
{
return;
}
IModel fence = ModelLoaderRegistry.getModelOrLogError(fenceLocation, "Error loading fence model");
IModel stone = ModelLoaderRegistry.getModelOrLogError(stoneLocation, "Error loading planks model");
IModel retexturedFence = fence.retexture(ImmutableMap.of("texture", "blocks/log_oak"));
IModel retexturedStone = stone.retexture(ImmutableMap.of("all", "blocks/diamond_block"));
IBakedModel fenceResult = retexturedFence.bake(fence.getDefaultState(), DefaultVertexFormats.BLOCK, textureGetter);
IBakedModel stoneResult = retexturedStone.bake(stone.getDefaultState(), DefaultVertexFormats.BLOCK, textureGetter);
event.getModelRegistry().putObject(fenceLocation, fenceResult);
event.getModelRegistry().putObject(stoneLocation, stoneResult);
}
}
}