Search in sources :

Example 1 with MapItemRenderer

use of net.minecraft.client.gui.MapItemRenderer in project Charset by CharsetMC.

the class ProjectorHandlerMap method render.

@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
    MapData mapData = ((ItemMap) stack.getItem()).getMapData(stack, surface.getWorld());
    if (mapData != null && mapData.mapName != null) {
        MapItemRenderer mapItemRenderer = Minecraft.getMinecraft().entityRenderer.getMapItemRenderer();
        mapItemRenderer.updateMapTexture(mapData);
        Object o = mapItemRenderer.getMapInstanceIfExists(mapData.mapName);
        if (o != null) {
            if (MAP_DATA_LOCATION_GETTER == null) {
                MAP_DATA_LOCATION_GETTER = MethodHandleHelper.findFieldGetter(o.getClass(), "location", "field_148240_d");
            }
            try {
                Minecraft.getMinecraft().getTextureManager().bindTexture((ResourceLocation) MAP_DATA_LOCATION_GETTER.invoke(o));
                ProjectorHelper.INSTANCE.renderTexture(surface, 0, 256, 0, 256);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    } else {
        PacketRequestMapData.requestMap(stack);
    }
}
Also used : ItemMap(net.minecraft.item.ItemMap) MapData(net.minecraft.world.storage.MapData) MapItemRenderer(net.minecraft.client.gui.MapItemRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

MapItemRenderer (net.minecraft.client.gui.MapItemRenderer)1 ItemMap (net.minecraft.item.ItemMap)1 MapData (net.minecraft.world.storage.MapData)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1