refactor limit access to built-in registries
This commit is contained in:
1 parent
8dd08d5cb1
commit
bd5dfdbf9f
25 files changed
+243
-176
No files matched your search
@@ -4,7 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
@@ -227,6 +229,7 @@ public class BlockInfo
|
||||
Material material = state.getMaterial();
|
||||
Block block = state.getBlock();
|
||||
String metastring = "";
|
||||
final Registry<Block> blocks = world.registryAccess().registryOrThrow(Registries.BLOCK);
|
||||
for (net.minecraft.world.level.block.state.properties.Property<?> iproperty : state.getProperties())
|
||||
{
|
||||
metastring += ", "+iproperty.getName() + '='+state.getValue(iproperty);
|
||||
@@ -234,7 +237,7 @@ public class BlockInfo
|
||||
List<Component> lst = new ArrayList<>();
|
||||
lst.add(Messenger.s(""));
|
||||
lst.add(Messenger.s("====================================="));
|
||||
lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):", BuiltInRegistries.BLOCK.getKey(block),metastring, BuiltInRegistries.BLOCK.getId(block), metastring )));
|
||||
lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):", blocks.getKey(block),metastring, blocks.getId(block), metastring )));
|
||||
lst.add(Messenger.s(String.format(" - Material: %s", materialName.get(material))));
|
||||
lst.add(Messenger.s(String.format(" - Map colour: %s", mapColourName.get(state.getMapColor(world, pos)))));
|
||||
lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundType(state)))));
|
||||
|
||||
@@ -3,7 +3,9 @@ package carpet.utils;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -274,13 +276,14 @@ public class CarpetProfiler
|
||||
private static String sectionName(Pair<Level,Object> section)
|
||||
{
|
||||
ResourceLocation id;
|
||||
final RegistryAccess regs = section.getKey().registryAccess();
|
||||
if (section.getValue() instanceof EntityType)
|
||||
{
|
||||
id = BuiltInRegistries.ENTITY_TYPE.getKey((EntityType<?>) section.getValue());
|
||||
id = regs.registryOrThrow(Registries.ENTITY_TYPE).getKey((EntityType<?>) section.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
id = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey((BlockEntityType<?>) section.getValue());
|
||||
id = regs.registryOrThrow(Registries.BLOCK_ENTITY_TYPE).getKey((BlockEntityType<?>) section.getValue());
|
||||
}
|
||||
String name = "minecraft".equals(id.getNamespace())?id.getPath():id.toString();
|
||||
if (section.getKey().isClientSide)
|
||||
|
||||
@@ -8,8 +8,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -54,14 +57,14 @@ public class MobAI
|
||||
aiTrackers.get(e).add(type);
|
||||
}
|
||||
|
||||
public static List<String> availbleTypes()
|
||||
public static List<String> availbleTypes(CommandSourceStack source)
|
||||
{
|
||||
Set<EntityType<?>> types = new HashSet<>();
|
||||
for (TrackingType type: TrackingType.values())
|
||||
{
|
||||
types.addAll(type.types);
|
||||
}
|
||||
return types.stream().map(t -> BuiltInRegistries.ENTITY_TYPE.getKey(t).getPath()).collect(Collectors.toList());
|
||||
return types.stream().map(t -> source.registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getKey(t).getPath()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<String> availableFor(EntityType<?> entityType)
|
||||
|
||||
Reference in new issue
Block a user