Jump to content

Recommended Posts

Posted (edited)

I am trying to create a darkened version of mycelium and I found that the vanilla MapColors are not the right color. I have no trouble making an instance of MapColor but it just appears transparent on the map. 

 

Util.java

package drmeepster.evilshrooms.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import net.minecraft.block.material.MapColor;

public final class Util {
	
	private Util(){}
	
	public static int getNextMapColor(){
		//Will only be -1 if array is full
		int out = -1;
		
		for(int i = 0; i < MapColor.COLORS.length; i++){
			if(MapColor.COLORS[i] == null){
				continue;
			}
			out = i;
			break;
		}
		
		return out;
	}
	
	public static MapColor newMapColor(int index, int color){
		Constructor<MapColor> constr;
		try{
			constr = MapColor.class.getDeclaredConstructor(int.class, int.class);
		}catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
			return null;
		}
		
		constr.setAccessible(true);
		
		try {
			return constr.newInstance(index, color);
		} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
			return null;
		}
	}
}

 

ModEvilShrooms.java

package drmeepster.evilshrooms;

import drmeepster.evilshrooms.blocks.EvilShroomBlocks;
import drmeepster.evilshrooms.util.TabEvilShroom;
import drmeepster.evilshrooms.util.Util;
import net.minecraft.block.material.MapColor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = ModEvilShrooms.MODID, useMetadata = true, dependencies = "after:drcorester")
public class ModEvilShrooms{
	
    public static final String MODID = "evilshrooms";
    public static final TabEvilShroom EVIL_SHROOM_TAB = new TabEvilShroom();
    public static MapColor colorShadowMycelium;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
    	colorShadowMycelium = Util.newMapColor(Util.getNextMapColor(), 0x281538);
    	EvilShroomBlocks.preInit();
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event){

    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event){

    }
}

 

Edited by DrMeepster

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.