45a great reg split

This commit is contained in:
gnembon committed 2022-11-10 20:51:10 +01:00
1 parent 48c804fcaa
commit cda6994cae
28 files changed
+164 -153

No files matched your search

@@ -30,6 +30,8 @@ import java.util.stream.Collectors;
import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
@@ -65,11 +67,11 @@ public class Inventories {
expression.addContextFunction("item_list", -1, (c, t, lv) ->
{
if (lv.size() == 0)
return ListValue.wrap(Registry.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
return ListValue.wrap(BuiltInRegistries.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
CarpetContext cc = (CarpetContext)c;
Registry<Item> items = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
Registry<Item> items = cc.s.getServer().registryAccess().registryOrThrow(Registries.ITEM);
String tag = lv.get(0).getString();
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
if (itemTag.isEmpty()) return Value.NULL;
return ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))).collect(Collectors.toList()));
/*
@@ -85,7 +87,7 @@ public class Inventories {
{
CarpetContext cc = (CarpetContext)c;
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registries.ITEM);
if (lv.size() == 0)
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.s.registryAccess()).getItem();
@@ -94,7 +96,7 @@ public class Inventories {
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
}
String tag = lv.get(1).getString();
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
if (tagSet.isEmpty()) return Value.NULL;
//return BooleanValue.of(tagSet.get().contains(item.builtInRegistryHolder()));
@@ -123,7 +125,7 @@ public class Inventories {
if (lv.size() > 1)
{
String recipeType = lv.get(1).getString();
type = Registry.RECIPE_TYPE.get(InputValidator.identifierOf(recipeType));
type = BuiltInRegistries.RECIPE_TYPE.get(InputValidator.identifierOf(recipeType));
}
List<Recipe<?>> recipes;
recipes = ((RecipeManagerInterface) cc.s.getServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
@@ -197,9 +199,9 @@ public class Inventories {
String itemStr = v.getString();
Item item;
ResourceLocation id = InputValidator.identifierOf(itemStr);
item = Registry.ITEM.getOptional(id).orElseThrow(() -> new ThrowStatement(itemStr, Throwables.UNKNOWN_ITEM));
item = BuiltInRegistries.ITEM.getOptional(id).orElseThrow(() -> new ThrowStatement(itemStr, Throwables.UNKNOWN_ITEM));
if (!item.hasCraftingRemainingItem()) return Value.NULL;
return new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.ITEM.getKey(item.getCraftingRemainingItem())));
return new StringValue(NBTSerializableValue.nameFromRegistryId(BuiltInRegistries.ITEM.getKey(item.getCraftingRemainingItem())));
});
expression.addContextFunction("inventory_size", -1, (c, t, lv) ->