mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-02-16 01:42:20 +01:00
fixed startup
rewrote Setting generator added Button settings moved Bedrock authentication
This commit is contained in:
parent
60e5eaf8f7
commit
550b9b4e4a
@ -32,11 +32,10 @@ import de.florianmichael.viafabricplus.event.PreLoadCallback;
|
||||
import de.florianmichael.viafabricplus.information.InformationSystem;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.settings.SettingsSystem;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ViaFabricPlus implements ClientModInitializer {
|
||||
public class ViaFabricPlus {
|
||||
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public final static File RUN_DIRECTORY = new File("ViaFabricPlus");
|
||||
|
||||
@ -45,8 +44,12 @@ public class ViaFabricPlus implements ClientModInitializer {
|
||||
private final SettingsSystem settingsSystem = new SettingsSystem();
|
||||
private final InformationSystem informationSystem = new InformationSystem();
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
public void init() {
|
||||
PreLoadCallback.EVENT.invoker().onLoad();
|
||||
|
||||
CustomClassicProtocolExtensions.create();
|
||||
new ProtocolHack();
|
||||
|
||||
FinishMinecraftLoadCallback.EVENT.register(() -> {
|
||||
// General settings
|
||||
settingsSystem.init();
|
||||
@ -65,10 +68,6 @@ public class ViaFabricPlus implements ClientModInitializer {
|
||||
// Bedrock Stuff
|
||||
BedrockAccountManager.INSTANCE.load();
|
||||
});
|
||||
PreLoadCallback.EVENT.invoker().onLoad();
|
||||
|
||||
CustomClassicProtocolExtensions.create();
|
||||
new ProtocolHack();
|
||||
}
|
||||
|
||||
public SettingsSystem getSettingsSystem() {
|
||||
|
@ -29,6 +29,6 @@ public class MixinMain {
|
||||
|
||||
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;initCrashReport()V"))
|
||||
private static void preLoad(CallbackInfo ci) {
|
||||
// ViaFabricPlus.INSTANCE.init();
|
||||
ViaFabricPlus.INSTANCE.init();
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class MixinAnvilBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(state.get(FACING).getAxis() == Direction.Axis.X ? viafabricplus_x_axis_shape_v1_12_2 : viafabricplus_z_axis_shape_v1_12_2);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class MixinBrewingStandBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_base_shape_v1_12_2);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public abstract class MixinCauldronBlock extends AbstractCauldronBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
return viafabricplus_cauldron_shape_v1_12_2;
|
||||
}
|
||||
return super.getOutlineShape(state, world, pos, context);
|
||||
|
@ -39,7 +39,7 @@ public abstract class MixinChestBlock extends AbstractChestBlock<ChestBlockEntit
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
return super.getCollisionShape(state, world, pos, context);
|
||||
|
@ -44,7 +44,7 @@ public class MixinEndPortalFrameBlock {
|
||||
|
||||
@Redirect(method = "getOutlineShape", at = @At(value = "FIELD", target = "Lnet/minecraft/block/EndPortalFrameBlock;FRAME_WITH_EYE_SHAPE:Lnet/minecraft/util/shape/VoxelShape;"))
|
||||
public VoxelShape redirectGetOutlineShape() {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
return VoxelShapes.union(FRAME_SHAPE, viafabricplus_eye_shape_v1_12_2);
|
||||
}
|
||||
return FRAME_WITH_EYE_SHAPE;
|
||||
|
@ -50,7 +50,7 @@ public class MixinFarmlandBlock extends Block {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
|
||||
cir.setReturnValue(viafabricplus_shape_v1_9_4);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class MixinFenceBlock extends HorizontalConnectingBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
|
||||
return viafabricplus_fence_shape_b1_8_1;
|
||||
}
|
||||
return super.getCollisionShape(state, world, pos, context);
|
||||
@ -59,7 +59,7 @@ public class MixinFenceBlock extends HorizontalConnectingBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
return super.getOutlineShape(state, world, pos, context);
|
||||
|
@ -36,7 +36,7 @@ public class MixinFireBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_15_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_15_2)) {
|
||||
cir.setReturnValue(VoxelShapes.empty());
|
||||
}
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ public class MixinHopperBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_hopper_shape_v1_12_2);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getRaycastShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetRaycastShape(BlockState state, BlockView world, BlockPos pos, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_inside_shape_v1_12_2);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class MixinLadderBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
private void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> ci) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
switch (state.get(LadderBlock.FACING)) {
|
||||
case NORTH -> ci.setReturnValue(viafabricplus_north_shape_v1_8_x);
|
||||
case SOUTH -> ci.setReturnValue(viafabricplus_south_shape_v1_8_x);
|
||||
|
@ -40,7 +40,7 @@ public class MixinLilyPadBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void changeBoundingBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
cir.setReturnValue(viafabricplus_shape_v1_8_x);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class MixinPaneBlock extends HorizontalConnectingBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
return viafabricplus_get1_8Shape(state);
|
||||
}
|
||||
return super.getOutlineShape(state, world, pos, context);
|
||||
@ -44,7 +44,7 @@ public class MixinPaneBlock extends HorizontalConnectingBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
return viafabricplus_get1_8Shape(state);
|
||||
}
|
||||
return super.getCollisionShape(state, world, pos, context);
|
||||
|
@ -40,14 +40,14 @@ public class MixinPistonHeadBlock extends FacingBlock {
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_getCoreShape_v1_8_x(state));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
return VoxelShapes.union(viafabricplus_getHeadShape_v1_8_x(state), viafabricplus_getCoreShape_v1_8_x(state));
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class MixinSnowBlock {
|
||||
|
||||
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_layers_to_shape_v1_12_2[state.get(LAYERS) - 1]);
|
||||
}
|
||||
}
|
||||
|
@ -158,14 +158,14 @@ public class MixinWallBlock extends Block {
|
||||
|
||||
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_cip_shape_by_index_v1_12_2[viafabricplus_getShapeIndex_v1_12_2(state)]);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
|
||||
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
|
||||
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(viafabricplus_shape_by_index_v1_12_2[viafabricplus_getShapeIndex_v1_12_2(state)]);
|
||||
}
|
||||
}
|
||||
|
@ -60,51 +60,14 @@ public class ProtocolSelectionScreen extends Screen {
|
||||
RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(INSTANCE));
|
||||
}
|
||||
|
||||
private ButtonWidget bedrockAuthentication;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, textRenderer.fontHeight + 4));
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build());
|
||||
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height - 25, textRenderer.fontHeight + 4));
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, 0).size(20, 20).build());
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("Settings"), button -> client.setScreen(SettingsScreen.get(this))).position(0, 0).size(98, 20).build());
|
||||
this.addDrawableChild(bedrockAuthentication = ButtonWidget.builder(getBedrockAuthenticationText(), button -> {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
BedrockAccountManager.INSTANCE.setAccount(MinecraftAuth.requestBedrockLogin(msaDeviceCode -> {
|
||||
client.execute(() -> this.client.setScreen(new NoticeScreen(() -> {
|
||||
ProtocolSelectionScreen.open(new MultiplayerScreen(new TitleScreen()));
|
||||
Thread.currentThread().interrupt();
|
||||
}, Text.literal("Microsoft Bedrock login"), Text.literal("Your webbrowser should've opened.\nPlease enter the following Code: " + msaDeviceCode.userCode() + "\nClosing this screen will cancel the process!"), Text.literal("Cancel"), false)));
|
||||
try {
|
||||
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri()));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
ProtocolSelectionScreen.open(new MultiplayerScreen(new TitleScreen()));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}).position(width - 98, 0).size(98, 20).build());
|
||||
}
|
||||
|
||||
public Text getBedrockAuthenticationText() {
|
||||
if (BedrockAccountManager.INSTANCE.getAccount() != null) {
|
||||
return Text.literal(BedrockAccountManager.INSTANCE.getAccount().displayName());
|
||||
}
|
||||
return Text.literal("Set Bedrock Account");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (bedrockAuthentication != null) {
|
||||
bedrockAuthentication.setMessage(getBedrockAuthenticationText());
|
||||
}
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("Settings"), button -> client.setScreen(SettingsScreen.get(this))).position(width - 98, 0).size(98, 20).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,12 +19,14 @@ package de.florianmichael.viafabricplus.screen.settings;
|
||||
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.BooleanSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ButtonSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ModeSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ProtocolSyncBooleanSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.meta.TitleRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.ButtonSetting;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -58,7 +60,7 @@ public class SettingsScreen extends Screen {
|
||||
super.init();
|
||||
|
||||
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, height + 5, (textRenderer.fontHeight + 2) * 2));
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build());
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, 0).size(20, 20).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,25 +81,14 @@ public class SettingsScreen extends Screen {
|
||||
|
||||
public static class SlotList extends AlwaysSelectedEntryListWidget<AbstractSettingRenderer> {
|
||||
|
||||
public static final Map<Class<? extends AbstractSetting<?>>, Class<? extends AbstractSettingRenderer>> RENDERER = new HashMap<>() {
|
||||
{
|
||||
put(BooleanSetting.class, BooleanSettingRenderer.class);
|
||||
put(ProtocolSyncBooleanSetting.class, ProtocolSyncBooleanSettingRenderer.class);
|
||||
put(ModeSetting.class, ModeSettingRenderer.class);
|
||||
}
|
||||
};
|
||||
|
||||
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
super(minecraftClient, width, height, top, bottom, entryHeight);
|
||||
|
||||
for (SettingGroup group : ViaFabricPlus.INSTANCE.getSettingsSystem().getGroups()) {
|
||||
this.addEntry(new TitleRenderer(group.getName()));
|
||||
|
||||
for (AbstractSetting<?> setting : group.getSettings()) {
|
||||
try {
|
||||
this.addEntry(RENDERER.get(setting.getClass()).getConstructor(setting.getClass()).newInstance(setting));
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.addEntry(setting.makeSettingRenderer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.screen.settings.settingrenderer;
|
||||
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.ButtonSetting;
|
||||
import de.florianmichael.viafabricplus.util.ScreenUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class ButtonSettingRenderer extends AbstractSettingRenderer {
|
||||
private final ButtonSetting value;
|
||||
|
||||
public ButtonSettingRenderer(ButtonSetting value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getNarration() {
|
||||
return Text.literal(this.value.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
this.value.getValue().run();
|
||||
ScreenUtil.playClickSound();
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
matrices.push();
|
||||
matrices.translate(x, y, 0);
|
||||
DrawableHelper.fill(matrices, 0, 0, entryWidth - 4 /* int i = this.left + (this.width - entryWidth) / 2; int j = this.left + (this.width + entryWidth) / 2; */, entryHeight, Integer.MIN_VALUE);
|
||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
|
||||
DrawableHelper.drawCenteredTextWithShadow(matrices, textRenderer, this.value.displayValue(), entryWidth / 2, entryHeight / 2 - textRenderer.fontHeight / 2, -1);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ public class SettingsSystem {
|
||||
addGroup(
|
||||
GeneralSettings.INSTANCE,
|
||||
BridgeSettings.INSTANCE,
|
||||
BedrockSettings.INSTANCE,
|
||||
MPPassSettings.INSTANCE,
|
||||
VisualSettings.INSTANCE,
|
||||
DebugSettings.INSTANCE
|
||||
|
@ -18,6 +18,7 @@
|
||||
package de.florianmichael.viafabricplus.settings.base;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
|
||||
public abstract class AbstractSetting<T> {
|
||||
private final String name;
|
||||
@ -34,6 +35,8 @@ public abstract class AbstractSetting<T> {
|
||||
parent.getSettings().add(this);
|
||||
}
|
||||
|
||||
public abstract AbstractSettingRenderer makeSettingRenderer();
|
||||
|
||||
public abstract void write(final JsonObject object);
|
||||
public abstract void read(final JsonObject object);
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.settings.groups;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountManager;
|
||||
import de.florianmichael.viafabricplus.screen.ProtocolSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.screen.settings.SettingsScreen;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
import de.florianmichael.viafabricplus.settings.type_impl.ButtonSetting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.NoticeScreen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Util;
|
||||
import net.raphimc.mcauth.MinecraftAuth;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class BedrockSettings extends SettingGroup {
|
||||
public final static BedrockSettings INSTANCE = new BedrockSettings();
|
||||
|
||||
public final ButtonSetting BEDROCK_ACCOUNT = new ButtonSetting(this, "Click to set account for Bedrock edition", () -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
BedrockAccountManager.INSTANCE.setAccount(MinecraftAuth.requestBedrockLogin(msaDeviceCode -> {
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> {
|
||||
MinecraftClient.getInstance().setScreen(SettingsScreen.get(new MultiplayerScreen(new TitleScreen())));
|
||||
Thread.currentThread().interrupt();
|
||||
}, Text.literal("Microsoft Bedrock login"), Text.literal("Your browser should have opened.\nPlease enter the following Code: " + Formatting.BOLD + msaDeviceCode.userCode() + Formatting.RESET + "\nClosing this screen will cancel the process!"), Text.literal("Cancel"), false)));
|
||||
try {
|
||||
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri()));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
ProtocolSelectionScreen.open(new MultiplayerScreen(new TitleScreen()));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
})) {
|
||||
@Override
|
||||
public String displayValue() {
|
||||
if (BedrockAccountManager.INSTANCE.getAccount() != null) {
|
||||
return super.displayValue() + ", current: " + BedrockAccountManager.INSTANCE.getAccount().displayName();
|
||||
}
|
||||
return super.displayValue();
|
||||
}
|
||||
};
|
||||
|
||||
public BedrockSettings() {
|
||||
super("Bedrock");
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
package de.florianmichael.viafabricplus.settings.type_impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.BooleanSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
|
||||
@ -27,6 +29,11 @@ public class BooleanSetting extends AbstractSetting<Boolean> {
|
||||
super(parent, name, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingRenderer makeSettingRenderer() {
|
||||
return new BooleanSettingRenderer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {
|
||||
object.addProperty(getName(), getValue());
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.settings.type_impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ButtonSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
|
||||
public class ButtonSetting extends AbstractSetting<Runnable> {
|
||||
|
||||
public ButtonSetting(SettingGroup parent, String name, Runnable onClick) {
|
||||
super(parent, name, onClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingRenderer makeSettingRenderer() {
|
||||
return new ButtonSettingRenderer(this);
|
||||
}
|
||||
|
||||
public String displayValue() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {}
|
||||
|
||||
@Override
|
||||
public void read(JsonObject object) {}
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
package de.florianmichael.viafabricplus.settings.type_impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ModeSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
|
||||
@ -31,6 +33,11 @@ public class ModeSetting extends AbstractSetting<String> {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingRenderer makeSettingRenderer() {
|
||||
return new ModeSettingRenderer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {
|
||||
object.addProperty(getName(), getValue());
|
||||
|
@ -18,6 +18,8 @@
|
||||
package de.florianmichael.viafabricplus.settings.type_impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ProtocolSyncBooleanSettingRenderer;
|
||||
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
|
||||
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
|
||||
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
||||
@ -32,6 +34,11 @@ public class ProtocolSyncBooleanSetting extends BooleanSetting {
|
||||
this.protocolRange = protocolRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingRenderer makeSettingRenderer() {
|
||||
return new ProtocolSyncBooleanSettingRenderer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {
|
||||
object.addProperty(getName(), getValue());
|
||||
|
@ -18,9 +18,6 @@
|
||||
"icon": "assets/viafabricplus/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"de.florianmichael.viafabricplus.ViaFabricPlus"
|
||||
],
|
||||
"modmenu": [
|
||||
"de.florianmichael.viafabricplus.integration.ModMenuImpl"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user