下面列出了怎么用net.minecraft.util.profiler.Profiler的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected Map<Identifier, Properties> prepare(ResourceManager manager, Profiler profiler) {
Collection<Identifier> ids = manager.findResources("textures", s -> s.endsWith(SUFFIX));
Map<Identifier, Properties> result = new HashMap<>();
for (Identifier input : ids) {
try (Resource resource = manager.getResource(input);
InputStream stream = resource.getInputStream()) {
Properties props = new Properties();
props.load(stream);
Identifier textureId = new Identifier(input.getNamespace(), input.getPath().substring(0, input.getPath().length() - SUFFIX.length()));
result.put(textureId, props);
} catch (Exception e) {
LibGuiClient.logger.error("Error while loading metadata file {}, skipping...", input, e);
}
}
return result;
}
@Override
protected void apply(Map<Identifier, Properties> meta, ResourceManager manager, Profiler profiler) {
properties = new HashMap<>();
for (Map.Entry<Identifier, Properties> entry : meta.entrySet()) {
Identifier id = entry.getKey();
Properties props = entry.getValue();
Mode mode = TextureProperties.DEFAULT.getMode();
// float cornerUv = TextureProperties.DEFAULT.getCornerUv();
if (props.containsKey("mode")) {
String modeStr = props.getProperty("mode");
mode = Mode.fromString(modeStr);
if (mode == null) {
LibGuiClient.logger.error("Invalid mode '{}' in nine-patch metadata file for texture {}", modeStr, id);
continue;
}
}
// if (props.containsKey("cornerUv")) {
// cornerUv = Float.parseFloat(props.getProperty("cornerUv"));
// }
TextureProperties texProperties = new TextureProperties(mode);
properties.put(id, texProperties);
}
}
@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;addLightning(Lnet/minecraft/entity/LightningEntity;)V"
))
private void onNaturalLightinig(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci,
ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos, boolean bl2)
{
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
}
@Inject(method = "tickBlockEntities", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/entity/BlockEntity;isRemoved()Z",
shift = At.Shift.BEFORE,
ordinal = 0
))
private void startTileEntitySection(CallbackInfo ci, Profiler profiler_1, Iterator i, BlockEntity blockEntity_2)
{
entitySection = CarpetProfiler.start_entity_section((World)(Object)this, blockEntity_2, CarpetProfiler.TYPE.TILEENTITY);
}
@Override
public CompletableFuture<Void> reload(Synchronizer sync, ResourceManager sender,
Profiler serverProfiler, Profiler clientProfiler,
Executor serverExecutor, Executor clientExecutor) {
sync.getClass();
return sync.whenPrepared(null).thenRunAsync(() -> {
clientProfiler.startTick();
clientProfiler.push("Reloading all background ponies");
poniesCache.invalidateAll();
backgroundPonyList.reloadAll(sender);
clientProfiler.pop();
clientProfiler.endTick();
}, clientExecutor);
}
@Inject(method = "stitch", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/SpriteAtlasTexture;loadSprites(Lnet/minecraft/resource/ResourceManager;Ljava/util/Set;)Ljava/util/Collection;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
private void onStitch(ResourceManager resourceManager, Iterable<Identifier> iterable, Profiler profiler, CallbackInfoReturnable<SpriteAtlasTexture.Data> cir, Set<Identifier> set) {
RenderEvents.onTextureStitchPre((SpriteAtlasTexture) (Object) this, set);
}
protected MixinServerWorld(LevelProperties levelProperties, DimensionType dimensionType, BiFunction<World, Dimension, ChunkManager> chunkManagerProvider, Profiler profiler, boolean isClient) {
super(levelProperties, dimensionType, chunkManagerProvider, profiler, isClient);
}
protected MixinClientWorld(LevelProperties levelProperties, DimensionType dimensionType, BiFunction<World, Dimension, ChunkManager> chunkManagerProvider, Profiler profiler, boolean isClient) {
super(levelProperties, dimensionType, chunkManagerProvider, profiler, isClient);
}
protected ServerWorld_tickMixin(LevelProperties levelProperties_1, DimensionType dimensionType_1, BiFunction<World, Dimension, ChunkManager> biFunction_1, Profiler profiler_1, boolean boolean_1)
{
super(levelProperties_1, dimensionType_1, biFunction_1, profiler_1, boolean_1);
}
protected WorldMixin_RealTime(MutableWorldProperties mutableWorldProperties, RegistryKey<World> registryKey, RegistryKey<DimensionType> registryKey2, DimensionType dimensionType, Supplier<Profiler> profiler, boolean bl, boolean bl2, long l) {
super(mutableWorldProperties, registryKey, registryKey2, dimensionType, profiler, bl, bl2, l);
}