refactor limit access to built-in registries

This commit is contained in:
gnembon committed 2023-01-18 04:07:55 +01:00
1 parent 8dd08d5cb1
commit bd5dfdbf9f
25 files changed
+243 -176

No files matched your search

@@ -139,12 +139,12 @@ public class Auxiliary {
CarpetContext cc = (CarpetContext)c;
if (lv.size() == 0)
{
return ListValue.wrap(BuiltInRegistries.SOUND_EVENT.keySet().stream().map(ValueConversions::of));
return ListValue.wrap(cc.registry(Registries.SOUND_EVENT).keySet().stream().map(ValueConversions::of));
}
String rawString = lv.get(0).getString();
ResourceLocation soundName = InputValidator.identifierOf(rawString);
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
if (BuiltInRegistries.SOUND_EVENT.get(soundName) == null)
if (cc.registry(Registries.SOUND_EVENT).get(soundName) == null)
throw new ThrowStatement(rawString, Throwables.UNKNOWN_SOUND);
final Holder<SoundEvent> soundHolder = Holder.direct(SoundEvent.createVariableRangeEvent(soundName));
float volume = 1.0F;
@@ -180,7 +180,7 @@ public class Auxiliary {
expression.addContextFunction("particle", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext)c;
if (lv.size() == 0) return ListValue.wrap(BuiltInRegistries.PARTICLE_TYPE.keySet().stream().map(ValueConversions::of));
if (lv.size() == 0) return ListValue.wrap(cc.registry(Registries.PARTICLE_TYPE).keySet().stream().map(ValueConversions::of));
MinecraftServer ms = cc.server();
ServerLevel world = cc.level();
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
@@ -756,21 +756,20 @@ public class Auxiliary {
{
Map<Value, Value> plopData = new HashMap<>();
CarpetContext cc = (CarpetContext)c;
RegistryAccess registryManager = cc.registryAccess();
plopData.put(StringValue.of("scarpet_custom"),
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of).collect(Collectors.toList()))
);
plopData.put(StringValue.of("features"),
ListValue.wrap(BuiltInRegistries.FEATURE.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
ListValue.wrap(cc.registry(Registries.FEATURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
);
plopData.put(StringValue.of("configured_features"),
ListValue.wrap(registryManager.registryOrThrow(Registries.CONFIGURED_FEATURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
ListValue.wrap(cc.registry(Registries.CONFIGURED_FEATURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
);
plopData.put(StringValue.of("structure_types"),
ListValue.wrap(BuiltInRegistries.STRUCTURE_TYPE.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
ListValue.wrap(cc.registry(Registries.STRUCTURE_TYPE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
);
plopData.put(StringValue.of("structures"),
ListValue.wrap(registryManager.registryOrThrow(Registries.STRUCTURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
ListValue.wrap(cc.registry(Registries.STRUCTURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
);
return MapValue.wrap(plopData);
}
@@ -966,7 +965,7 @@ public class Auxiliary {
ResourceLocation statName;
category = InputValidator.identifierOf(lv.get(1).getString());
statName = InputValidator.identifierOf(lv.get(2).getString());
StatType<?> type = BuiltInRegistries.STAT_TYPE.get(category);
StatType<?> type = cc.registry(Registries.STAT_TYPE).get(category);
if (type == null) return Value.NULL;
Stat<?> stat = getStat(type, statName);
if (stat == null) return Value.NULL;