Jump to content

BaseMetals API


KewaiiGamer

Recommended Posts

MetaPaxel.java

package main.java.com.kewaiigamer.multitools.plugin.basemetals;

import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import cyano.basemetals.items.ItemMetalPickaxe;
import cyano.basemetals.material.MetalMaterial;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;

public class MetalPaxel extends ItemMetalPickaxe {

public MetalPaxel(MetalMaterial metal) {
	super(metal);
}

	public Set<String> getToolClasses(ItemStack stack) {
		return ImmutableSet.of("pickaxe", "spade");
	}
	private static HashSet<Block> effectiveAgainst = Sets.newHashSet(new Block[] {
		    Blocks.GRASS, Blocks.DIRT, Blocks.SAND, Blocks.GRAVEL, 
		    Blocks.SNOW_LAYER, Blocks.SNOW, Blocks.CLAY, Blocks.FARMLAND, 
		    Blocks.SOUL_SAND, Blocks.MYCELIUM, Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, 
		    Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN});

	@Override
	public boolean canHarvestBlock(IBlockState blockIn) {
			return effectiveAgainst.contains(blockIn) ? true : super.canHarvestBlock(blockIn);
	}

	@Override
	public float getStrVsBlock(ItemStack stack, IBlockState state) {
		 if (state.getMaterial() == Material.WOOD || state.getMaterial() == Material.VINE || state.getMaterial() == Material.PLANTS || state.getMaterial() == Material.GROUND || state.getMaterial() == Material.GRASS || state.getMaterial() == Material.SAND)
		        return this.efficiencyOnProperMaterial;
		 return effectiveAgainst.contains(state) ? this.efficiencyOnProperMaterial : super.getStrVsBlock(stack, state);
	}

}

ModItems.java

package main.java.com.kewaiigamer.multitools.item;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cyano.basemetals.init.Materials;
import cyano.basemetals.material.MetalMaterial;
import main.java.com.kewaiigamer.multitools.CreativeTab;
import main.java.com.kewaiigamer.multitools.Main;
import main.java.com.kewaiigamer.multitools.RegistryUtils;
import main.java.com.kewaiigamer.multitools.plugin.basemetals.MetalPaxel;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModItems {

public static Item woodpaxel;
public static Item stonepaxel;
public static Item ironpaxel;
public static Item goldpaxel;
public static Item diamondpaxel;
public static Item ingotCopper;
public static Item bronzepaxel;

private static Map<Item,String> itemRegistry = new HashMap<>();
private static Map<MetalMaterial,List<Item>> itemsByMetal = new HashMap<>();

public ModItems() {
	createItems();
	createMetalItems();

}
public static void createItems() {
	woodpaxel = new WoodPaxel(ToolMaterial.WOOD).setCreativeTab(CreativeTab.tabMultiTools);
	RegistryUtils.setNames(woodpaxel, "woodpaxel");
	GameRegistry.register(woodpaxel);
	stonepaxel = new StonePaxel(ToolMaterial.STONE).setCreativeTab(CreativeTab.tabMultiTools);
	RegistryUtils.setNames(stonepaxel, "stonepaxel");
	GameRegistry.register(stonepaxel);
	ironpaxel = new IronPaxel(ToolMaterial.IRON).setCreativeTab(CreativeTab.tabMultiTools);
	RegistryUtils.setNames(ironpaxel, "ironpaxel");
	GameRegistry.register(ironpaxel);
	goldpaxel = new GoldPaxel(ToolMaterial.GOLD).setCreativeTab(CreativeTab.tabMultiTools);
	RegistryUtils.setNames(goldpaxel, "goldpaxel");
	GameRegistry.register(goldpaxel);
	diamondpaxel = new DiamondPaxel(ToolMaterial.DIAMOND).setCreativeTab(CreativeTab.tabMultiTools);
	RegistryUtils.setNames(diamondpaxel, "diamondpaxel");
	GameRegistry.register(diamondpaxel);
}
public static void createMetalItems() {
    	bronzepaxel = createPaxel(Materials.bronze);
}
private static Item registerItem(Item item, String name, MetalMaterial metal, CreativeTabs tab){
	item.setRegistryName(Main.MODID, name);
	item.setUnlocalizedName(Main.MODID+"."+name);
	GameRegistry.register(item); 
	itemRegistry.put(item, name);
	if(tab != null){
		item.setCreativeTab(tab);
	}
	if(metal != null){
		itemsByMetal.computeIfAbsent(metal, (MetalMaterial g)->new ArrayList<>());
		itemsByMetal.get(metal).add(item);
	}
	return item;

}

private static Item createPaxel(MetalMaterial metal){
	return registerItem(new MetalPaxel(metal), metal.getName()+"_"+"paxel", metal, CreativeTab.tabMultiTools);
}
    
    


}

 

