Some minor 1.19 migrations

This commit is contained in:
Frank 2022-05-10 19:08:05 +02:00
parent 50f623477f
commit 4ba3a71a68
14 changed files with 60 additions and 55 deletions

View file

@ -7,7 +7,7 @@ import net.fabricmc.loader.api.metadata.ModEnvironment;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import ru.bclib.BCLib;
import ru.bclib.api.dataexchange.DataExchangeAPI;
@ -380,7 +380,7 @@ public class HelloClient extends DataHandler.FromServer {
showSyncFilesScreen(client, filesToRequest, filesToRemove);
return;
} else if (serverPublishedModInfo && mismatchingMods.size()>0 && Configs.CLIENT_CONFIG.isShowingModInfo()) {
client.setScreen(new ModListScreen(client.screen, new TranslatableComponent("title.bclib.modmissmatch"), new TranslatableComponent("message.bclib.modmissmatch"), CommonComponents.GUI_PROCEED, ModUtil.getMods(), modVersion));
client.setScreen(new ModListScreen(client.screen, Component.translatable("title.bclib.modmissmatch"), Component.translatable("message.bclib.modmissmatch"), CommonComponents.GUI_PROCEED, ModUtil.getMods(), modVersion));
return;
}
}
@ -481,8 +481,8 @@ public class HelloClient extends DataHandler.FromServer {
private void requestFileDownloads(List<AutoSyncID> files) {
BCLib.LOGGER.info("Starting download of Files:" + files.size());
final ProgressScreen progress = new ProgressScreen(null, new TranslatableComponent("title.bclib.filesync.progress"), new TranslatableComponent("message.bclib.filesync.progress"));
progress.progressStart(new TranslatableComponent("message.bclib.filesync.progress.stage.empty"));
final ProgressScreen progress = new ProgressScreen(null, Component.translatable("title.bclib.filesync.progress"), Component.translatable("message.bclib.filesync.progress"));
progress.progressStart(Component.translatable("message.bclib.filesync.progress.stage.empty"));
ChunkerProgress.setProgressScreen(progress);
DataExchangeAPI.send(new RequestFiles(files));

View file

@ -13,7 +13,7 @@ import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.storage.RegionFile;
import net.minecraft.world.level.storage.LevelResource;
@ -179,7 +179,7 @@ public class DataFixerAPI {
@Environment(EnvType.CLIENT)
private static AtomicProgressListener showProgressScreen(){
ProgressScreen ps = new ProgressScreen(Minecraft.getInstance().screen, new TranslatableComponent("title.bclib.datafixer.progress"), new TranslatableComponent("message.bclib.datafixer.progress"));
ProgressScreen ps = new ProgressScreen(Minecraft.getInstance().screen, Component.translatable("title.bclib.datafixer.progress"), Component.translatable("message.bclib.datafixer.progress"));
Minecraft.getInstance().setScreen(ps);
return ps;
}
@ -225,7 +225,7 @@ public class DataFixerAPI {
Supplier<State> runner = () -> {
if (createBackup) {
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.waitbackup"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.waitbackup"));
EditWorldScreen.makeBackupAndShowToast(Minecraft.getInstance().getLevelSource(), levelID);
}
@ -319,23 +319,23 @@ public class DataFixerAPI {
State state = new State();
progress.resetAtomic();
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.reading"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.reading"));
List<File> players = getAllPlayers(dir);
List<File> regions = getAllRegions(dir, null);
final int maxProgress = players.size()+regions.size()+4;
progress.incAtomic(maxProgress);
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.players"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.players"));
players.parallelStream().forEach((file) -> {
fixPlayer(profile, state, file);
progress.incAtomic(maxProgress);
});
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.level"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.level"));
fixLevel(profile, state, dir);
progress.incAtomic(maxProgress);
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.worlddata"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.worlddata"));
try {
profile.patchWorldData();
} catch (PatchDidiFailException e){
@ -345,14 +345,14 @@ public class DataFixerAPI {
}
progress.incAtomic(maxProgress);
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.regions"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.regions"));
regions.parallelStream().forEach((file) -> {
fixRegion(profile, state, file);
progress.incAtomic(maxProgress);
});
if (!state.didFail) {
progress.progressStage(new TranslatableComponent("message.bclib.datafixer.progress.saving"));
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.saving"));
profile.markApplied();
WorldDataAPI.saveFile(BCLib.MOD_ID);
}

