下面列出了net.minecraft.util.NonNullList#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ItemStack getResultItemStack(FluidStack fluid, ItemStack stack) {
for (Entry<FluidStack, Map<Object, ItemStack>> entry : RecipesList.entrySet()) {
if(entry.getKey().isFluidEqual(fluid))
for (Entry<Object, ItemStack> entry2 : entry.getValue().entrySet()) {
if (entry2.getKey() instanceof ItemStack) {
if (ItemStack.areItemsEqual(stack, (ItemStack) entry2.getKey())) {
return entry2.getValue();
}
} else if (entry2.getKey() instanceof String) {
String dict = (String) entry2.getKey();
NonNullList<ItemStack> ore = OreDictionary.getOres(dict);
if (!ore.isEmpty() && RecipesUtil.containsMatch(true, ore, stack))
return entry2.getValue();
}
}
}
return ItemStack.EMPTY;
}
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ings = NonNullList.create();
for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
ings.add(CraftingHelper.getIngredient(ele, context));
if (ings.isEmpty())
throw new JsonParseException("No ingredients for shapeless recipe");
JsonObject result = JsonUtils.getJsonObject(json, "result");
String name = JsonUtils.getString(result, "name");
int amount = JsonUtils.getInt(result, "amount", 1);
ItemStack stack = ItemStack.EMPTY;
for (MetaItem<?> item : MetaItems.ITEMS) {
MetaItem<?>.MetaValueItem value = item.getItem(name);
if (value != null) {
stack = value.getStackForm(amount);
}
}
return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, stack);
}
public FluidStack getResultFluidStack(FluidStack fluid, ItemStack[] inputs) {
for (Entry<FluidStack, Map<Object[], FluidStack>> entry : RecipesList.entrySet()) {
if(entry.getKey().isFluidEqual(fluid))
for(Entry<Object[], FluidStack> entry2 : entry.getValue().entrySet()){
boolean flg1 = true;
for (Object obj1 : entry2.getKey()) {
boolean flg2 = false;
for (ItemStack input:inputs) {
if(obj1 instanceof ItemStack){
ItemStack stack1 = (ItemStack) obj1;
if (ItemStack.areItemsEqual(stack1, input)) {
flg2 = true;
break;
}
}else if(obj1 instanceof String){
NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
flg2 = true;
break;
}
}
}
if (!flg2) {
flg1 = false;
break;
}
}
if (flg1) {
return entry2.getValue();
}
}
}
return null;
}
public ItemStack getResultItemStack(FluidStack fluid, List<ItemStack> inputs) {
for (Entry<FluidStack, Map<Object[], ItemStack>> entry : RecipesList.entrySet()) {
if(entry.getKey().isFluidEqual(fluid))
for(Entry<Object[], ItemStack> entry2 : entry.getValue().entrySet()){
boolean flg1 = true;
if ((inputs.size() != entry2.getKey().length))
continue;
for (Object obj1 : entry2.getKey()) {
boolean flg2 = false;
for (ItemStack input:inputs) {
if(obj1 instanceof ItemStack){
ItemStack stack1 = (ItemStack) obj1;
if (ItemStack.areItemsEqual(stack1, input)) {
flg2 = true;
break;
}
}else if(obj1 instanceof String){
NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
flg2 = true;
break;
}
}
}
if (!flg2) {
flg1 = false;
break;
}
}
if (flg1) {
return entry2.getValue();
}
}
}
return ItemStack.EMPTY;
}
public FluidStack getResultFluidStack(FluidStack fluid, ItemStack[] inputs) {
for (Entry<FluidStack, Map<Object[], FluidStack>> entry : RecipesList.entrySet()) {
if(entry.getKey().isFluidEqual(fluid))
for(Entry<Object[], FluidStack> entry2 : entry.getValue().entrySet()){
boolean flg1 = true;
for (Object obj1 : entry2.getKey()) {
boolean flg2 = false;
for (ItemStack input:inputs) {
if(obj1 instanceof ItemStack){
ItemStack stack1 = (ItemStack) obj1;
if (ItemStack.areItemsEqual(stack1, input)) {
flg2 = true;
break;
}
}else if(obj1 instanceof String){
NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
flg2 = true;
break;
}
}
}
if (!flg2) {
flg1 = false;
break;
}
}
if (flg1) {
return entry2.getValue();
}
}
}
return null;
}
public ItemStack[] getResult(List<ItemStack> inputs) {
ItemStack[] retStack = new ItemStack[0];
for(Entry<Object[], ItemStack[]> entry : RecipesList.entrySet()){
boolean flg1 = true;
if ((inputs.size() != entry.getKey().length))
continue;
for (Object obj1 : entry.getKey()) {
boolean flg2 = false;
for (ItemStack input:inputs) {
if(input.isEmpty()) break;
if(obj1 instanceof ItemStack){
ItemStack stack1 = (ItemStack) obj1;
if (ItemStack.areItemsEqual(stack1, input)) {
inputs.remove(input);
flg2 = true;
break;
}
}else if(obj1 instanceof String){
NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
inputs.remove(input);
flg2 = true;
break;
}
}
}
if (!flg2) {
flg1 = false;
break;
}
}
if (flg1) {
return entry.getValue();
}
}
return retStack;
}
public static ItemStack getStackFromOreDict(String entry) {
ItemStack stack = null;
if (OreDictionary.doesOreNameExist(entry)) {
NonNullList<ItemStack> list = OreDictionary.getOres(entry, false);
if (!list.isEmpty()) {
stack = list.get(0);
}
}
return stack;
}
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ings = NonNullList.create();
for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
ings.add(CraftingHelper.getIngredient(ele, context));
if (ings.isEmpty())
throw new JsonParseException("No ingredients for shapeless recipe");
ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
int[] damage = new int[ings.size()];
if (JsonUtils.hasField(json, "damage"))
{
JsonArray array = JsonUtils.getJsonArray(json, "damage");
if (array.size() > damage.length)
throw new JsonParseException("Too many values for damage array: got " + array.size() + ", expected " + damage.length);
for (int i = 0; i < array.size(); i++)
{
JsonElement element = array.get(i);
if (!element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber())
throw new JsonSyntaxException("Entry in damage array is not a number, got " + element);
damage[i] = element.getAsJsonPrimitive().getAsInt();
}
}
return new DamageableShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), damage, ings, itemstack);
}
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ingredients = NonNullList.create();
for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients"))
ingredients.add(CraftingHelper.getIngredient(element, context));
if (ingredients.isEmpty())
throw new JsonParseException("No ingredients in shapeless recipe");
ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients);
return recipe;
}
/** Ran post init **/
public static void createUniversalProcessingRecipes() {
String[] oreDict = OreDictionary.getOreNames();
int oreDictSize = oreDict.length;
for (int i = 0; i < oreDictSize; ++i) {
String id = oreDict[i];
String dust;
NonNullList<ItemStack> list;
// block to dust iterator
if (id.startsWith("block")) {
dust = "dust" + id.substring(5);
if (OreDictionary.doesOreNameExist(dust)) {
list = OreDictionary.getOres(dust, false);
if (!list.isEmpty() && !id.contains("Chromium") && !id.contains("Aluminum") && !id.contains("Coal")
&& !id.contains("Charcoal") && !id.contains("Quartz") && !id.contains("Prismarine")) {
TileEntityMacerator.addRecipe((String) id, 1, GTHelperStack.copyWithSize((ItemStack) list.get(0), 9), 0.1F);
}
}
}
// ingot to block iterator
String block;
if (id.startsWith("ingot")) {
block = "block" + id.substring(5);
if (OreDictionary.doesOreNameExist(block)) {
list = OreDictionary.getOres(block, false);
if (!list.isEmpty() && !id.contains("Copper") && !id.contains("Chromium")
&& !id.contains("Aluminum")) {
TileEntityCompressor.addRecipe((String) id, 9, GTHelperStack.copyWithSize((ItemStack) list.get(0), 1), 0.1F);
}
}
} else
// gems to block iterator
if (id.startsWith("gem")) {
block = "block" + id.substring(3);
if (OreDictionary.doesOreNameExist(block)) {
list = OreDictionary.getOres(block, false);
if (!list.isEmpty() && !id.contains("Coal") && !id.contains("Quartz")) {
TileEntityCompressor.addRecipe((String) id, 9, GTHelperStack.copyWithSize((ItemStack) list.get(0), 1), 0.1F);
}
}
}
}
}