2017-05-29 09:10:40 +00:00
|
|
|
package net.minecraftforge.debug;
|
2016-12-02 04:49:23 +00:00
|
|
|
|
2017-06-26 03:58:19 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2016-12-02 04:49:23 +00:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
|
|
|
import net.minecraft.client.resources.IResourceManager;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2017-06-19 22:02:18 +00:00
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
2016-12-02 04:49:23 +00:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2017-05-29 09:10:40 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
2016-12-02 04:49:23 +00:00
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
2017-06-26 03:58:19 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.function.Function;
|
2016-12-02 04:49:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for {@link TextureStitchEvent.Pre}.
|
|
|
|
*/
|
2017-01-17 21:07:22 +00:00
|
|
|
@Mod(modid = CustomSpriteTest.MOD_ID, name = CustomSpriteTest.NAME, version = "1.0", clientSideOnly = true)
|
2016-12-02 04:49:23 +00:00
|
|
|
public class CustomSpriteTest
|
|
|
|
{
|
|
|
|
static final String MOD_ID = "custom_sprite_test";
|
|
|
|
static final String NAME = "Custom sprite test";
|
2017-05-29 09:10:40 +00:00
|
|
|
private static Logger logger;
|
2016-12-02 04:49:23 +00:00
|
|
|
|
2017-06-19 22:02:18 +00:00
|
|
|
|
|
|
|
@Mod.EventBusSubscriber(modid = MOD_ID)
|
|
|
|
public static class Registration
|
|
|
|
{
|
|
|
|
@SubscribeEvent
|
2017-06-26 03:58:19 +00:00
|
|
|
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
2017-06-19 22:02:18 +00:00
|
|
|
{
|
|
|
|
event.getRegistry().register(new Block(Material.WOOD).setRegistryName(MOD_ID, "custom_sprite_block").setCreativeTab(CreativeTabs.MISC));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:49:23 +00:00
|
|
|
@Mod.EventHandler
|
2017-05-29 09:10:40 +00:00
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
2016-12-02 04:49:23 +00:00
|
|
|
{
|
2017-05-29 09:10:40 +00:00
|
|
|
logger = event.getModLog();
|
2016-12-02 04:49:23 +00:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void textureStitch(TextureStitchEvent.Pre event)
|
|
|
|
{
|
2017-06-26 03:58:19 +00:00
|
|
|
DelegateSprite bottom = DelegateSprite.make("bottom", new ResourceLocation("blocks/diamond_block"));
|
|
|
|
DelegateSprite top = DelegateSprite.make("top", new ResourceLocation("blocks/tnt_side"));
|
2016-12-02 04:49:23 +00:00
|
|
|
|
|
|
|
TextureMap textureMap = event.getMap();
|
|
|
|
textureMap.setTextureEntry(bottom);
|
|
|
|
textureMap.setTextureEntry(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
static final class DelegateSprite extends TextureAtlasSprite
|
|
|
|
{
|
|
|
|
final ResourceLocation delegate;
|
|
|
|
|
|
|
|
private DelegateSprite(ResourceLocation loc, ResourceLocation delegate)
|
|
|
|
{
|
|
|
|
super(loc.toString());
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DelegateSprite make(String name, ResourceLocation delegate)
|
|
|
|
{
|
|
|
|
return new DelegateSprite(new ResourceLocation(MOD_ID, name), delegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomLoader(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-06-26 03:58:19 +00:00
|
|
|
public Collection<ResourceLocation> getDependencies()
|
2016-12-02 04:49:23 +00:00
|
|
|
{
|
2017-06-26 03:58:19 +00:00
|
|
|
return ImmutableList.of(delegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean load(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location, @Nonnull Function<ResourceLocation, TextureAtlasSprite> textureGetter)
|
|
|
|
{
|
|
|
|
final TextureAtlasSprite sprite = textureGetter.apply(delegate);
|
|
|
|
width = sprite.getIconWidth();
|
|
|
|
height = sprite.getIconHeight();
|
|
|
|
final int[][] oldPixels = sprite.getFrameTextureData(0);
|
|
|
|
final int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
|
|
|
|
pixels[0] = new int[width * height];
|
|
|
|
for (int p = 0; p < width * height; p++) {
|
|
|
|
pixels[0][p] = oldPixels[0][p] >> 8;
|
2016-12-02 04:49:23 +00:00
|
|
|
}
|
|
|
|
this.clearFramesTextureData();
|
|
|
|
this.framesTextureData.add(pixels);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 21:07:22 +00:00
|
|
|
}
|