When I start minecraft it crashes with this log: https://paste.ee/p/UYkWs

Link to comment
Share on other sites

Good job, you created an identifier.

 

You might want to set it equal to something.

 

http://stackoverflow.com/questions/2614072/java-define-terms-initialization-declaration-and-assignment

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I replaced that line of code I replied before with

public static MetalMaterial bronze = Materials.bronze;

and the method createMetalItems() is now

public static void createMetalItems() {
    	bronzepaxel = createPaxel(bronze);

 

but it still gives the same error. (No use to post the log.It's the same)

Link to comment
Share on other sites

The bronze material is initialized in Materials.java:

public abstract class Materials {

private static Map<String,MetalMaterial> allMaterials = new HashMap<>();
private static Map<MetalMaterial,ArmorMaterial> armorMaterialMap= new HashMap<>();
private static Map<MetalMaterial,ToolMaterial> toolMaterialMap= new HashMap<>();

public static MetalMaterial copper;
public static MetalMaterial silver;
public static MetalMaterial tin;
public static MetalMaterial lead;
public static MetalMaterial nickel;
public static MetalMaterial bronze;
public static MetalMaterial brass;
public static MetalMaterial steel;
public static MetalMaterial invar;
public static MetalMaterial electrum;
public static MetalMaterial coldiron;
public static MetalMaterial mithril;
public static MetalMaterial adamantine;
public static MetalMaterial starsteel;
public static MetalMaterial zinc;
public static MetalMaterial aquarium;
public static MetalMaterial cupronickel;
public static MetalMaterial platinum;

// vanilla imports
public static MetalMaterial vanilla_wood;
public static MetalMaterial vanilla_stone;
public static MetalMaterial vanilla_iron;
public static MetalMaterial vanilla_gold;
public static MetalMaterial vanilla_diamond;

private static boolean initDone = false;
public static void init(){
	if(initDone)return;

	// vanilla metals
	vanilla_wood = addMaterial("wood",2,2,6);
	vanilla_stone = addMaterial("stone",5,4,2);
	vanilla_iron = addMaterial("iron",8,8,4.5);
	vanilla_gold = addMaterial("gold",1,1,10);
	vanilla_diamond = addMaterial("diamond",10,15,4);

	// mod metals
	copper = addMaterial("copper",4,4,5);
	silver = addMaterial("silver", 5, 4, 6);
	tin = addMaterial("tin", 3, 1, 2);
	lead = new LeadMaterial("lead", 1, 1, 1);
	registerMaterial(lead.getName(), lead);
	nickel = addMaterial("nickel", 4, 4, 7);
	zinc = addMaterial("zinc", 1, 1, 1);
	bronze = addMaterial("bronze", 8, 4, 4.5);
	brass = addMaterial("brass", 3.5, 3, 9);
	steel = addMaterial("steel", 8, 15, 2);
	invar = addMaterial("invar", 9, 10, 3);
	electrum = addMaterial("electrum", 5, 4, 10);
	coldiron = addMaterial("coldiron", 7, 7, 7);
	mithril = addMaterial("mithril", 9, 9, 9);
	adamantine = new AdamantineMaterial("adamantine", 12, 100, 0);
	registerMaterial(adamantine.getName(), adamantine);
	starsteel = new StarSteelMaterial("starsteel", 10, 25, 12);
	registerMaterial(starsteel.getName(), starsteel);
	aquarium = addMaterial("aquarium", 4, 10, 15);

	cupronickel = addMaterial("cupronickel", 6, 6, 6);
	platinum = addRareMaterial("platinum", 3, 5, 15);

	initDone = true;
}

private static MetalMaterial addMaterial(String name, double hardness, double strength, double magic){
	MetalMaterial m = new MetalMaterial(name,(float)hardness,(float)strength,(float)magic);
	registerMaterial(name, m);
	return m;
}

private static MetalMaterial addRareMaterial(String name, double hardness, double strength, double magic){
	MetalMaterial m = new MetalMaterial(name,(float)hardness,(float)strength,(float)magic,true);
	registerMaterial(name, m);
	return m;
}

protected static void registerMaterial(String name, MetalMaterial m){

	allMaterials.put(name, m);

	String enumName = m.getEnumName();
	String texName = m.getName();
	int[] protection = m.getDamageReductionArray();
	int durability = m.getArmorMaxDamageFactor();
	ArmorMaterial am = EnumHelper.addArmorMaterial(enumName, texName, durability, protection, m.getEnchantability(), SoundEvents.ITEM_ARMOR_EQUIP_IRON, (m.hardness > 10 ? (int)(m.hardness / 5) : 0));
	if(am == null){
		// uh-oh
		FMLLog.severe("Failed to create armor material enum for "+m);
	}
	armorMaterialMap.put(m, am);
	FMLLog.info("Created armor material enum "+am);

	ToolMaterial tm = EnumHelper.addToolMaterial(enumName, m.getToolHarvestLevel(), m.getToolDurability(), m.getToolEfficiency(), m.getBaseAttackDamage(), m.getEnchantability());
	if(tm == null){
		// uh-oh
		FMLLog.severe("Failed to create tool material enum for "+m);
	}
	toolMaterialMap.put(m, tm);
	FMLLog.info("Created tool material enum "+tm);
}
/**
 * Gets the armor material for a given metal 
 * @param m The metal of interest
 * @return The armor material for this metal, or null if there isn't one
 */
public static ArmorMaterial getArmorMaterialFor(MetalMaterial m){
	return armorMaterialMap.get(m);
}


/**
 * Gets the tool material for a given metal 
 * @param m The metal of interest
 * @return The tool material for this metal, or null if there isn't one
 */
public static ToolMaterial getToolMaterialFor(MetalMaterial m){
	return toolMaterialMap.get(m);
}

/**
 * Returns a list of all metal materials in Base Metals. All of the metals 
 * in this list are also available as static public members of this class. 
 * @return A Collection of MetalMaterial instances.
 */
public static Collection<MetalMaterial> getAllMetals() {
	return allMaterials.values();
}
/**
 * Gets a metal material by its name (e.g. "copper").
 * @param metalName The name of a metal
 * @return The material representing the named metal, or null if no metals 
 * have been registered under that name.
 */
public static MetalMaterial getMetalByName(String metalName){
	return allMaterials.get(metalName);
}
}

so I grabbed the bronze from there with

public static MetalMaterial bronze = Materials.bronze;

as Draco said

Link to comment
Share on other sites

public static void init(){
	if(initDone)return;

	// vanilla metals
	vanilla_wood = addMaterial("wood",2,2,6);
	vanilla_stone = addMaterial("stone",5,4,2);
	vanilla_iron = addMaterial("iron",8,8,4.5);
	vanilla_gold = addMaterial("gold",1,1,10);
	vanilla_diamond = addMaterial("diamond",10,15,4);

	// mod metals
	copper = addMaterial("copper",4,4,5);
	silver = addMaterial("silver", 5, 4, 6);
	tin = addMaterial("tin", 3, 1, 2);
	lead = new LeadMaterial("lead", 1, 1, 1);
	registerMaterial(lead.getName(), lead);
	nickel = addMaterial("nickel", 4, 4, 7);
	zinc = addMaterial("zinc", 1, 1, 1);
	bronze = addMaterial("bronze", 8, 4, 4.5);
	brass = addMaterial("brass", 3.5, 3, 9);
	steel = addMaterial("steel", 8, 15, 2);
	invar = addMaterial("invar", 9, 10, 3);
	electrum = addMaterial("electrum", 5, 4, 10);
	coldiron = addMaterial("coldiron", 7, 7, 7);
	mithril = addMaterial("mithril", 9, 9, 9);
	adamantine = new AdamantineMaterial("adamantine", 12, 100, 0);
	registerMaterial(adamantine.getName(), adamantine);
	starsteel = new StarSteelMaterial("starsteel", 10, 25, 12);
	registerMaterial(starsteel.getName(), starsteel);
	aquarium = addMaterial("aquarium", 4, 10, 15);

	cupronickel = addMaterial("cupronickel", 6, 6, 6);
	platinum = addRareMaterial("platinum", 3, 5, 15);

	initDone = true;
}

Link to comment
Share on other sites

At BaseMetals.java during preInitialization

@Mod(
	modid = BaseMetals.MODID,
	name=BaseMetals.NAME,
	version = BaseMetals.VERSION,
	acceptedMinecraftVersions = "[1.9.4,)") // see VersionRange.createFromVersionSpec(String) for explanation of this convoluted feature
//		updateJSON = "https://raw.githubusercontent.com/cyanobacterium/BaseMetals/master/update.json")

public class BaseMetals
{

public static BaseMetals INSTANCE = null;
/** ID of this mod */
public static final String MODID = "basemetals";
/** display name of this mod */
public static final String NAME ="Base Metals";
/** Version number, in Major.Minor.Build format. The minor number is increased whenever a change 
 * is made that has the potential to break compatibility with other mods that depend on this one. */
public static final String VERSION = "2.3.0";



//	/** If true, some metals can be used to brew potions */
//	public static boolean enablePotionRecipes = true;

/** If true, hammers cannot crush ores that they cannot mine */
public static boolean enforceHardness = true;
/** If true, then crack hammers can mine on all the same blocks that their pick-axe equivalent 
 * can mine. If false, then the hammer is 1 step weaker than the pick-axe */
public static boolean strongHammers = true;
/** For when the user adds specific recipies via the config file */
public static List<String> userCrusherRecipes = new ArrayList<>();
/** location of ore-spawn files */
public static Path oreSpawnFolder = null;
/** if true, then this mod will scan the Ore Dictionary for obvious hammer recipes from other mods */
public static boolean autoDetectRecipes = true;
/** if true, then this mod will require the orespawn mod */
public static boolean requireOreSpawn = true;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	INSTANCE = this;
	// load config
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();

//		enablePotionRecipes = config.getBoolean("enable_potions", "options", enablePotionRecipes, 
//				"If true, then some metals can be used to brew potions.");



	enforceHardness = config.getBoolean("enforce_hardness", "options", enforceHardness, 
			"If true, then the crack hammer cannot crush ingots into powders if that \n"
		+	"crackhammer is not hard enough to crush the ingot's ore.");

	strongHammers = config.getBoolean("strong_hammers", "options", strongHammers, 
			"If true, then the crack hammer can crush ingots/ores that a pickaxe of the same \n"
		+	"material can harvest. If false, then your crack hammer must be made of a harder \n"
		+	"material than the ore you are crushing.");


	autoDetectRecipes = config.getBoolean("automatic_recipes", "options", autoDetectRecipes,
			"If true, then Base Metals will scan the Ore Dictionary to automatically add a \n"
					+	"Crack Hammer recipe for every material that has an ore, dust, and ingot.");

	requireOreSpawn = config.getBoolean("using_orespawn", "options", requireOreSpawn,
			"If false, then Base Metals will not require DrCyano's Ore Spawn mod. \n" +
					"Set to false if using another mod to manually handle ore generation.");


	ConfigCategory userRecipeCat = config.getCategory("hammer recipes");
	userRecipeCat.setComment(
		  "This section allows you to add your own recipes for the Crack Hammer (and other rock \n"
		+ "crushers). Recipes are specified in semicolon ( delimited lists of formulas in the \n"
		+ "format modid:name#y->x*modid:name#y, where x is the number of items in a stack and y \n"
		+ "is the metadata value. Note that both x and y are optional, so you can use the \n"
		+ "formula modid:name->modid:name for most items/blocks. \n\n"
		+ "All properties in this section will be parsed for formulas, regardless their name. \n"
		+ "This lets you organize your recipe lists for easier reading.");
	if(userRecipeCat.keySet().size()==0){
		Property prop = new Property("custom","",Property.Type.STRING);
		prop.setComment("Example: minecraft:stained_glass#11->minecraft:dye#4; minecraft:wool->4*minecraft:string");
		userRecipeCat.put("custom", prop);
	}
	for(Property p : userRecipeCat.values()){
		String[] recipes = p.getString().split(";");
		for(String r : recipes){
			String recipe = r.trim();
			if(recipe.isEmpty()) continue;
			if(recipe.contains("->") == false){
				throw new IllegalArgumentException ("Malformed hammer recipe expression '"+recipe+"'. Should be in format 'modid:itemname->modid:itemname'");
			}
			userCrusherRecipes.add(recipe);
		}
	}

	if(requireOreSpawn) {
		if(!net.minecraftforge.fml.common.Loader.isModLoaded("orespawn")){
			HashSet<ArtifactVersion> orespawnMod = new HashSet<>();
			orespawnMod.add(new DefaultArtifactVersion("1.0.0"));
			throw new MissingModsException(orespawnMod, "orespawn", "DrCyano's Ore Spawn Mod");
		}
		oreSpawnFolder = Paths.get(event.getSuggestedConfigurationFile().toPath().getParent().toString(), "orespawn");
		Path oreSpawnFile = Paths.get(oreSpawnFolder.toString(), MODID + ".json");
		if (Files.exists(oreSpawnFile) == false) {
			try {
				Files.createDirectories(oreSpawnFile.getParent());
				Files.write(oreSpawnFile, Arrays.asList(DataConstants.defaultOreSpawnJSON.split("\n")), Charset.forName("UTF-8"));
			} catch (IOException e) {
				FMLLog.severe(MODID + ": Error: Failed to write file " + oreSpawnFile);
			}
		}
	}

	config.save();

	cyano.basemetals.init.Fluids.init();
	cyano.basemetals.init.Materials.init();
	cyano.basemetals.init.ItemGroups.init();
	cyano.basemetals.init.Blocks.init();
	cyano.basemetals.init.Items.init();
	cyano.basemetals.init.VillagerTrades.init();




	Path ALTPath = Paths.get(event.getSuggestedConfigurationFile().getParent(),"additional-loot-tables");
	Path myLootFolder = ALTPath.resolve(MODID);
	if(Files.notExists(myLootFolder)){
		try{
			Files.createDirectories(myLootFolder.resolve("chests"));
			Files.write(myLootFolder.resolve("chests").resolve("abandoned_mineshaft.json"),
					Arrays.asList(         AdditionalLootTables.abandoned_mineshaft));
			Files.write(myLootFolder.resolve("chests").resolve("desert_pyramid.json"),
					Arrays.asList(         AdditionalLootTables.desert_pyramid));
			Files.write(myLootFolder.resolve("chests").resolve("end_city_treasure.json"),
					Arrays.asList(         AdditionalLootTables.end_city_treasure));
			Files.write(myLootFolder.resolve("chests").resolve("jungle_temple.json"),
					Arrays.asList(         AdditionalLootTables.jungle_temple));
			Files.write(myLootFolder.resolve("chests").resolve("nether_bridge.json"),
					Arrays.asList(         AdditionalLootTables.nether_bridge));
			Files.write(myLootFolder.resolve("chests").resolve("simple_dungeon.json"),
					Arrays.asList(         AdditionalLootTables.simple_dungeon));
			Files.write(myLootFolder.resolve("chests").resolve("spawn_bonus_chest.json"),
					Arrays.asList(         AdditionalLootTables.spawn_bonus_chest));
			Files.write(myLootFolder.resolve("chests").resolve("stronghold_corridor.json"),
					Arrays.asList(         AdditionalLootTables.stronghold_corridor));
			Files.write(myLootFolder.resolve("chests").resolve("stronghold_crossing.json"),
					Arrays.asList(         AdditionalLootTables.stronghold_crossing));
			Files.write(myLootFolder.resolve("chests").resolve("village_blacksmith.json"),
					Arrays.asList(         AdditionalLootTables.village_blacksmith));
		} catch(IOException ex){
			FMLLog.log(Level.ERROR,ex,"%s: Failed to extract additional loot tables",MODID);
		}
	}

	if(event.getSide() == Side.CLIENT){
		clientPreInit(event);
	}
	if(event.getSide() == Side.SERVER){
		serverPreInit(event);
	}
}

@SideOnly(Side.CLIENT)
private void clientPreInit(FMLPreInitializationEvent event){
	// client-only code
	cyano.basemetals.init.Fluids.bakeModels(MODID);

}
@SideOnly(Side.SERVER)
private void serverPreInit(FMLPreInitializationEvent event){
	// server-only code
}

@EventHandler
public void init(FMLInitializationEvent event)
{

	cyano.basemetals.init.Recipes.init();
	cyano.basemetals.init.DungeonLoot.init();
	cyano.basemetals.init.Entities.init();

	cyano.basemetals.init.Achievements.init();


	if(event.getSide() == Side.CLIENT){
		clientInit(event);
	}
	if(event.getSide() == Side.SERVER){
		serverInit(event);
	}
}


@SideOnly(Side.CLIENT)
private void clientInit(FMLInitializationEvent event){
	// client-only code
	cyano.basemetals.init.Items.registerItemRenders(event);
	cyano.basemetals.init.Blocks.registerItemRenders(event);
}
@SideOnly(Side.SERVER)
private void serverInit(FMLInitializationEvent event){
	// server-only code
}

@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	cyano.basemetals.init.WorldGen.init();


	// parse user crusher recipes
	for(String recipe : userCrusherRecipes){
		FMLLog.info(MODID+": adding custom crusher recipe '"+recipe+"'");
		int i = recipe.indexOf("->");
		String inputStr = recipe.substring(0,i);
		String outputStr = recipe.substring(i+2,recipe.length());
		ItemStack input = parseStringAsItemStack(inputStr,true);
		ItemStack output = parseStringAsItemStack(outputStr,false);
		if(input == null || output == null){
			FMLLog.severe("Failed to add recipe formula '"+recipe+"' because the blocks/items could not be found");
		} else {
			CrusherRecipeRegistry.addNewCrusherRecipe(input, output);
		}
	}


	if(autoDetectRecipes){
		// add recipe for every X where the Ore Dictionary has dustX, oreX, and ingotX
		Set<String> dictionary = new HashSet<>();
		dictionary.addAll(Arrays.asList(OreDictionary.getOreNames()));
		for(String entry : dictionary){
			if(entry.contains("Mercury")) continue;
			if(entry.startsWith("dust")){
				String X = entry.substring("dust".length());
				String dustX = entry;
				String ingotX = "ingot".concat(X);
				String oreX = "ore".concat(X);
				if(dictionary.contains(oreX) && dictionary.contains(ingotX) && !OreDictionary.getOres(dustX).isEmpty()){
					ItemStack dustX1 = OreDictionary.getOres(dustX).get(0).copy();
					dustX1.stackSize = 1; 
					ItemStack dustX2 = dustX1.copy();
					dustX2.stackSize = 2; 
					// recipe found
					// but is it already registered
					List<ItemStack> oreBlocks = OreDictionary.getOres(oreX);
					boolean alreadyHasOreRecipe = true;
					for(ItemStack i : oreBlocks){
						alreadyHasOreRecipe = alreadyHasOreRecipe 
								&& (CrusherRecipeRegistry.getInstance().getRecipeForInputItem(i) != null);
					}
					List<ItemStack> ingotStacks = OreDictionary.getOres(ingotX);
					boolean alreadyHasIngotRecipe = true;
					for(ItemStack i : ingotStacks){
						alreadyHasIngotRecipe = alreadyHasIngotRecipe 
								&& (CrusherRecipeRegistry.getInstance().getRecipeForInputItem(i) != null);
					}
					if(!alreadyHasOreRecipe){
						FMLLog.info(MODID+": automatically adding custom crusher recipe \"%s\" -> %s",oreX,dustX2);
						CrusherRecipeRegistry.addNewCrusherRecipe(oreX, dustX2);
					}
					if(!alreadyHasIngotRecipe){
						FMLLog.info(MODID+": automatically adding custom crusher recipe \"%s\" -> %s",ingotX,dustX1);
						CrusherRecipeRegistry.addNewCrusherRecipe(ingotX, dustX1);
					}
				}
			}
		}
	}

	if(event.getSide() == Side.CLIENT){
		clientPostInit(event);
	}
	if(event.getSide() == Side.SERVER){
		serverPostInit(event);
	}

	CrusherRecipeRegistry.getInstance().clearCache();
}


@SideOnly(Side.CLIENT)
private void clientPostInit(FMLPostInitializationEvent event){
	// client-only code
}
@SideOnly(Side.SERVER)
private void serverPostInit(FMLPostInitializationEvent event){
	// server-only code
}


/**
 * Parses a String in the format (stack-size)*(modid):(item/block name)#(metadata value). The 
 * stacksize and metadata value parameters are optional.
 * @param str A String describing an itemstack (e.g. "4*minecraft:dye#15" or "minecraft:bow")
 * @param allowWildcard If true, then item strings that do not specify a metadata value will use 
 * the OreDictionary wildcard value. If false, then the default meta value is 0 instead.
 * @return An ItemStack representing the item, or null if the item is not found
 */
public static ItemStack parseStringAsItemStack(String str, boolean allowWildcard){
	str = str.trim();
	int count = 1;
	int meta;
	if(allowWildcard){
		meta = OreDictionary.WILDCARD_VALUE;
	} else {
		meta = 0;
	}
	int nameStart = 0;
	int nameEnd = str.length();
	if(str.contains("*")){
		count = Integer.parseInt(str.substring(0,str.indexOf("*")).trim());
		nameStart = str.indexOf("*")+1;
	}
	if(str.contains("#")){
		meta = Integer.parseInt(str.substring(str.indexOf("#")+1,str.length()).trim());
		nameEnd = str.indexOf("#");
	}
	String id = str.substring(nameStart,nameEnd).trim();
	if(Block.getBlockFromName(id) != null){
		// is a block
		return new ItemStack(Block.getBlockFromName(id),count,meta);
	} else if(Item.getByNameOrId(id) != null){
		// is an item
		return new ItemStack(Item.getByNameOrId(id),count,meta);
	} else {
		// item not found
		FMLLog.severe("Failed to find item or block for ID '"+id+"'");
		return null;
	}
}




}

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You can try other builds of Quark/Zeta
    • Hello all, I recently tried to upgrade my Minecraft mod to version 1.21.3, and I seem to have a problem with the `RenderSystem#setShaderColor` method. Here is how the screen is usually supposed to look like: Here is how it looks at present: To further explain, the note labels atop of the note buttons are colored cyan (here) using `RenderSystem#setShaderColor`. The note buttons and labels get their colors from their native texture - white. This means that even though I set the coloring to apply to the label (top), it is applied to the button (bottom). What I conclude is happening then, in essence, is that this method (at least for my case) does not color the blit after - but rather the blit before..?  This also blocks me from later resetting the shader, as I need to set it back to white before the blitting is done, and not when it's done. So like... what? I've tested this further with other components that require this method, and this preceding-like behavior seems to be pretty consistent for them too.   I should mention that all the snippets I am about to show have all worked in past versions. In my class `ClientUtil`, the following methods are defined: public static void setShaderColor(final Color color, final float alpha) { RenderSystem.setShaderColor( color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, alpha ); } public static void setShaderColor(final Color color) { setShaderColor(color, 1); } public static void resetShaderColor() { setShaderColor(Color.WHITE); } //... public static RenderType guiRT(final ResourceLocation loc) { return RenderType.guiTextured(loc); } And here is the snippet from `NoteButtonRenderer#renderNote` using it: // "Note" here refers to those symbols in the middle of a note button protected void renderNote(final GuiGraphics gui, final InstrumentThemeLoader themeLoader) { final int noteWidth = noteButton.getWidth()/2, noteHeight = noteButton.getHeight()/2; ClientUtil.setShaderColor((noteButton.isPlaying() && !foreignPlaying) ? themeLoader.notePressed() : themeLoader.noteReleased() ); gui.blit(ClientUtil::guiRT, noteTextureProvider.get(), noteButton.getX() + noteWidth/2, noteButton.getY() + noteHeight/2, 0, 0, noteWidth, noteHeight, noteWidth, noteButton.getHeight()/2 ); ClientUtil.resetShaderColor(); } You may find the full source here. The odd thing is that Minecraft does seem to use this method the regular way I showed, for instance `SkyRenderer#renderSkyDisc` (not sure if I'l allowed to paste it). Could it be that I'm doing something wrong that leads to this issue..? I'm really stumped on this one.  I couldn't really find any change logs or documentation for this rendering API (even in this Fabric blog post), so I'm sorry if this seems obvious or anything.  Either way, any help would be appreciated.
    • This did work. rip Quark Thank you
    • It says Quark Requires zeta. do i just remove Quark? https://mclo.gs/cq799kI
    • It refers to the mod elenaidodge Backup the world and make a test without it
  • Topics

×
×
  • Create New...

Important Information

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