View file

@ -5,7 +5,7 @@ import net.minecraft.core.NonNullList;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
@ -67,7 +67,7 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
}
protected Component getDefaultName() {
return new TranslatableComponent("container.barrel");
return Component.translatable("container.barrel");
}
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {

View file

@ -2,7 +2,7 @@ package ru.bclib.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.FurnaceMenu;
@ -17,7 +17,7 @@ public class BaseFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
}
protected Component getDefaultName() {
return new TranslatableComponent("container.furnace");
return Component.translatable("container.furnace");
}
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {

View file

@ -2,7 +2,7 @@ package ru.bclib.gui.modmenu;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.TranslatableComponent;
import org.jetbrains.annotations.Nullable;
import ru.bclib.config.ConfigKeeper.BooleanEntry;
import ru.bclib.config.Configs;
@ -22,11 +22,11 @@ import java.util.function.Supplier;
public class MainScreen extends GridScreen{
public MainScreen(@Nullable Screen parent) {
super(parent, new TranslatableComponent("title.bclib.modmenu.main"), 10, false);
super(parent, Component.translatable("title.bclib.modmenu.main"), 10, false);
}
protected <T> TranslatableComponent getComponent(NamedPathConfig config, ConfigTokenDescription<T> option, String type){
return new TranslatableComponent(type + ".config." + config.configID + option.getPath() );
return Component.translatable(type + ".config." + config.configID + option.getPath() );
}
Map<GridWidgetWithEnabledState, Supplier<Boolean>> dependentWidgets = new HashMap<>();

View file

@ -6,7 +6,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import org.jetbrains.annotations.Nullable;
import ru.bclib.gui.gridlayout.GridCheckboxCell;
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
@ -19,10 +19,10 @@ public class ConfirmFixScreen extends BCLibScreen {
protected int id;
public ConfirmFixScreen(@Nullable Screen parent, ConfirmFixScreen.Listener listener) {
super(parent, new TranslatableComponent("bclib.datafixer.backupWarning.title"));
super(parent, Component.translatable("bclib.datafixer.backupWarning.title"));
this.listener = listener;
this.description = new TranslatableComponent("bclib.datafixer.backupWarning.message");
this.description = Component.translatable("bclib.datafixer.backupWarning.message");
}
protected void initLayout() {
@ -32,12 +32,12 @@ public class ConfirmFixScreen extends BCLibScreen {
grid.addSpacerRow();
GridRow row = grid.addRow();
GridCheckboxCell backup = row.addCheckbox(new TranslatableComponent("bclib.datafixer.backupWarning.backup"), true, BUTTON_HEIGHT, this.font);
GridCheckboxCell backup = row.addCheckbox(Component.translatable("bclib.datafixer.backupWarning.backup"), true, BUTTON_HEIGHT, this.font);
grid.addSpacerRow(10);
row = grid.addRow();
GridCheckboxCell fix = row.addCheckbox(new TranslatableComponent("bclib.datafixer.backupWarning.fix"), true, BUTTON_HEIGHT, this.font);
GridCheckboxCell fix = row.addCheckbox(Component.translatable("bclib.datafixer.backupWarning.fix"), true, BUTTON_HEIGHT, this.font);
grid.addSpacerRow(20);

View file

@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
import ru.bclib.gui.gridlayout.GridRow;
@ -19,9 +19,9 @@ public class ConfirmRestartScreen extends BCLibScreen {
}
public ConfirmRestartScreen(ConfirmRestartScreen.Listener listener, Component message) {
super(new TranslatableComponent("title.bclib.confirmrestart"));
super(Component.translatable("title.bclib.confirmrestart"));
this.description = message==null?new TranslatableComponent("message.bclib.confirmrestart"):message;
this.description = message==null?Component.translatable("message.bclib.confirmrestart"):message;
this.listener = listener;
}

View file

@ -5,7 +5,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import ru.bclib.gui.gridlayout.GridColumn;
import ru.bclib.gui.gridlayout.GridLayout;
import ru.bclib.gui.gridlayout.GridRow;
@ -16,7 +16,7 @@ public class LevelFixErrorScreen extends BCLibScreen {
final Listener onContinue;
public LevelFixErrorScreen(Screen parent, String[] errors, Listener onContinue) {
super(parent, new TranslatableComponent("title.bclib.datafixer.error"), 10, true);
super(parent, Component.translatable("title.bclib.datafixer.error"), 10, true);
this.errors = errors;
this.onContinue = onContinue;
}
@ -24,7 +24,7 @@ public class LevelFixErrorScreen extends BCLibScreen {
@Override
protected void initLayout() {
grid.addSpacerRow();
grid.addRow().addMessage(new TranslatableComponent("message.bclib.datafixer.error"), font, GridLayout.Alignment.CENTER);
grid.addRow().addMessage(Component.translatable("message.bclib.datafixer.error"), font, GridLayout.Alignment.CENTER);
grid.addSpacerRow(8);
GridRow row = grid.addRow();
@ -42,7 +42,7 @@ public class LevelFixErrorScreen extends BCLibScreen {
grid.addSpacerRow(8);
row = grid.addRow();
row.addFiller();
row.addButton(new TranslatableComponent("title.bclib.datafixer.error.continue"), 0.5f, 20, font, (n)-> {
row.addButton(Component.translatable("title.bclib.datafixer.error.continue"), 0.5f, 20, font, (n)-> {
onClose();
onContinue.doContinue(true);
});

View file

@ -8,7 +8,7 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ProgressListener;
import org.jetbrains.annotations.Nullable;
@ -138,7 +138,7 @@ public class ProgressScreen extends GridScreen implements ProgressListener, Atom
}
private Component getProgressComponent(int pg){
return new TranslatableComponent("title.bclib.progress").append(": " + pg + "%");
return Component.translatable("title.bclib.progress").append(": " + pg + "%");
}
@Override
protected void initLayout() {

View file

@ -5,7 +5,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import ru.bclib.api.dataexchange.handler.autosync.HelloClient;
import ru.bclib.gui.gridlayout.GridCheckboxCell;
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
@ -22,10 +22,10 @@ public class SyncFilesScreen extends BCLibScreen {
private final boolean shouldDelete;
private final HelloClient.IServerModMap serverInfo;
public SyncFilesScreen(int modFiles, int configFiles, int singleFiles, int folderFiles, int deleteFiles, HelloClient.IServerModMap serverInfo, Listener listener) {
super(new TranslatableComponent("title.bclib.syncfiles"));
super(Component.translatable("title.bclib.syncfiles"));
this.serverInfo = serverInfo;
this.description = new TranslatableComponent("message.bclib.syncfiles");
this.description = Component.translatable("message.bclib.syncfiles");
this.listener = listener;
this.hasConfigFiles = configFiles>0;
@ -47,15 +47,15 @@ public class SyncFilesScreen extends BCLibScreen {
final GridCheckboxCell mods;
row = grid.addRow();
mods = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.mods"), hasMods, BUTTON_HEIGHT, this.font);
mods = row.addCheckbox(Component.translatable("message.bclib.syncfiles.mods"), hasMods, BUTTON_HEIGHT, this.font);
mods.setEnabled(hasMods);
row.addSpacer();
row.addButton(new TranslatableComponent("title.bclib.syncfiles.modInfo"), 20, font, (button)->{
row.addButton(Component.translatable("title.bclib.syncfiles.modInfo"), 20, font, (button)->{
ModListScreen scr = new ModListScreen(
this,
new TranslatableComponent("title.bclib.syncfiles.modlist"),
new TranslatableComponent("message.bclib.syncfiles.modlist"),
Component.translatable("title.bclib.syncfiles.modlist"),
Component.translatable("message.bclib.syncfiles.modlist"),
ModUtil.getMods(),
serverInfo
);
@ -67,7 +67,7 @@ public class SyncFilesScreen extends BCLibScreen {
final GridCheckboxCell configs;
row = grid.addRow();
configs = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.configs"), hasConfigFiles, BUTTON_HEIGHT, this.font);
configs = row.addCheckbox(Component.translatable("message.bclib.syncfiles.configs"), hasConfigFiles, BUTTON_HEIGHT, this.font);
configs.setEnabled(hasConfigFiles);
grid.addSpacerRow();
@ -75,12 +75,12 @@ public class SyncFilesScreen extends BCLibScreen {
row = grid.addRow();
final GridCheckboxCell folder;
folder = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.folders"), hasFiles, BUTTON_HEIGHT, this.font);
folder = row.addCheckbox(Component.translatable("message.bclib.syncfiles.folders"), hasFiles, BUTTON_HEIGHT, this.font);
folder.setEnabled(hasFiles);
row.addSpacer();
GridCheckboxCell delete;
delete = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.delete"), shouldDelete, BUTTON_HEIGHT, this.font);
delete = row.addCheckbox(Component.translatable("message.bclib.syncfiles.delete"), shouldDelete, BUTTON_HEIGHT, this.font);
delete.setEnabled(shouldDelete);

View file

@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
import ru.bclib.gui.gridlayout.GridRow;
@ -13,9 +13,9 @@ public class WarnBCLibVersionMismatch extends BCLibScreen {
private final Component description;
private final Listener listener;
public WarnBCLibVersionMismatch(Listener listener) {
super(new TranslatableComponent("title.bclib.bclibmissmatch"));
super(Component.translatable("title.bclib.bclibmissmatch"));
this.description = new TranslatableComponent("message.bclib.bclibmissmatch");
this.description = Component.translatable("message.bclib.bclibmissmatch");
this.listener = listener;
}

View file

@ -7,7 +7,7 @@ import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;
@ -40,9 +40,9 @@ public interface SurvivesOnSpecialGround {
final int MAX_LINES = 7;
List<String> lines = splitLines(description);
if (lines.size()==1) {
list.add(new TranslatableComponent("tooltip.bclib.place_on", lines.get(0)).withStyle(ChatFormatting.GREEN));
list.add(Component.translatable("tooltip.bclib.place_on", lines.get(0)).withStyle(ChatFormatting.GREEN));
} else if (lines.size()>1) {
list.add(new TranslatableComponent("tooltip.bclib.place_on", "").withStyle(ChatFormatting.GREEN));
list.add(Component.translatable("tooltip.bclib.place_on", "").withStyle(ChatFormatting.GREEN));
for (int i = 0; i < Math.min(lines.size(), MAX_LINES); i++) {
String line = lines.get(i);
if (i == MAX_LINES - 1 && i < lines.size() - 1) line += " ...";

View file

@ -5,7 +5,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
@ -59,7 +59,7 @@ public class BaseAnvilItem extends BlockItem implements ItemModelProvider {
int maxValue = block.getMaxDurability() * 3;
float damage = maxValue - destruction;
String percents = String.format(Locale.ROOT, "%.0f%%", damage);
list.add(new TranslatableComponent("message.bclib.anvil_damage").append(": " + percents));
list.add(Component.translatable("message.bclib.anvil_damage").append(": " + percents));
}
}

View file

@ -2,11 +2,15 @@ package ru.bclib.mixin.common;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.MultiPackResourceManager;
import net.minecraft.server.packs.resources.Resource;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
@Mixin(MultiPackResourceManager.class)
public class MultiPackResourceManagerMixin {
private static final String[] BCLIB_MISSING_RESOURCES = new String[] {
@ -16,12 +20,13 @@ public class MultiPackResourceManagerMixin {
"dimension_type/the_nether.json"
};
@Inject(method = "hasResource", at = @At("HEAD"), cancellable = true)
private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Boolean> info) {
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Optional<Resource>> info) {
if (resourceLocation.getNamespace().equals("minecraft")) {
for (String key: BCLIB_MISSING_RESOURCES) {
if (resourceLocation.getPath().equals(key)) {
info.setReturnValue(false);
info.setReturnValue(Optional.empty());
info.cancel();
return;
}
}