Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for running IModel.retexture() on models from blockstates (…
- Loading branch information
1 parent
d14a872
commit 82d735e
Showing
2 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/net/minecraftforge/debug/BlockstateRetextureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} | ||
} |