Skip to content

Commit

Permalink
compact
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Oct 16, 2024
1 parent 65cf412 commit bb1fb0f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.hiedacamellia.mystiasizakaya.core.recipes.MIRecipeInput;
import org.hiedacamellia.mystiasizakaya.integration.youkaihomecoming.IngredientsCompact;
import org.hiedacamellia.mystiasizakaya.integration.compact.IngredientsCompact;
import org.hiedacamellia.mystiasizakaya.registries.MIItem;
import org.hiedacamellia.mystiasizakaya.registries.MIRecipeType;
import org.hiedacamellia.mystiasizakaya.util.GetItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hiedacamellia.mystiasizakaya.integration.compact;

import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.hiedacamellia.mystiasizakaya.registries.MITag;
import org.hiedacamellia.mystiasizakaya.util.Tag2Item;

public class IngredientsCompact {
public static ItemStack execute(ItemStack itemstack) {
for(TagKey<Item> key:MITag.ingredients.values()){
if(itemstack.is(key)){
return Tag2Item.regs.get(key).getDefaultInstance();
}
}
return itemstack;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class MITag {
public static TagKey<Item> ingredientsKey = ItemTags.create(ResourceLocation.parse("mystias_izakaya:ingredients"));
public static TagKey<Item> kitchenwaresKey = ItemTags.create(ResourceLocation.parse("mystias_izakaya:kitchenwares"));

public static Map<String,TagKey<Item>> ingredients = getKnownIngredients().stream().collect(Collectors.toMap(s->s,s-> ItemTags.create(ResourceLocation.fromNamespaceAndPath(MystiasIzakaya.MODID,s))));
public static Map<String,TagKey<Item>> ingredients = getKnownIngredients();

public static List<String> getKnownIngredients(){
public static Map<String,TagKey<Item>> getKnownIngredients(){
Collection<DeferredHolder<Item, ? extends Item>> knownIngredients = MIItem.Ingredients.getEntries();
List<String> regs =new ArrayList<>();
for(DeferredHolder<Item, ? extends Item> item: knownIngredients){
regs.add(BuiltInRegistries.ITEM.getKey(item.get()).getPath());
}
return regs;
return regs.stream().collect(Collectors.toMap(s->s,s-> ItemTags.create(ResourceLocation.fromNamespaceAndPath(MystiasIzakaya.MODID,s))));
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/hiedacamellia/mystiasizakaya/util/Tag2Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hiedacamellia.mystiasizakaya.util;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.neoforged.neoforge.registries.DeferredHolder;
import org.hiedacamellia.mystiasizakaya.registries.MIItem;
import org.hiedacamellia.mystiasizakaya.registries.MITag;

import java.util.*;


public class Tag2Item {

public static Map<TagKey<Item>,Item> regs = get();

public static Map<TagKey<Item>,Item> get() {
Collection<DeferredHolder<Item, ? extends Item>> knownIngredients = MIItem.Ingredients.getEntries();
Map<TagKey<Item>,Item> regs = new HashMap<>();
Map<String,TagKey<Item>> ingredients = MITag.getKnownIngredients();
for(DeferredHolder<Item, ? extends Item> item: knownIngredients){
regs.put(ingredients.get(BuiltInRegistries.ITEM.getKey(item.get()).getPath()),item.get());
}
return regs;
}
}

0 comments on commit bb1fb0f

Please sign in to comment.