Integrated recipes
This commit is contained in:
parent
f4239f1838
commit
a55a7ac473
3 changed files with 289 additions and 264 deletions
|
@ -771,7 +771,7 @@ public class WarpDrive {
|
||||||
final static public ArrayList<Potion> potions = new ArrayList<>(10);
|
final static public ArrayList<Potion> potions = new ArrayList<>(10);
|
||||||
final static public ArrayList<PotionType> potionTypes = new ArrayList<>(10);
|
final static public ArrayList<PotionType> potionTypes = new ArrayList<>(10);
|
||||||
final static public ArrayList<SoundEvent> soundEvents = new ArrayList<>(100);
|
final static public ArrayList<SoundEvent> soundEvents = new ArrayList<>(100);
|
||||||
final static public ArrayList<IRecipe> recipes = new ArrayList<>(100);
|
final static public HashMap<ResourceLocation, IRecipe> recipes = new HashMap<>(100);
|
||||||
final static public ArrayList<VillagerProfession> villagerProfessions = new ArrayList<>(10);
|
final static public ArrayList<VillagerProfession> villagerProfessions = new ArrayList<>(10);
|
||||||
|
|
||||||
// Register a Biome.
|
// Register a Biome.
|
||||||
|
@ -793,7 +793,8 @@ public class WarpDrive {
|
||||||
public static <BLOCK extends Block> BLOCK register(final BLOCK block, @Nullable final ItemBlock itemBlock) {
|
public static <BLOCK extends Block> BLOCK register(final BLOCK block, @Nullable final ItemBlock itemBlock) {
|
||||||
final ResourceLocation resourceLocation = block.getRegistryName();
|
final ResourceLocation resourceLocation = block.getRegistryName();
|
||||||
if (resourceLocation == null) {
|
if (resourceLocation == null) {
|
||||||
WarpDrive.logger.error(String.format("Missing registry name for block %s, ignoring registration...", block));
|
WarpDrive.logger.error(String.format("Missing registry name for block %s, ignoring registration...",
|
||||||
|
block));
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,6 +834,9 @@ public class WarpDrive {
|
||||||
|
|
||||||
// Register a recipe.
|
// Register a recipe.
|
||||||
public static <RECIPE extends IRecipe> RECIPE register(final RECIPE recipe) {
|
public static <RECIPE extends IRecipe> RECIPE register(final RECIPE recipe) {
|
||||||
|
return register(recipe, "");
|
||||||
|
}
|
||||||
|
public static <RECIPE extends IRecipe> RECIPE register(final RECIPE recipe, final String suffix) {
|
||||||
ResourceLocation registryName = recipe.getRegistryName();
|
ResourceLocation registryName = recipe.getRegistryName();
|
||||||
if (registryName == null) {
|
if (registryName == null) {
|
||||||
final String path;
|
final String path;
|
||||||
|
@ -840,20 +844,33 @@ public class WarpDrive {
|
||||||
if (itemStackOutput.isEmpty()) {
|
if (itemStackOutput.isEmpty()) {
|
||||||
path = recipe.toString();
|
path = recipe.toString();
|
||||||
} else if (itemStackOutput.getCount() == 1) {
|
} else if (itemStackOutput.getCount() == 1) {
|
||||||
path = String.format("%s@%d",
|
path = String.format("%s@%d%s",
|
||||||
itemStackOutput.getItem().getUnlocalizedName(),
|
itemStackOutput.getItem().getRegistryName(),
|
||||||
itemStackOutput.getItemDamage() );
|
|
||||||
} else {
|
|
||||||
path = String.format("%s@%dx%d",
|
|
||||||
itemStackOutput.getItem().getUnlocalizedName(),
|
|
||||||
itemStackOutput.getItemDamage(),
|
itemStackOutput.getItemDamage(),
|
||||||
itemStackOutput.getCount() );
|
suffix );
|
||||||
|
} else {
|
||||||
|
path = String.format("%s@%dx%d%s",
|
||||||
|
itemStackOutput.getItem().getRegistryName(),
|
||||||
|
itemStackOutput.getItemDamage(),
|
||||||
|
itemStackOutput.getCount(),
|
||||||
|
suffix );
|
||||||
}
|
}
|
||||||
registryName = new ResourceLocation(MODID, path);
|
registryName = new ResourceLocation(MODID, path);
|
||||||
|
if (recipes.containsKey(registryName)) {
|
||||||
|
logger.error(String.format("Overlapping recipe detected, please report this to the mod author %s",
|
||||||
|
registryName));
|
||||||
|
registryName = new ResourceLocation(MODID, path + "!" + System.nanoTime());
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
recipe.setRegistryName(registryName);
|
recipe.setRegistryName(registryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
recipes.add(recipe);
|
recipes.put(registryName, recipe);
|
||||||
return recipe;
|
return recipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -998,7 +1015,7 @@ public class WarpDrive {
|
||||||
|
|
||||||
Recipes.initDynamic();
|
Recipes.initDynamic();
|
||||||
|
|
||||||
for (final IRecipe recipe : recipes) {
|
for (final IRecipe recipe : recipes.values()) {
|
||||||
event.getRegistry().register(recipe);
|
event.getRegistry().register(recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.EnumDyeColor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -29,7 +30,7 @@ public class RecipeTuningDriver implements IRecipe {
|
||||||
private final int size;
|
private final int size;
|
||||||
private ResourceLocation group;
|
private ResourceLocation group;
|
||||||
|
|
||||||
public RecipeTuningDriver(@Nonnull final ResourceLocation group, final ItemStack itemStackTool, final ItemStack itemStackConsumable, final int countDyes) {
|
public RecipeTuningDriver(@Nonnull final ResourceLocation group, final ItemStack itemStackTool, final ItemStack itemStackConsumable, final int countDyes, final String suffix) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.itemStackTool = itemStackTool.copy();
|
this.itemStackTool = itemStackTool.copy();
|
||||||
this.itemStackConsumable = itemStackConsumable.copy();
|
this.itemStackConsumable = itemStackConsumable.copy();
|
||||||
|
@ -43,7 +44,7 @@ public class RecipeTuningDriver implements IRecipe {
|
||||||
for (int index = 0; index < countDyes; index++) {
|
for (int index = 0; index < countDyes; index++) {
|
||||||
recipe[2 + index] = "dye";
|
recipe[2 + index] = "dye";
|
||||||
}
|
}
|
||||||
WarpDrive.register(new ShapelessOreRecipe(group, itemStackTool, recipe));
|
WarpDrive.register(new ShapelessOreRecipe(group, itemStackTool, recipe), suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,14 +118,14 @@ public class RecipeTuningDriver implements IRecipe {
|
||||||
} else {
|
} else {
|
||||||
// find a matching dye from ore dictionary
|
// find a matching dye from ore dictionary
|
||||||
boolean matched = false;
|
boolean matched = false;
|
||||||
for (int indexDye = 0; indexDye < Recipes.oreDyes.length; indexDye++) {
|
for (final EnumDyeColor enumDyeColor : EnumDyeColor.values()) {
|
||||||
final List<ItemStack> itemStackDyes = OreDictionary.getOres(Recipes.oreDyes[indexDye]);
|
final List<ItemStack> itemStackDyes = OreDictionary.getOres("dye" + enumDyeColor.getUnlocalizedName());
|
||||||
for (final ItemStack itemStackDye : itemStackDyes) {
|
for (final ItemStack itemStackDye : itemStackDyes) {
|
||||||
if (OreDictionary.itemMatches(itemStackSlot, itemStackDye, true)) {
|
if (OreDictionary.itemMatches(itemStackSlot, itemStackDye, true)) {
|
||||||
// match found, update dye combination
|
// match found, update dye combination
|
||||||
matched = true;
|
matched = true;
|
||||||
countDyesFound++;
|
countDyesFound++;
|
||||||
dye = dye * 16 + indexDye;
|
dye = dye * 16 + enumDyeColor.getDyeDamage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue