#I'm trying to make a screen but java gives me error of java.lang.StringIndexOutOfBoundsException.

5 messages · Page 1 of 1 (latest)

opal cosmos
#

[Netty Local Client IO #0/ERROR] (ClientPlayNetworkAddon for Player55) Encountered exception while handling in channel with name "fabric-screen-handler-api-v1:open_screen"
java.lang.StringIndexOutOfBoundsException: Range [1, 1 + 116) out of bounds for length 25

This is the full error log. please HELP

#
public class ScreenBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory {
    private final DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(0, ItemStack.EMPTY);

    public ScreenBlockEntity(BlockPos pos, BlockState state) {
        super(ModBlockEntities.SCREEN_BLOCK_ENTITY, pos, state);
    }

    @Override
    public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
        buf.readBlockPos();
    }

    @Override
    public Text getDisplayName() {
        return null;
    }

    @Nullable
    @Override
    public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
        return new TestScreenHandler(syncId, inv, this);
    }

    @Override
    public DefaultedList<ItemStack> getItems() {
        return defaultedList;
    }
}
#
public class ScreenBlock extends BlockWithEntity {
    private PacketByteBuf packetByteBuf;

    public ScreenBlock(Settings settings) {
        super(settings);
    }

    @Override
    public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
        if (!world.isClient) {
            NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);

            if (screenHandlerFactory != null) {
                player.openHandledScreen(screenHandlerFactory);
            }
        }
        return ActionResult.SUCCESS;
    }

    @Nullable
    @Override
    public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
        return new ScreenBlockEntity(pos, state);
    }
}
#
public class TestScreenHandler extends ScreenHandler {
    private final Inventory INVENTORY;

    public TestScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf packetByteBuf) {
        this(syncId, playerInventory, new SimpleInventory(0));
    }

    public TestScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {
        super(ModScreenHandlers.TEST_SCREEN_HANDLER, syncId);
        INVENTORY = inventory;
        inventory.onOpen(playerInventory.player);
    }

    @Override
    public boolean canUse(PlayerEntity player) {
        return this.INVENTORY.canPlayerUse(player);
    }
}
#
public class TestScreen extends HandledScreen<ScreenHandler> {
    public TestScreen(ScreenHandler screenHandler, PlayerInventory playerInventory, Text title) {
        super(screenHandler, playerInventory, title);
    }

    private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/dispenser.png");

    @Override
    protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
    }

    @Override
    public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    }

    @Override
    protected void init() {
        super.init();
    }
}